Fennel: PseudoUuid Class Reference (original) (raw)
Wrapper for a UUID. More...
#include <[PseudoUuid.h](PseudoUuid%5F8h-source.html)>
| Public Member Functions | |
|---|---|
| PseudoUuid () | |
| PseudoUuid (std::string uuid) | |
| virtual | ~PseudoUuid () |
| void | generate () |
| Generates a new UUID. | |
| void | generateInvalid () |
| Generates a bogus constant UUID. | |
| std::string | toString () const |
| Converts the UUID into a string of the form 1b4e28ba-2fa1-11d2-883f-b9a76. | |
| int | hashCode () const |
| Returns the hash code for the UUID. | |
| bool | operator== (PseudoUuid const &) const |
| bool | operator!= (PseudoUuid const &other) const |
| uint8_t | getByte (int) const |
| const uint8_t * | getBytes () const |
| void | parse (std::string uuid) throw (FennelExcn) |
| Converts an input UUID string of the form 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb into the internal representation. | |
| Static Public Attributes | |
| static const int | UUID_LENGTH = UUID_LEN_BIN |
| Protected Attributes | |
| uuid_t | data |
| uint8_t | data [UUID_LENGTH] |
Detailed Description
Wrapper for a UUID.
Since real UUID generation may not be available on all systems, use this instead (may be real, may be fake). Note that the default constructor leaves the value uninitialized; call generate to get a new UUID.
Definition at line 58 of file PseudoUuid.h.
Constructor & Destructor Documentation
| PseudoUuid::PseudoUuid | ( | | ) | [explicit] | | ---------------------- | - | | - | ------------ |
| PseudoUuid::PseudoUuid | ( | std::string | uuid | ) |
|---|
| PseudoUuid::~PseudoUuid | ( | | ) | [virtual] | | ------------------------ | - | | - | ----------- |
Member Function Documentation
| void PseudoUuid::generate | ( | | ) | | ------------------------- | - | | - |
Generates a new UUID.
Definition at line 54 of file PseudoUuid.cpp.
References data, and UUID_LENGTH.
Referenced by PseudoUuidGenerator::generateUuid(), and PseudoUuidTest::testGeneration().
00055 {
00056 #ifdef FENNEL_UUID_REAL_NEW
00057 uuid_t *apiData;
00058
00059 uuid_rc_t result = uuid_create(&apiData);
00060 assert(result == UUID_RC_OK);
00061
00062
00063
00064
00065 result = uuid_make(apiData, UUID_MAKE_V4);
00066 assert(result == UUID_RC_OK);
00067
00068 size_t len = UUID_LENGTH;
00069 result =
00070 uuid_export(
00071 apiData,
00072 UUID_FMT_BIN,
00073 reinterpret_cast<void **>(&data),
00074 &len);
00075 assert(result == UUID_RC_OK);
00076
00077 result = uuid_destroy(apiData);
00078 assert(result == UUID_RC_OK);
00079 #else
00080
00081 #ifdef FENNEL_UUID_REAL
00082
00083 uuid_generate(data);
00084
00085 #else
00086
00087 memset(&data,0,sizeof(data));
00088 #ifdef MSVC
00089 assert(sizeof(data) == sizeof(UUID));
00090 UuidCreate((UUID *) data);
00091 #else
00092 int x = rand();
00093 assert(sizeof(x) <= sizeof(data));
00094 memcpy(&data,&x,sizeof(x));
00095 #endif
00096
00097 #endif
00098
00099 #endif
00100 }
| void PseudoUuid::generateInvalid | ( | | ) | | -------------------------------- | - | | - |
| string PseudoUuid::toString | ( | | ) | const | | --------------------------- | - | | - | ----- |
Converts the UUID into a string of the form 1b4e28ba-2fa1-11d2-883f-b9a76.
Definition at line 139 of file PseudoUuid.cpp.
References data.
Referenced by operator<<(), and PseudoUuidTest::testFormatting().
00140 {
00141
00142
00143
00144 ostringstream ostr;
00145
00146 for (int i = 0; i < sizeof(data); i++) {
00147 if (i == 4 || i == 6 || i == 8 || i == 10) {
00148 ostr << "-";
00149 }
00150
00151 ostr << hex << setw(2) << setfill('0') << (int) (data[i] & 0xFF);
00152 }
00153
00154 return ostr.str();
00155 }
| int PseudoUuid::hashCode | ( | | ) | const | | ------------------------ | - | | - | ----- |
| bool PseudoUuid::operator== | ( | PseudoUuid const & | | ) | const | | --------------------------- | - | ------------------------------------------ | | - | ----- |
Definition at line 107 of file PseudoUuid.cpp.
References data.
00108 { 00109 return (memcmp(data,other.data,sizeof(data)) == 0); 00110 }
| bool PseudoUuid::operator!= | ( | PseudoUuid const & | other | ) | const [inline] |
|---|
Definition at line 109 of file PseudoUuid.h.
00110 { 00111 return !(*this == other); 00112 }
| uint8_t PseudoUuid::getByte | ( | int | | ) | const | | -------------------------------------------------------------------------------- | - | --- | | - | ----- |
| const uint8_t * PseudoUuid::getBytes | ( | | ) | const | | ------------------------------------------------------------------------------------------ | - | | - | ----- |
Definition at line 121 of file PseudoUuid.cpp.
References data.
00122 { 00123 #ifdef FENNEL_UUID_REAL 00124 return reinterpret_cast<const uint8_t *>(&data); 00125 #else 00126 return data; 00127 #endif 00128 }
| void PseudoUuid::parse | ( | std::string | uuid | ) | throw (FennelExcn) |
|---|
Member Data Documentation
The documentation for this class was generated from the following files:
- /home/pub/open/dev/fennel/common/PseudoUuid.h
- /home/pub/open/dev/fennel/common/PseudoUuid.cpp
