Changeset 24446 in vbox
- Timestamp:
- Nov 6, 2009 2:38:35 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r19239 r24446 62 62 public: 63 63 64 Guid () { ::RTUuidClear (&uuid); } 65 Guid (const Guid &that) { uuid = that.uuid; } 66 Guid (const RTUUID &that) { uuid = that; } 67 68 Guid (const GUID &that) 69 { 70 AssertCompileSize (GUID, sizeof (RTUUID)); 71 ::memcpy (&uuid, &that, sizeof (GUID)); 72 } 73 74 Guid (const char *that) 75 { 76 ::RTUuidClear (&uuid); 77 ::RTUuidFromStr (&uuid, that); 78 } 79 80 Guid (const Bstr &that) 64 Guid() 65 { 66 ::RTUuidClear(&uuid); 67 refresh(); 68 } 69 70 Guid(const Guid &that) 71 { 72 uuid = that.uuid; 73 refresh(); 74 } 75 76 Guid(const RTUUID &that) 77 { 78 uuid = that; 79 refresh(); 80 } 81 82 Guid(const GUID &that) 83 { 84 AssertCompileSize(GUID, sizeof(RTUUID)); 85 ::memcpy(&uuid, &that, sizeof(GUID)); 86 refresh(); 87 } 88 89 Guid(const char *that) 90 { 91 ::RTUuidClear(&uuid); 92 ::RTUuidFromStr(&uuid, that); 93 refresh(); 94 } 95 96 Guid(const Bstr &that) 81 97 { 82 98 ::RTUuidClear (&uuid); 83 99 if (!that.isNull()) 84 100 ::RTUuidFromUtf16(&uuid, that.raw()); 85 } 86 87 Guid &operator= (const Guid &that) 88 { 89 ::memcpy (&uuid, &that.uuid, sizeof (RTUUID)); 90 return *this; 91 } 92 Guid &operator= (const GUID &guid) 93 { 94 ::memcpy (&uuid, &guid, sizeof (GUID)); 95 return *this; 96 } 97 Guid &operator= (const RTUUID &guid) 98 { 99 ::memcpy (&uuid, &guid, sizeof (RTUUID)); 100 return *this; 101 } 102 Guid &operator= (const char *str) 103 { 104 ::RTUuidFromStr (&uuid, str); 105 return *this; 106 } 107 108 void create() { ::RTUuidCreate (&uuid); } 109 void clear() { ::RTUuidClear (&uuid); } 110 111 Utf8Str toString () const 112 { 113 char buf [RTUUID_STR_LENGTH]; 114 ::RTUuidToStr (&uuid, buf, RTUUID_STR_LENGTH); 115 return Utf8Str (buf); 101 refresh(); 102 } 103 104 Guid &operator=(const Guid &that) 105 { 106 ::memcpy(&uuid, &that.uuid, sizeof (RTUUID)); 107 refresh(); 108 return *this; 109 } 110 Guid &operator=(const GUID &guid) 111 { 112 ::memcpy(&uuid, &guid, sizeof (GUID)); 113 refresh(); 114 return *this; 115 } 116 Guid &operator=(const RTUUID &guid) 117 { 118 ::memcpy(&uuid, &guid, sizeof (RTUUID)); 119 refresh(); 120 return *this; 121 } 122 Guid &operator=(const char *str) 123 { 124 ::RTUuidFromStr(&uuid, str); 125 refresh(); 126 return *this; 127 } 128 129 void create() 130 { 131 ::RTUuidCreate(&uuid); 132 refresh(); 133 } 134 void clear() 135 { 136 ::RTUuidClear(&uuid); 137 refresh(); 138 } 139 140 Utf8Str toString() const 141 { 142 char buf[RTUUID_STR_LENGTH]; 143 ::RTUuidToStr(&uuid, buf, RTUUID_STR_LENGTH); 144 return Utf8Str(buf); 116 145 } 117 146 … … 121 150 return Bstr(); 122 151 123 RTUTF16 buf [RTUUID_STR_LENGTH]; 124 ::RTUuidToUtf16 (&uuid, buf, RTUUID_STR_LENGTH); 125 return Bstr (buf); 126 } 127 128 bool isEmpty() const { return ::RTUuidIsNull (&uuid); } 129 operator bool() const { return !isEmpty(); } 130 131 bool operator== (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; } 132 bool operator== (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; } 133 bool operator!= (const Guid &that) const { return !operator==(that); } 134 bool operator!= (const GUID &guid) const { return !operator==(guid); } 135 bool operator< (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; } 136 bool operator< (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; } 152 RTUTF16 buf[RTUUID_STR_LENGTH]; 153 ::RTUuidToUtf16(&uuid, buf, RTUUID_STR_LENGTH); 154 return Bstr(buf); 155 } 156 157 bool isEmpty() const 158 { 159 return ::RTUuidIsNull (&uuid); 160 } 161 162 operator bool() const 163 { 164 return !isEmpty(); 165 } 166 167 bool operator==(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; } 168 bool operator==(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; } 169 bool operator!=(const Guid &that) const { return !operator==(that); } 170 bool operator!=(const GUID &guid) const { return !operator==(guid); } 171 bool operator<(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; } 172 bool operator<(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; } 137 173 138 174 /* to pass instances as IN_GUID parameters to interface methods */ 139 operator const GUID &() const { return *(GUID *) &uuid; } 175 operator const GUID&() const 176 { 177 return *(GUID *) &uuid; 178 } 140 179 141 180 /* to directly pass instances to RTPrintf("%Vuuid") */ 142 PRTUUID ptr() { return &uuid; } 181 PRTUUID ptr() 182 { 183 return &uuid; 184 } 143 185 144 186 /* to pass instances to printf-like functions */ 145 PCRTUUID raw() const { return &uuid; } 187 PCRTUUID raw() const 188 { 189 return &uuid; 190 } 146 191 147 192 /* to pass instances to RTUuid*() as a constant argument */ 148 operator const RTUUID * () const { return &uuid; } 193 operator const RTUUID*() const 194 { 195 return &uuid; 196 } 149 197 150 198 #if !defined (VBOX_WITH_XPCOM) … … 154 202 const Guid &cloneTo (GUID *pguid) const 155 203 { 156 if (pguid) { ::memcpy (pguid, &uuid, sizeof (GUID)); } 204 if (pguid) 205 ::memcpy(pguid, &uuid, sizeof(GUID)); 157 206 return *this; 158 207 } 159 208 160 209 /* to pass instances as OUT_GUID parameters to interface methods */ 161 GUID *asOutParam() { return (GUID *) &uuid; } 210 GUID *asOutParam() 211 { 212 return (GUID*)&uuid; 213 } 162 214 163 215 #else … … 171 223 } 172 224 173 /* internal helper class for asOutParam() */ 225 // internal helper class for asOutParam(); this takes a GUID refrence 226 // in the constructor and copies the uuid from the method to that instance 227 // in its destructor 174 228 class GuidOutParam 175 229 { 176 GuidOutParam (Guid &guid) : ptr (0), outer (guid) { outer.clear(); } 230 GuidOutParam(Guid &guid) 231 : ptr(0), 232 outer(guid) 233 { 234 outer.clear(); 235 } 236 177 237 nsID *ptr; 178 238 Guid &outer; 179 GuidOutParam 180 GuidOutParam &operator= 239 GuidOutParam(const GuidOutParam &that); // disabled 240 GuidOutParam &operator=(const GuidOutParam &that); // disabled 181 241 public: 182 operator nsID 242 operator nsID**() { return &ptr; } 183 243 ~GuidOutParam() 184 244 { 185 if (ptr && outer.isEmpty()) { outer = *ptr; nsMemory::Free (ptr); } 245 if (ptr && outer.isEmpty()) 246 { 247 outer = *ptr; 248 outer.refresh(); 249 nsMemory::Free(ptr); 250 } 186 251 } 187 252 friend class Guid; … … 189 254 190 255 /* to pass instances as OUT_GUID parameters to interface methods */ 191 GuidOutParam asOutParam() { return GuidOutParam 256 GuidOutParam asOutParam() { return GuidOutParam(*this); } 192 257 193 258 #endif 194 259 195 260 /* to directly test IN_GUID interface method's parameters */ 196 static bool isEmpty 197 { 198 return ::RTUuidIsNull ((PRTUUID)&guid);261 static bool isEmpty(const GUID &guid) 262 { 263 return ::RTUuidIsNull((PRTUUID)&guid); 199 264 } 200 265 … … 205 270 206 271 private: 272 // in debug code, refresh the UUID string representatino for 273 // debugging; must be called every time the internal uuid 274 // changes; compiles to nothing in release code 275 inline void refresh() 276 { 277 #ifdef DEBUG 278 ::RTUuidToStr(&uuid, szUUID, RTUUID_STR_LENGTH); 279 pcszUUID = szUUID; 280 #endif 281 } 207 282 208 283 RTUUID uuid; 284 285 #ifdef DEBUG 286 // in debug builds, have a Utf8Str representation of the UUID so we can look 287 // at it in the debugger more easily 288 char szUUID[RTUUID_STR_LENGTH]; 289 const char *pcszUUID; 290 #endif 209 291 }; 210 292
Note:
See TracChangeset
for help on using the changeset viewer.