UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
idgenerator.h
Go to the documentation of this file.
1 #ifndef HORUSEYE_FRAMEWORK_IDGENERATOR_H_
2 #define HORUSEYE_FRAMEWORK_IDGENERATOR_H_
3 
4 #include <ugdk/portable/tr1.h>
5 
6 #include FROM_TR1(unordered_set)
7 
8 #include <ugdk/util/uncopyable.h>
9 
10 namespace ugdk {
11 namespace util {
12 class IDGenerator : public Uncopyable {
13  public:
14  IDGenerator(int min_id, int max_id, int error_value);
17 
18  int GenerateID();
20 
21  int ReleaseID(int id);
22  private:
23  int current_id_;
24  const int min_id_,
25  max_id_,
26  error_value_;
27  std::tr1::unordered_set<int> unused_ids_;
28  size_t range () const { return static_cast<size_t>(max_id_ - min_id_ + 1);}
29 };
30 
31 } // namespace util
32 } // namespace ugdk
33 
34 #endif