IdPool Class Reference

#include <IdPool.h>

List of all members.


Public Member Functions

 IdPool (unsigned minIdx, unsigned maxIdx)
 ~IdPool ()
IdPoolallocSubPool (unsigned size)
IdPoolallocSubPool (unsigned startIdx, unsigned size)
unsigned allocEntry (bool *succeeded=NULL)
bool allocEntryAt (unsigned id)
void freeEntry (unsigned id)
bool freeSubPool (IdPool *pool)
unsigned getUnallocatedSubPoolIdx ()
unsigned getMinIdx ()
unsigned getMaxIdx ()

Protected Attributes

std::vector< IdPool * > subPoolList
std::deque< unsigned > freeIdList
bool hasAllocatedIds
unsigned minIdx
unsigned maxIdx

Constructor & Destructor Documentation

IdPool::IdPool ( unsigned  minIdx,
unsigned  maxIdx 
)

Allocates a pool of IDs begining at minIdx and ending at maxIdx, both inclusive

Parameters:
minIdx lowest ID belonging to this instance
maxIdx highest ID belonging to this instance

IdPool::~IdPool (  ) 


Member Function Documentation

unsigned IdPool::allocEntry ( bool *  succeeded = NULL  ) 

Allocates a single ID. If the allocated ID is not used anymore call freeEntry() on it.

Parameters:
succeeded if != NULL will indicated whether finding an unused ID was successfull
Returns:
an unused ID, 0 on failure

bool IdPool::allocEntryAt ( unsigned  id  ) 

Marks a single ID as reserved. If the allocated ID is not used anymore call freeEntry() on it.

Parameters:
id requested ID
Returns:
returns true on success and false on failure

IdPool * IdPool::allocSubPool ( unsigned  startIdx,
unsigned  size 
)

Tries to allocate a subpool with the specified range. Ohterwise it behaves as allocSubPool() with size provided.

Parameters:
size minimum number of IDs of the subpool
Returns:
pointer to the subpool, NULL in case of failure

IdPool * IdPool::allocSubPool ( unsigned  size  ) 

Creates a new instance of IdPool (a 'subpool') containing size entries. The IDs owned by the subpool are marked as reserved in its parent. In case the method fails NULL is returned. Depending on the implementation it might fail for various reasons, not necessarily only when it is running out of available IDs.

Parameters:
size minimum number of IDs of the subpool
Returns:
pointer to the subpool, NULL in case of failure

void IdPool::freeEntry ( unsigned  id  ) 

Releases a previousely reserved ID (by allocEntry() or by allocEntryAt() for instance)

Parameters:
id id which should be released

bool IdPool::freeSubPool ( IdPool pool  ) 

Releases a previousely allocated subpool.

Parameters:
pool pool which should be released

unsigned IdPool::getMaxIdx (  ) 

Returns maximum ID belonging to this pool

Returns:
maximum ID

unsigned IdPool::getMinIdx (  ) 

Returns minimal ID belonging to this pool

Returns:
minimal ID

unsigned IdPool::getUnallocatedSubPoolIdx (  ) 

Returns the lowest ID of a "very large" block of unused IDs The current implementation starts allocating IDs at the bottom of its range and it returns the lowest ID of a block which goes to the end of the allocated range. The ID returned is not marked as reserved. This method is used by the IdPoolListener in order to find an initial guess where all instances could allow a subpool to be allocated.

Returns:
an ID (not reserved)


Member Data Documentation

std::deque<unsigned> IdPool::freeIdList [protected]

bool IdPool::hasAllocatedIds [protected]

unsigned IdPool::maxIdx [protected]

unsigned IdPool::minIdx [protected]

std::vector<IdPool*> IdPool::subPoolList [protected]


The documentation for this class was generated from the following files:

Generated on Wed Oct 20 16:11:57 2010 for inVRs by doxygen 1.5.8