#include <PseudoUuid.h>
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] |
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.
PseudoUuid::PseudoUuid | ( | ) | [explicit] |
PseudoUuid::PseudoUuid | ( | std::string | uuid | ) |
PseudoUuid::~PseudoUuid | ( | ) | [virtual] |
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 // REVIEW: SWZ: 9/22/2006: Consider using a different mode. V1 seems 00063 // weak, but v3 and v5 seem reasonable. They require arguments, however. 00064 // Also, uuid_make never returns error for V4, but might for others. 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 | ( | ) |
Generates a bogus constant UUID.
Definition at line 102 of file PseudoUuid.cpp.
References data.
Referenced by LogicalTxnTest::LogicalTxnTest(), VersionedSegment::notifyPageDirty(), PseudoUuidTest::testCopy(), PseudoUuidTest::testInvalid(), and VersionedSegmentTest::VersionedSegmentTest().
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 // NOTE: libuuid has either uuid_unparse or uuid_export (depending on 00142 // the library's version). Those two methods produce different output 00143 // for the same UUID. 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 |
Returns the hash code for the UUID.
Definition at line 130 of file PseudoUuid.cpp.
References data.
00131 { 00132 return 00133 ((int)(data[0] ^ data[4] ^ data[8] ^ data[12]) & 0xFF) << 24 | 00134 ((int)(data[1] ^ data[5] ^ data[9] ^ data[13]) & 0xFF) << 16 | 00135 ((int)(data[2] ^ data[6] ^ data[10] ^ data[14]) & 0xFF) << 8 | 00136 ((int)(data[3] ^ data[7] ^ data[11] ^ data[15]) & 0xFF); 00137 }
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] |
uint8_t PseudoUuid::getByte | ( | int | ) | const |
Definition at line 114 of file PseudoUuid.cpp.
References data.
Referenced by PseudoUuidTest::testGeneration(), PseudoUuidTest::testInvalid(), and PseudoUuidTest::testParsing().
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) |
Converts an input UUID string of the form 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb into the internal representation.
FennelExcn | if the String is not in the correct format. |
Referenced by JniPseudoUuidGenerator::generateUuid().
static const int PseudoUuid::UUID_LENGTH = UUID_LEN_BIN [static] |
Definition at line 62 of file PseudoUuid.h.
Referenced by generate(), PseudoUuidTest::testGeneration(), PseudoUuidTest::testInvalid(), and PseudoUuidTest::testParsing().
uuid_t PseudoUuid::data [protected] |
Definition at line 69 of file PseudoUuid.h.
Referenced by generate(), generateInvalid(), getByte(), getBytes(), hashCode(), operator==(), PseudoUuid(), toString(), and ~PseudoUuid().
uint8_t PseudoUuid::data[UUID_LENGTH] [protected] |
Definition at line 77 of file PseudoUuid.h.