00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LIBCERTI_HANDLE_MANAGER
00024 #define LIBCERTI_HANDLE_MANAGER
00025
00026 #include "certi.hh"
00027
00028 #include <limits>
00029
00030 #ifdef _WIN32
00031 #ifdef max
00032 #undef max
00033 #endif
00034 #endif
00035
00036 namespace certi {
00037
00042 template<typename T>
00043 class HandleManager
00044 {
00045 public:
00052 HandleManager(T);
00058 HandleManager(T init, size_t hmax);
00064 T provide() throw (RTIinternalError);
00071 void free(T handle);
00072
00073 private:
00074 size_t maximum ;
00075 T highest ;
00076 std::list<T> available ;
00077 };
00078
00079
00080 template<typename T>
00081 HandleManager<T>::HandleManager(T init)
00082 : maximum(std::numeric_limits<T>::max()), highest(init) { }
00083
00084 template<typename T>
00085 HandleManager<T>::HandleManager(T init, size_t hmax)
00086 : highest(init), maximum(hmax) { }
00087
00088 template<typename T> T
00089 HandleManager<T>::provide() throw (RTIinternalError)
00090 {
00091 T handle = 0 ;
00092
00093 if (available.size() > 0) {
00094 handle = available.front();
00095 available.pop_front();
00096 }
00097 else {
00098 if (highest < maximum)
00099 handle = highest++ ;
00100 else
00101 throw RTIinternalError("Maximum handle reached");
00102 }
00103
00104 return handle ;
00105 }
00106
00107 template<typename T> void
00108 HandleManager<T>::free(T handle)
00109 {
00110
00111
00112
00113
00114 }
00115
00116 }
00117
00118 #endif // LIBCERTI_HANDLE_MANAGER