OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
IDPool.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#*****************************************************************************
29 
30 
31 #ifndef IDPOOL_H
32 #define IDPOOL_H
33 
34 #if defined(OPENOG_SDK)
35  #include <OpenIG-Base/Export.h>
36 #else
37  #include <Core-Base/Export.h>
38 #endif
39 
40 #include <string>
41 #include <map>
42 #include <vector>
43 
44 namespace OpenIG {
45  namespace Base {
46 
58  class IGCORE_EXPORT IDPool
59  {
60  public:
68  static IDPool* instance();
69 
79  void initIdGroup(const std::string& group, unsigned int base, unsigned int size = 0);
80 
90  bool getNextId(const std::string& group, unsigned int& id);
91 
103  void setAvailableIds(const std::string& group, const std::vector<unsigned int>& ids);
104 
105  protected:
106  IDPool();
107  ~IDPool();
108 
115  struct IdGroup
116  {
117  typedef std::vector<unsigned int> IDs;
118 
119  unsigned int _base;
120  IDs _ids;
121 
122  IdGroup() : _base(0) {}
123  };
124 
125  typedef std::map< std::string, IdGroup > IdGroupMap;
126 
128  IdGroupMap _groups;
129  };
130  } // namespace
131 } // namespace
132 
133 #endif // IDPOOL_H
134 
Definition: ImageGenerator.h:62
Handy singleton class for ID numbers management.
Definition: IDPool.h:58
IdGroupMap _groups
name based std::map of IdGroup
Definition: IDPool.h:128
The IdGroup struct. Internal for ID management.
Definition: IDPool.h:115