| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
#ifndef ___VBox_com_Guid_h |
|---|
| 34 |
#define ___VBox_com_Guid_h |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
#ifndef __STDC_LIMIT_MACROS |
|---|
| 38 |
# define __STDC_LIMIT_MACROS |
|---|
| 39 |
#endif |
|---|
| 40 |
#ifndef __STDC_CONSTANT_MACROS |
|---|
| 41 |
# define __STDC_CONSTANT_MACROS |
|---|
| 42 |
#endif |
|---|
| 43 |
|
|---|
| 44 |
#if defined (VBOX_WITH_XPCOM) |
|---|
| 45 |
#include <nsMemory.h> |
|---|
| 46 |
#endif |
|---|
| 47 |
|
|---|
| 48 |
#include "VBox/com/string.h" |
|---|
| 49 |
|
|---|
| 50 |
#include <iprt/cpputils.h> |
|---|
| 51 |
#include <iprt/uuid.h> |
|---|
| 52 |
|
|---|
| 53 |
namespace com |
|---|
| 54 |
{ |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
class Guid |
|---|
| 61 |
{ |
|---|
| 62 |
public: |
|---|
| 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 &operator= (const Guid &that) |
|---|
| 81 |
{ |
|---|
| 82 |
::memcpy (&uuid, &that.uuid, sizeof (RTUUID)); |
|---|
| 83 |
return *this; |
|---|
| 84 |
} |
|---|
| 85 |
Guid &operator= (const GUID &guid) |
|---|
| 86 |
{ |
|---|
| 87 |
::memcpy (&uuid, &guid, sizeof (GUID)); |
|---|
| 88 |
return *this; |
|---|
| 89 |
} |
|---|
| 90 |
Guid &operator= (const RTUUID &guid) |
|---|
| 91 |
{ |
|---|
| 92 |
::memcpy (&uuid, &guid, sizeof (RTUUID)); |
|---|
| 93 |
return *this; |
|---|
| 94 |
} |
|---|
| 95 |
Guid &operator= (const char *str) |
|---|
| 96 |
{ |
|---|
| 97 |
::RTUuidFromStr (&uuid, str); |
|---|
| 98 |
return *this; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
void create() { ::RTUuidCreate (&uuid); } |
|---|
| 102 |
void clear() { ::RTUuidClear (&uuid); } |
|---|
| 103 |
|
|---|
| 104 |
Utf8Str toString () const |
|---|
| 105 |
{ |
|---|
| 106 |
char buf [RTUUID_STR_LENGTH]; |
|---|
| 107 |
::RTUuidToStr (&uuid, buf, RTUUID_STR_LENGTH); |
|---|
| 108 |
return Utf8Str (buf); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
bool isEmpty() const { return ::RTUuidIsNull (&uuid); } |
|---|
| 112 |
operator bool() const { return !isEmpty(); } |
|---|
| 113 |
|
|---|
| 114 |
bool operator== (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; } |
|---|
| 115 |
bool operator== (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; } |
|---|
| 116 |
bool operator!= (const Guid &that) const { return !operator==(that); } |
|---|
| 117 |
bool operator!= (const GUID &guid) const { return !operator==(guid); } |
|---|
| 118 |
bool operator< (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; } |
|---|
| 119 |
bool operator< (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; } |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
operator const GUID &() const { return *(GUID *) &uuid; } |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
PRTUUID ptr() { return &uuid; } |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
PCRTUUID raw() const { return &uuid; } |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
operator const RTUUID * () const { return &uuid; } |
|---|
| 132 |
|
|---|
| 133 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
const Guid &cloneTo (GUID *pguid) const |
|---|
| 138 |
{ |
|---|
| 139 |
if (pguid) { ::memcpy (pguid, &uuid, sizeof (GUID)); } |
|---|
| 140 |
return *this; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
GUID *asOutParam() { return (GUID *) &uuid; } |
|---|
| 145 |
|
|---|
| 146 |
#else |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
const Guid &cloneTo (nsID **ppguid) const |
|---|
| 151 |
{ |
|---|
| 152 |
if (ppguid) { *ppguid = (nsID *) nsMemory::Clone (&uuid, sizeof (nsID)); } |
|---|
| 153 |
return *this; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
class GuidOutParam |
|---|
| 158 |
{ |
|---|
| 159 |
GuidOutParam (Guid &guid) : ptr (0), outer (guid) { outer.clear(); } |
|---|
| 160 |
nsID *ptr; |
|---|
| 161 |
Guid &outer; |
|---|
| 162 |
GuidOutParam (const GuidOutParam &that); |
|---|
| 163 |
GuidOutParam &operator= (const GuidOutParam &that); |
|---|
| 164 |
public: |
|---|
| 165 |
operator nsID **() { return &ptr; } |
|---|
| 166 |
~GuidOutParam() |
|---|
| 167 |
{ |
|---|
| 168 |
if (ptr && outer.isEmpty()) { outer = *ptr; nsMemory::Free (ptr); } |
|---|
| 169 |
} |
|---|
| 170 |
friend class Guid; |
|---|
| 171 |
}; |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
GuidOutParam asOutParam() { return GuidOutParam (*this); } |
|---|
| 175 |
|
|---|
| 176 |
#endif |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
static bool isEmpty (const GUID &guid) |
|---|
| 180 |
{ |
|---|
| 181 |
return ::RTUuidIsNull ((PRTUUID) &guid); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
static const Guid Empty; |
|---|
| 188 |
|
|---|
| 189 |
private: |
|---|
| 190 |
|
|---|
| 191 |
RTUUID uuid; |
|---|
| 192 |
}; |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP (Guid); |
|---|
| 196 |
|
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
#endif |
|---|
| 200 |
|
|---|