Changeset 34071 in vbox for trunk/include/VBox/com
- Timestamp:
- Nov 15, 2010 3:35:10 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67759
- Location:
- trunk/include/VBox/com
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r32781 r34071 1 1 /* $Id$ */ 2 3 2 /** @file 4 * MS COM / XPCOM Abstraction Layer: 5 * Guid class declaration 3 * MS COM / XPCOM Abstraction Layer - Guid class declaration. 6 4 */ 7 5 … … 38 36 #endif 39 37 40 #if defined 41 # include <nsMemory.h>38 #if defined(VBOX_WITH_XPCOM) 39 # include <nsMemory.h> 42 40 #endif 43 41 … … 45 43 46 44 #include <iprt/uuid.h> 45 #include <iprt/err.h> 47 46 48 47 namespace com … … 59 58 Guid() 60 59 { 61 ::RTUuidClear(& uuid);60 ::RTUuidClear(&mUuid); 62 61 refresh(); 63 62 } … … 65 64 Guid(const Guid &that) 66 65 { 67 uuid = that.uuid;66 mUuid = that.mUuid; 68 67 refresh(); 69 68 } … … 71 70 Guid(const RTUUID &that) 72 71 { 73 uuid = that;72 mUuid = that; 74 73 refresh(); 75 74 } … … 78 77 { 79 78 AssertCompileSize(GUID, sizeof(RTUUID)); 80 ::memcpy(&uuid, &that, sizeof(GUID)); 81 refresh(); 82 } 83 79 ::memcpy(&mUuid, &that, sizeof(GUID)); 80 refresh(); 81 } 82 83 /** 84 * Construct a GUID from a string. 85 * 86 * Should the string be invalid, the object will be set to the null GUID 87 * (isEmpty() == true). 88 * 89 * @param that The UUID string. We feed this to RTUuidFromStr(), 90 * so check it out for the exact format. 91 */ 84 92 Guid(const char *that) 85 93 { 86 ::RTUuidClear(&uuid); 87 ::RTUuidFromStr(&uuid, that); 88 refresh(); 89 } 90 94 int rc = ::RTUuidFromStr(&mUuid, that); 95 if (RT_FAILURE(rc)) 96 ::RTUuidClear(&mUuid); 97 refresh(); 98 } 99 100 /** 101 * Construct a GUID from a BSTR. 102 * 103 * Should the string be empty or invalid, the object will be set to the 104 * null GUID (isEmpty() == true). 105 * 106 * @param that The UUID BSTR. We feed this to RTUuidFromUtf16(), 107 * so check it out for the exact format. 108 */ 91 109 Guid(const Bstr &that) 92 110 { 93 ::RTUuidClear(&uuid); 94 if (!that.isEmpty()) 95 ::RTUuidFromUtf16(&uuid, that.raw()); 111 int rc = !that.isEmpty() 112 ? ::RTUuidFromUtf16(&mUuid, that.raw()) 113 : VERR_INVALID_UUID_FORMAT; 114 if (RT_FAILURE(rc)) 115 ::RTUuidClear(&mUuid); 96 116 refresh(); 97 117 } … … 99 119 Guid& operator=(const Guid &that) 100 120 { 101 ::memcpy(& uuid, &that.uuid, sizeof (RTUUID));121 ::memcpy(&mUuid, &that.mUuid, sizeof (RTUUID)); 102 122 refresh(); 103 123 return *this; … … 105 125 Guid& operator=(const GUID &guid) 106 126 { 107 ::memcpy(& uuid, &guid, sizeof (GUID));127 ::memcpy(&mUuid, &guid, sizeof (GUID)); 108 128 refresh(); 109 129 return *this; … … 111 131 Guid& operator=(const RTUUID &guid) 112 132 { 113 ::memcpy(& uuid, &guid, sizeof (RTUUID));133 ::memcpy(&mUuid, &guid, sizeof (RTUUID)); 114 134 refresh(); 115 135 return *this; … … 117 137 Guid& operator=(const char *str) 118 138 { 119 ::RTUuidFromStr(&uuid, str); 139 int rc = ::RTUuidFromStr(&mUuid, str); 140 if (RT_FAILURE(rc)) 141 ::RTUuidClear(&mUuid); 120 142 refresh(); 121 143 return *this; … … 124 146 void create() 125 147 { 126 ::RTUuidCreate(& uuid);148 ::RTUuidCreate(&mUuid); 127 149 refresh(); 128 150 } 129 151 void clear() 130 152 { 131 ::RTUuidClear(&uuid); 132 refresh(); 133 } 134 153 ::RTUuidClear(&mUuid); 154 refresh(); 155 } 156 157 /** 158 * Convert the GUID to a string. 159 * 160 * @returns String object containing the formatted GUID. 161 * @throws std::bad_alloc 162 */ 135 163 Utf8Str toString() const 136 164 { 137 165 char buf[RTUUID_STR_LENGTH]; 138 ::RTUuidToStr(& uuid, buf, RTUUID_STR_LENGTH);166 ::RTUuidToStr(&mUuid, buf, RTUUID_STR_LENGTH); 139 167 return Utf8Str(buf); 140 168 } … … 142 170 /** 143 171 * Like toString, but encloses the returned string in curly brackets. 144 * @return 172 * 173 * @returns String object containing the formatted GUID in curly brackets. 174 * @throws std::bad_alloc 145 175 */ 146 176 Utf8Str toStringCurly() const 147 177 { 148 178 char buf[RTUUID_STR_LENGTH + 2] = "{"; 149 ::RTUuidToStr(& uuid, buf + 1, RTUUID_STR_LENGTH);179 ::RTUuidToStr(&mUuid, buf + 1, RTUUID_STR_LENGTH); 150 180 buf[sizeof(buf) - 2] = '}'; 151 181 buf[sizeof(buf) - 1] = '\0'; … … 153 183 } 154 184 185 /** 186 * Convert the GUID to a string. 187 * 188 * @returns Bstr object containing the formatted GUID. 189 * @throws std::bad_alloc 190 */ 155 191 Bstr toUtf16() const 156 192 { … … 159 195 160 196 RTUTF16 buf[RTUUID_STR_LENGTH]; 161 ::RTUuidToUtf16(& uuid, buf, RTUUID_STR_LENGTH);197 ::RTUuidToUtf16(&mUuid, buf, RTUUID_STR_LENGTH); 162 198 return Bstr(buf); 163 199 } … … 165 201 bool isEmpty() const 166 202 { 167 return ::RTUuidIsNull (&uuid); 168 } 169 170 bool operator==(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; } 171 bool operator==(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; } 203 return ::RTUuidIsNull(&mUuid); 204 } 205 206 bool isNotEmpty() const 207 { 208 return !::RTUuidIsNull(&mUuid); 209 } 210 211 bool operator==(const Guid &that) const { return ::RTUuidCompare(&mUuid, &that.mUuid) == 0; } 212 bool operator==(const GUID &guid) const { return ::RTUuidCompare(&mUuid, (PRTUUID)&guid) == 0; } 172 213 bool operator!=(const Guid &that) const { return !operator==(that); } 173 214 bool operator!=(const GUID &guid) const { return !operator==(guid); } 174 bool operator<(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; } 175 bool operator<(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; } 176 177 /* to directly copy the contents to a GUID, or for passing it as 178 * an input parameter of type (const GUID *), the compiler converts */ 215 bool operator<( const Guid &that) const { return ::RTUuidCompare(&mUuid, &that.mUuid) < 0; } 216 bool operator<( const GUID &guid) const { return ::RTUuidCompare(&mUuid, (PRTUUID)&guid) < 0; } 217 218 /** 219 * To directly copy the contents to a GUID, or for passing it as an input 220 * parameter of type (const GUID *), the compiler converts. */ 179 221 const GUID &ref() const 180 222 { 181 return *(const GUID *)&uuid; 182 } 183 184 /* to pass instances to printf-like functions */ 223 return *(const GUID *)&mUuid; 224 } 225 226 /** 227 * To pass instances to printf-like functions. 228 */ 185 229 PCRTUUID raw() const 186 230 { 187 return (PCRTUUID)& uuid;188 } 189 190 #if !defined 191 192 /* to assign instances to OUT_GUID parameters from within the193 * interface method*/194 const Guid &cloneTo 231 return (PCRTUUID)&mUuid; 232 } 233 234 #if !defined(VBOX_WITH_XPCOM) 235 236 /** To assign instances to OUT_GUID parameters from within the interface 237 * method. */ 238 const Guid &cloneTo(GUID *pguid) const 195 239 { 196 240 if (pguid) 197 ::memcpy(pguid, & uuid, sizeof(GUID));198 return *this; 199 } 200 201 /* to pass instances as OUT_GUID parameters to interface methods*/241 ::memcpy(pguid, &mUuid, sizeof(GUID)); 242 return *this; 243 } 244 245 /** To pass instances as OUT_GUID parameters to interface methods. */ 202 246 GUID *asOutParam() 203 247 { 204 return (GUID *)&uuid;248 return (GUID *)&mUuid; 205 249 } 206 250 207 251 #else 208 252 209 /* to assign instances to OUT_GUID parameters from within the253 /** To assign instances to OUT_GUID parameters from within the 210 254 * interface method */ 211 const Guid &cloneTo (nsID **ppguid) const 212 { 213 if (ppguid) { *ppguid = (nsID *) nsMemory::Clone (&uuid, sizeof (nsID)); } 214 return *this; 215 } 216 217 // internal helper class for asOutParam(); this takes a GUID refrence 218 // in the constructor and copies the uuid from the method to that instance 219 // in its destructor 255 const Guid &cloneTo(nsID **ppGuid) const 256 { 257 if (ppGuid) 258 *ppGuid = (nsID *)nsMemory::Clone(&mUuid, sizeof(nsID)); 259 return *this; 260 } 261 262 /** 263 * Internal helper class for asOutParam(). 264 * 265 * This takes a GUID refrence in the constructor and copies the mUuid from 266 * the method to that instance in its destructor. 267 */ 220 268 class GuidOutParam 221 269 { … … 245 293 }; 246 294 247 /* to pass instances as OUT_GUID parameters to interface methods */295 /** to pass instances as OUT_GUID parameters to interface methods */ 248 296 GuidOutParam asOutParam() { return GuidOutParam(*this); } 249 297 … … 262 310 263 311 private: 264 // in debug code, refresh the UUID string representatino for 265 // debugging; must be called every time the internal uuid 266 // changes; compiles to nothing in release code 312 /** 313 * Refresh the debug-only UUID string. 314 * 315 * In debug code, refresh the UUID string representatino for debugging; 316 * must be called every time the internal uuid changes; compiles to nothing 317 * in release code. 318 */ 267 319 inline void refresh() 268 320 { 269 321 #ifdef DEBUG 270 ::RTUuidToStr(&uuid, szUUID, RTUUID_STR_LENGTH); 271 pcszUUID = szUUID; 272 #endif 273 } 274 275 RTUUID uuid; 322 ::RTUuidToStr(&mUuid, mszUuid, RTUUID_STR_LENGTH); 323 m_pcszUUID = mszUuid; 324 #endif 325 } 326 327 /** The UUID. */ 328 RTUUID mUuid; 276 329 277 330 #ifdef DEBUG 278 / / in debug builds, have a Utf8Str representation of the UUID so we can look279 // at it in the debugger more easily280 char szUUID[RTUUID_STR_LENGTH];281 const char * pcszUUID;331 /** String representation of mUuid for printing in the debugger. */ 332 char mszUuid[RTUUID_STR_LENGTH]; 333 /** Another string variant for the debugger, points to szUUID. */ 334 const char *m_pcszUUID; 282 335 #endif 283 336 }; … … 286 339 { 287 340 Guid guid(str); 288 return 341 return guid.isEmpty() ? Bstr() : guid.toUtf16(); 289 342 } 290 343 … … 292 345 { 293 346 Guid guid(str); 294 return 347 return !guid.isEmpty(); 295 348 } 296 349 297 350 } /* namespace com */ 298 351 299 #endif /* ___VBox_com_Guid_h */300 352 #endif /* !___VBox_com_Guid_h */ 353
Note:
See TracChangeset
for help on using the changeset viewer.