@@ -8,12 +8,20 @@ using namespace std;
88
99void DynamicIDManager::reserve (int quantity)
1010{
11- if (quantity < m_capacity)
11+ if (quantity > m_capacity)
1212 {
1313 reserveAdditional (quantity - m_capacity);
1414 }
1515}
1616
17+ void DynamicIDManager::addBlock (int start, int quantity)
18+ {
19+ m_idList.push_back (pair<int , int >(start, quantity));
20+
21+ // Assume no overlaps (should really fix this, but we just need to use this carefully)
22+ m_capacity += quantity;
23+ }
24+
1725void DynamicIDManager::reserveAdditional (int quantity)
1826{
1927
@@ -50,8 +58,12 @@ int DynamicIDManager::begin()
5058 m_current = m_idList.begin ();
5159 m_nextID = m_current->first ;
5260 }
61+ else
62+ {
63+ m_nextID = m_current->first ;
64+ }
5365
54- return m_nextID++ ;
66+ return m_nextID;
5567}
5668
5769int DynamicIDManager::currentID ()
@@ -83,6 +95,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
8395 {
8496 throw exception (" Out of IDs" );
8597 }
98+ else
99+ {
100+ // If the current ID is now within the limits of the last block
101+ // then we can just increment m_nextID
102+ if (m_nextID > m_current->first && m_nextID < m_current->first + m_current->second )
103+ {
104+ ++m_nextID;
105+ }
106+ else
107+ {
108+ // Otherwise, we can just set the next ID to the first in the last block
109+ m_nextID = m_current->first ;
110+ }
111+ }
112+ }
113+ else
114+ {
115+ m_nextID = m_current->first ;
86116 }
87117 }
88118 }
@@ -94,4 +124,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
94124bool DynamicIDManager::allocateIDs (int quantity, int *start)
95125{
96126 return m_allocator->allocate (quantity, start);
127+ }
128+
129+
130+ bool DynamicIDManager::inRange (int id)
131+ {
132+ bool retVal = false ;
133+ list< pair<int , int > >::iterator it = m_idList.begin ();
134+ for (;it != m_idList.end (); ++it)
135+ {
136+ if (it->first > id)
137+ break ;
138+
139+ if (id >= it->first && (id < (it->first + it->second )))
140+ {
141+ retVal = true ;
142+ break ;
143+ }
144+ }
145+
146+ return retVal;
97147}
0 commit comments