MUID.h
00001 #ifndef MUID_H 00002 #define MUID_H 00003 00004 #include <map> 00005 #include <vector> 00006 #include <crtdbg.h> 00007 00008 using namespace std; 00009 00011 struct MUID{ 00012 unsigned long int High; 00013 unsigned long int Low; 00014 00015 MUID(void) { SetZero(); } 00016 MUID(unsigned long int h, unsigned long int l){ 00017 High = h; 00018 Low = l; 00019 } 00020 00022 void SetZero(void){ 00023 High = Low = 0; 00024 } 00025 void SetInvalid(void){ 00026 SetZero(); 00027 } 00028 00029 /* 00031 void Increase(void){ 00032 if(Low==UINT_MAX){ 00033 _ASSERT(High<UINT_MAX); 00034 High++; 00035 Low = 0; 00036 } 00037 else{ 00038 Low++; 00039 } 00040 } 00041 /*/ 00042 00044 MUID Increase(unsigned long int nSize=1){ 00045 if(Low+nSize>UINT_MAX){ 00046 _ASSERT(High<UINT_MAX); 00047 Low = nSize-(UINT_MAX-Low); 00048 High++; 00049 } 00050 else{ 00051 Low+=nSize; 00052 } 00053 return *this; 00054 } 00055 00057 bool IsInvalid(void){ 00058 // 0이면 Invalid 00059 if(High==Low && Low==0) return true; 00060 return false; 00061 } 00063 bool IsValid(void){ 00064 // 0이면 Invalid 00065 if(High==Low && Low==0) return false; 00066 return true; 00067 } 00068 00070 inline friend bool operator > (const MUID& a, const MUID& b){ 00071 if(a.High>b.High) return true; 00072 if(a.High==b.High){ 00073 if(a.Low>b.Low) return true; 00074 } 00075 return false; 00076 } 00078 inline friend bool operator >= (const MUID& a, const MUID& b){ 00079 if(a.High>b.High) return true; 00080 if(a.High==b.High){ 00081 if(a.Low>=b.Low) return true; 00082 } 00083 return false; 00084 } 00086 inline friend bool operator < (const MUID& a, const MUID& b){ 00087 if(a.High<b.High) return true; 00088 if(a.High==b.High){ 00089 if(a.Low<b.Low) return true; 00090 } 00091 return false; 00092 } 00094 inline friend bool operator <= (const MUID& a, const MUID& b){ 00095 if(a.High<b.High) return true; 00096 if(a.High==b.High){ 00097 if(a.Low<=b.Low) return true; 00098 } 00099 return false; 00100 } 00101 00103 inline MUID& operator=(int v){ 00104 High = 0; 00105 Low = v; 00106 return *this; 00107 } 00109 inline MUID& operator=(const MUID& a){ 00110 High = a.High; 00111 Low = a.Low; 00112 return *this; 00113 } 00115 inline friend bool operator==(const MUID& a, const MUID& b){ 00116 if(a.High==b.High){ 00117 if(a.Low==b.Low) return true; 00118 } 00119 return false; 00120 } 00122 inline friend bool operator!=(const MUID& a, const MUID& b){ 00123 if(a.Low!=b.Low) return true; 00124 if(a.High!=b.High) return true; 00125 return false; 00126 } 00128 inline friend MUID& operator++(MUID& a){ 00129 a.Increase(); 00130 return a; 00131 } 00132 00134 static MUID Invalid(void); 00135 }; 00136 00138 struct MUIDRANGE{ 00139 MUID Start; 00140 MUID End; 00141 00142 bool IsEmpty(void){ 00143 return (Start==End); 00144 } 00145 void Empty(void){ 00146 SetZero(); 00147 } 00148 void SetZero(void){ 00149 Start.SetZero(); 00150 End.SetZero(); 00151 } 00152 }; 00153 00155 #define MAKEMUID(_high, _low) MUID(_high, _low) 00156 00157 00160 class MUIDRefMap : protected map<MUID, void*>{ 00161 MUID m_CurrentMUID; ///< 현재 발급된 MUID 00162 public: 00163 MUIDRefMap(void); 00164 virtual ~MUIDRefMap(void); 00165 00169 MUID Generate(void* pRef); 00170 00174 void* GetRef(MUID& uid); 00175 00179 void* Remove(MUID& uid); 00180 00182 MUIDRANGE Reserve(int nSize); 00183 00185 MUIDRANGE GetReservedCount(void); 00186 }; 00187 00188 /* 00191 class MUIDRefArray : protected vector<void*>{ 00192 MUID m_CurrentMUID; ///< 현재 MUID 00193 public: 00194 MUIDRefArray(void); 00195 virtual ~MUIDRefArray(void); 00196 00200 MUID Generate(void* pRef); 00204 void* GetRef(MUID& uid); 00205 }; 00206 */ 00207 00210 class MUIDRefCache : public map<MUID, void*>{ 00211 public: 00212 MUIDRefCache(void); 00213 virtual ~MUIDRefCache(void); 00214 00218 void Insert(const MUID& uid, void* pRef); 00222 void* GetRef(const MUID& uid); 00226 void* Remove(const MUID& uid); 00227 }; 00228 00229 #endif
MAIET entertainment