41 #ifndef _uidgenerator_cpp
42 #define _uidgenerator_cpp
44 #include "uidgenerator.h"
82 if( (*IDRangeIt).IsWithinBounds(ID) ) {
94 if( (*IDRangeIt).IsWithinBounds(ID) ) {
96 if( (*IDRangeIt).GetLowerBound() == ID ) {
98 (*IDRangeIt).LowerBound++;
101 if( (*IDRangeIt).GetUpperBound() == ID ) {
103 (*IDRangeIt).UpperBound--;
111 if( IDRangeIt != this->
FreeIDs.begin() ) {
112 Temp.insert(Temp.end(),this->
FreeIDs.begin(),IDRangeIt);
116 Temp.push_back(
IntervalType((*IDRangeIt).GetLowerBound(),ID - 1) );
117 Temp.push_back(
IntervalType(ID + 1,(*IDRangeIt).GetUpperBound()) );
121 if( AfterIterator != this->
FreeIDs.end() ) {
122 Temp.insert(Temp.end(),AfterIterator,this->
FreeIDs.end());
139 if( (*IDBegin).GetLowerBound() > ID ) {
140 if( (*IDBegin).GetLowerBound() - 1 == ID ) {
141 (*IDBegin).LowerBound--;
148 for(
IDIterator IDRangeIt = IDBegin ; IDRangeIt != this->
FreeIDs.end() ; ++IDRangeIt )
151 if( (*IDRangeIt).IsWithinBounds(ID) ) {
156 if( NextRange == this->
FreeIDs.end() ) {
160 if( (*NextRange).GetLowerBound() > ID ) {
161 Boole BorderPrev = (*IDRangeIt).GetUpperBound() + 1 == ID;
162 Boole BorderNext = (*NextRange).GetLowerBound() - 1 == ID;
163 if( BorderPrev && BorderNext ) {
166 Temp.insert(Temp.end(),this->
FreeIDs.begin(),IDRangeIt);
167 Temp.push_back(
IntervalType((*IDRangeIt).GetLowerBound(),(*NextRange).GetUpperBound()) );
168 if( NextRange + 1 != this->
FreeIDs.end() ) {
169 Temp.insert(Temp.end(),NextRange + 1,this->
FreeIDs.end());
172 }
else if( BorderPrev ) {
173 (*IDRangeIt).UpperBound++;
174 }
else if( BorderNext ) {
175 (*NextRange).LowerBound--;
bool Boole
Generally acts a single bit, true or false.
NumType LowerBound
The lower numeric boundry of the interval.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
NumType & GetLowerBound()
Gets the lower boundry of this Interval.
Interval< IDType > IntervalType
Convenience type for Intervals used by this class.
IDType GenerateID()
Generates a new ID unique to the pool made by this generator.
IDContainer::const_iterator ConstIDIterator
Const Iterator type for IDs generated and stored by this class.
std::vector< IntervalType > IDContainer
Basic container type for IDs generated and stored by this class.
IDContainer FreeIDs
The container storing all IDs generated and in use by this generator.
NumType GetIntervalSize() const
Gets the numeric distance between the lower and upper bounds of this interval.
Boole ReserveID(const IDType ID)
Adds a specific ID to the pool of used IDs.
UIDGenerator()
Class constructor.
This class will generate keep track of a pool of unique 32-bit ID's that can be used for distinct obj...
Thrown when the available information should have worked but failed for unknown reasons.
IDContainer::iterator IDIterator
Iterator type for IDs generated and stored by this class.
The bulk of the engine components go in this namspace.
~UIDGenerator()
Class destructor.
Boole ReleaseID(const IDType ID)
Frees up an ID so that it can be reused.
void Sort()
Sorts the free IDs stored in this generator.
UInt32 IDType
Convenience type for the ID to be used. Should be some flavor of int.
Boole IsIDUsed(const IDType ID) const
Checks to see if an ID is in use.