Changeset 44039 in vbox for trunk/include/VBox/com
- Timestamp:
- Dec 5, 2012 12:08:52 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r34071 r44039 48 48 { 49 49 50 typedef enum 51 { 52 ZERO_GUID, 53 NORMAL_GUID, 54 INVALID_GUID 55 }GuidState_t; 56 50 57 /** 51 58 * Helper class that represents the UUID type and hides platform-specific … … 60 67 ::RTUuidClear(&mUuid); 61 68 refresh(); 69 mGuidState = ZERO_GUID; 62 70 } 63 71 … … 66 74 mUuid = that.mUuid; 67 75 refresh(); 76 if (isEmpty()) 77 mGuidState = ZERO_GUID; 78 else 79 mGuidState = NORMAL_GUID; 68 80 } 69 81 … … 72 84 mUuid = that; 73 85 refresh(); 86 if (isEmpty()) 87 mGuidState = ZERO_GUID; 88 else 89 mGuidState = NORMAL_GUID; 74 90 } 75 91 … … 79 95 ::memcpy(&mUuid, &that, sizeof(GUID)); 80 96 refresh(); 97 if (isEmpty()) 98 mGuidState = ZERO_GUID; 99 else 100 mGuidState = NORMAL_GUID; 81 101 } 82 102 … … 92 112 Guid(const char *that) 93 113 { 114 mGuidState = NORMAL_GUID; 115 94 116 int rc = ::RTUuidFromStr(&mUuid, that); 117 95 118 if (RT_FAILURE(rc)) 119 { 96 120 ::RTUuidClear(&mUuid); 121 mGuidState = INVALID_GUID; 122 } 123 else if(isEmpty()) 124 mGuidState = ZERO_GUID; 97 125 refresh(); 98 126 } … … 109 137 Guid(const Bstr &that) 110 138 { 111 int rc = !that.isEmpty() 112 ? ::RTUuidFromUtf16(&mUuid, that.raw()) 113 : VERR_INVALID_UUID_FORMAT; 139 mGuidState = NORMAL_GUID; 140 141 if (that.isEmpty()) 142 { 143 ::RTUuidClear(&mUuid); 144 mGuidState = ZERO_GUID; 145 } 146 else 147 { 148 int rc = ::RTUuidFromUtf16(&mUuid, that.raw()); 149 if (RT_FAILURE(rc)) 150 { 151 ::RTUuidClear(&mUuid); 152 mGuidState = INVALID_GUID; 153 } 154 } 155 156 refresh(); 157 } 158 159 Guid& operator=(const Guid &that) 160 { 161 mGuidState = NORMAL_GUID; 162 ::memcpy(&mUuid, &that.mUuid, sizeof (RTUUID)); 163 if (isEmpty()) 164 mGuidState = ZERO_GUID; 165 refresh(); 166 return *this; 167 } 168 Guid& operator=(const GUID &guid) 169 { 170 mGuidState = NORMAL_GUID; 171 ::memcpy(&mUuid, &guid, sizeof (GUID)); 172 if (isEmpty()) 173 mGuidState = ZERO_GUID; 174 refresh(); 175 return *this; 176 } 177 Guid& operator=(const RTUUID &guid) 178 { 179 mGuidState = NORMAL_GUID; 180 ::memcpy(&mUuid, &guid, sizeof (RTUUID)); 181 if (isEmpty()) 182 mGuidState = ZERO_GUID; 183 refresh(); 184 return *this; 185 } 186 Guid& operator=(const char *str) 187 { 188 mGuidState = NORMAL_GUID; 189 int rc = ::RTUuidFromStr(&mUuid, str); 190 114 191 if (RT_FAILURE(rc)) 192 { 115 193 ::RTUuidClear(&mUuid); 116 refresh(); 117 } 118 119 Guid& operator=(const Guid &that) 120 { 121 ::memcpy(&mUuid, &that.mUuid, sizeof (RTUUID)); 122 refresh(); 123 return *this; 124 } 125 Guid& operator=(const GUID &guid) 126 { 127 ::memcpy(&mUuid, &guid, sizeof (GUID)); 128 refresh(); 129 return *this; 130 } 131 Guid& operator=(const RTUUID &guid) 132 { 133 ::memcpy(&mUuid, &guid, sizeof (RTUUID)); 134 refresh(); 135 return *this; 136 } 137 Guid& operator=(const char *str) 138 { 139 int rc = ::RTUuidFromStr(&mUuid, str); 140 if (RT_FAILURE(rc)) 141 ::RTUuidClear(&mUuid); 142 refresh(); 194 mGuidState = INVALID_GUID; 195 } 196 else 197 { 198 if (isEmpty()) 199 mGuidState = ZERO_GUID; 200 } 201 202 refresh(); 203 143 204 return *this; 144 205 } … … 147 208 { 148 209 ::RTUuidCreate(&mUuid); 210 mGuidState = NORMAL_GUID; 149 211 refresh(); 150 212 } … … 152 214 { 153 215 ::RTUuidClear(&mUuid); 216 mGuidState = ZERO_GUID; 154 217 refresh(); 155 218 } … … 164 227 { 165 228 char buf[RTUUID_STR_LENGTH]; 229 230 ::memset(buf,0,RTUUID_STR_LENGTH); 231 232 if (mGuidState == INVALID_GUID) 233 { 234 /* What to return in case of wrong Guid */ 235 return Utf8Str("00000000-0000-0000-0000-00000000000"); 236 } 237 166 238 ::RTUuidToStr(&mUuid, buf, RTUUID_STR_LENGTH); 239 240 167 241 return Utf8Str(buf); 168 242 } … … 176 250 Utf8Str toStringCurly() const 177 251 { 252 253 if (mGuidState == INVALID_GUID) 254 { 255 /* What to return in case of wrong Guid */ 256 return Utf8Str("{00000000-0000-0000-0000-00000000000}"); 257 } 258 178 259 char buf[RTUUID_STR_LENGTH + 2] = "{"; 260 179 261 ::RTUuidToStr(&mUuid, buf + 1, RTUUID_STR_LENGTH); 180 262 buf[sizeof(buf) - 2] = '}'; 181 263 buf[sizeof(buf) - 1] = '\0'; 264 182 265 return Utf8Str(buf); 183 266 } … … 191 274 Bstr toUtf16() const 192 275 { 193 if ( isEmpty())194 return Bstr( );276 if (mGuidState == INVALID_GUID) 277 return Bstr("00000000-0000-0000-0000-00000000000"); 195 278 196 279 RTUTF16 buf[RTUUID_STR_LENGTH]; … … 199 282 } 200 283 201 bool isEmpty() const 202 { 203 return ::RTUuidIsNull(&mUuid); 204 } 205 206 bool isNotEmpty() const 207 { 208 return !::RTUuidIsNull(&mUuid); 284 bool isValid() const 285 { 286 bool res = true; 287 if (mGuidState == INVALID_GUID) 288 res = false; 289 290 return res; 291 } 292 293 bool isZero() const 294 { 295 return (::RTUuidIsNull(&mUuid) && mGuidState == ZERO_GUID); 209 296 } 210 297 … … 257 344 if (ppGuid) 258 345 *ppGuid = (nsID *)nsMemory::Clone(&mUuid, sizeof(nsID)); 346 259 347 return *this; 260 348 } … … 309 397 static const Guid Empty; 310 398 399 protected: 400 401 bool isEmpty() const 402 { 403 return ::RTUuidIsNull(&mUuid); 404 } 405 406 bool isNotEmpty() const 407 { 408 return !::RTUuidIsNull(&mUuid); 409 } 410 311 411 private: 312 412 /** … … 327 427 /** The UUID. */ 328 428 RTUUID mUuid; 429 430 GuidState_t mGuidState; 329 431 330 432 #ifdef DEBUG … … 335 437 #endif 336 438 }; 337 439 /* 338 440 inline Bstr asGuidStr(const Bstr& str) 339 441 { … … 341 443 return guid.isEmpty() ? Bstr() : guid.toUtf16(); 342 444 } 343 445 */ 344 446 inline bool isValidGuid(const Bstr& str) 345 447 { 346 448 Guid guid(str); 347 return !guid.isEmpty(); 449 return guid.isValid(); 450 // return !guid.isEmpty(); 348 451 } 349 452
Note:
See TracChangeset
for help on using the changeset viewer.