00001 #ifndef Impala_Util_NumberGenerator_h 00002 #define Impala_Util_NumberGenerator_h 00003 00004 #include <exception> 00005 00006 namespace Impala 00007 { 00008 namespace Util 00009 { 00010 00011 // Simple class to generate consecutive numbers. 00012 // Note that no means (other than throwing an exception) is yet implemented to prevent overflow!! 00013 class NumberGenerator 00014 { 00015 00016 #define BASE_VALUE 0 00017 00018 public: 00019 00020 NumberGenerator(unsigned long highestValueIssued = BASE_VALUE) 00021 { 00022 mHighestValueIssued = highestValueIssued; 00023 } 00024 00025 unsigned long Generate() 00026 { 00027 if (++mHighestValueIssued == BASE_VALUE) 00028 throw std::runtime_error("end of number range reached"); 00029 00030 return mHighestValueIssued; 00031 } 00032 00033 void SetHighestValueIssued(unsigned long newHighestValueIssued) 00034 { 00035 if (newHighestValueIssued > mHighestValueIssued) 00036 mHighestValueIssued = newHighestValueIssued; 00037 } 00038 00039 unsigned long GetHighestValueIssued() 00040 { 00041 return mHighestValueIssued; 00042 } 00043 00044 private: 00045 00046 unsigned long mHighestValueIssued; 00047 00048 }; //class 00049 00050 } // namespace Util 00051 } // namespace Impala 00052 00053 #endif