UGDK
src/ugdk/util/idgenerator.h
Go to the documentation of this file.
00001 #ifndef HORUSEYE_FRAMEWORK_IDGENERATOR_H_
00002 #define HORUSEYE_FRAMEWORK_IDGENERATOR_H_
00003 
00004 #include <ugdk/portable/tr1.h>
00005 
00006 #include FROM_TR1(unordered_set)
00007 
00008 #include <ugdk/util/uncopyable.h>
00009 
00010 namespace ugdk {
00011 namespace util {
00012 class IDGenerator : public Uncopyable {
00013   public:
00014     IDGenerator(int min_id, int max_id, int error_value);
00015     ~IDGenerator() {}
00017 
00018     int GenerateID();
00020 
00021     int ReleaseID(int id);
00022   private:
00023     int                             current_id_;
00024     const int                       min_id_,
00025                                     max_id_,
00026                                     error_value_;
00027     std::tr1::unordered_set<int>    unused_ids_;
00028     size_t range () const { return static_cast<size_t>(max_id_ - min_id_ + 1);}
00029 };
00030 
00031 } // namespace util
00032 } // namespace ugdk
00033 
00034 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines