21 #ifndef DOXYGEN_NOTFOR_DEVEL
23 #ifndef _TULIPIDMANAGER_H
24 #define _TULIPIDMANAGER_H
27 #include <tulip/Iterator.h>
32 struct IdManagerState {
38 std::set<unsigned int> freeIds;
40 IdManagerState(): firstId(0), nextId(0) {}
45 template <
typename TYPE>
46 class IdManagerIterator:
public Iterator<TYPE> {
51 const std::set<unsigned int>& freeIds;
52 std::set<unsigned int>::const_iterator it;
56 IdManagerIterator(
const IdManagerState& infos):
57 current(infos.firstId), last(infos.nextId), freeIds(infos.freeIds), it(freeIds.begin()) {
58 #ifdef TLP_NO_IDS_REUSE
59 std::set<unsigned int>::const_reverse_iterator itr;
60 itr = freeIds.rbegin();
62 while(itr != freeIds.rend() && (*itr) == last - 1) {
69 ~IdManagerIterator() {}
72 return (current < last);
76 unsigned int tmp = current;
79 while(it != freeIds.end()) {
80 if (current < *it)
return (TYPE) tmp;
91 class TLP_SCOPE IdManager {
101 bool is_free(
unsigned int)
const;
105 void free(
const unsigned int);
110 #ifdef TLP_NO_IDS_REUSE
111 return state.nextId++;
113 return state.freeIds.empty() ? state.nextId++ : getFreeId();
119 unsigned int getFirstOfRange(
unsigned nb) {
120 unsigned int first = state.nextId;
125 #ifndef TLP_NO_IDS_REUSE
129 unsigned int getFreeId();
136 void getFreeId(
unsigned int id);
140 const IdManagerState& getState() {
146 void restoreState(
const IdManagerState& infos) {
154 template<
typename TYPE>
155 Iterator<TYPE>* getIds()
const {
156 return new IdManagerIterator<TYPE>(state);
159 friend std::ostream&
operator<<(std::ostream &,
const IdManager &);
160 friend class IdManagerTest;
163 std::ostream&
operator<<(std::ostream &,
const IdManager &);
168 #endif //DOXYGEN_NOTFOR_DEVEL
std::ostream & operator<<(std::ostream &os, const Array< Obj, SIZE > &array)
operator << stream operator to easily print an array, or save it to a file.