UGDK  0.5.0
 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 <unordered_set>
5 
6 #include <ugdk/util/uncopyable.h>
7 
8 namespace ugdk {
9 namespace util {
10 class IDGenerator : public Uncopyable {
11  public:
12  IDGenerator(int min_id, int max_id, int error_value);
14 
16 
17  int GenerateID();
18 
20 
21  int ReleaseID(int id);
22 
24  int error_value() const { return error_value_; }
25 
26  private:
27  int current_id_;
28  const int min_id_,
29  max_id_,
30  error_value_;
31 
32  std::unordered_set<int> unused_ids_;
33  std::size_t range() const {
34  return static_cast<std::size_t>(max_id_ - min_id_ + 1);
35  }
36 };
37 
38 } // namespace util
39 } // namespace ugdk
40 
41 #endif
int GenerateID()
Generate a new id.
Definition: animation.h:11
~IDGenerator()
Definition: idgenerator.h:13
Definition: idgenerator.h:10
IDGenerator(int min_id, int max_id, int error_value)
int error_value() const
The error value for this generator.
Definition: idgenerator.h:24
Definition: uncopyable.h:8
int ReleaseID(int id)
Release an id.