Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef UT_UUID_H
00027 #define UT_UUID_H
00028
00029
00030
00031
00032
00033 #ifndef UT_TYPES_H
00034 #include "ut_types.h"
00035 #endif
00036 #include "ut_vector.h"
00037 #include <time.h>
00038
00039 #include <string>
00040
00041 class UT_UTF8String;
00042
00043
00044
00045 typedef enum
00046 {
00047 UT_UUID_VARIANT_NCS = 0,
00048 UT_UUID_VARIANT_DCE = 1,
00049 UT_UUID_VARIANT_MICROSOFT = 2,
00050 UT_UUID_VARIANT_OTHER = 3,
00051 UT_UUID_VARIANT_ERROR = 0xffffffff
00052 } UT_UUIDVariant;
00053
00054 struct uuid
00055 {
00056 UT_uint32 time_low;
00057 UT_uint16 time_mid;
00058 UT_uint16 time_high_and_version;
00059 UT_uint16 clock_seq;
00060 UT_Byte node[6];
00061 };
00062
00063
00064 class UT_UUIDGenerator;
00065
00066
00079 class ABI_EXPORT UT_UUID
00080 {
00081 public:
00082
00083
00084
00085
00086
00087
00088 virtual ~UT_UUID (){};
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 bool makeUUID();
00099 bool makeUUID(UT_UTF8String & out);
00100
00101
00102 bool setUUID(const UT_UTF8String &s);
00103 bool setUUID(const char *s);
00104 bool setUUID(const struct uuid &u);
00105
00106
00107
00108 bool toString(UT_UTF8String & to) const;
00109 std::string& toString( std::string& to ) const;
00110
00111
00112 bool toBinary(struct uuid &u) const;
00113
00114
00115 static bool toStringFromBinary(char * s, UT_uint32 len, const struct uuid &u);
00116
00117
00118
00119 UT_uint32 hash32() const;
00120 UT_uint64 hash64() const;
00121
00122
00123
00124 static const UT_UUID & getNull() {return s_Null;}
00125
00126
00127
00128 time_t getTime() const;
00129 UT_sint32 getType() const;
00130 UT_UUIDVariant getVariant() const;
00131
00132 bool resetTime();
00133
00134
00135
00136
00137 bool operator ==(const UT_UUID &u) const;
00138 bool operator !=(const UT_UUID &u) const;
00139 bool operator < (const UT_UUID &u) const;
00140 bool operator > (const UT_UUID &u) const;
00141
00142 UT_UUID & operator = (const UT_UUID &u);
00143
00144
00145 bool isOlder(const UT_UUID &u) const;
00146 bool isYounger(const UT_UUID &u) const;
00147 bool isOfSameAge(const UT_UUID &u) const;
00148
00149 bool isValid() const {return m_bIsValid;}
00150 bool isNull() const;
00151
00152
00153 void clear();
00154
00155 protected:
00156 friend class UT_UUIDGenerator;
00157
00158
00159
00160 UT_UUID();
00161 UT_UUID(const UT_UTF8String &s);
00162 UT_UUID(const char *s);
00163 UT_UUID(const struct uuid&u);
00164 UT_UUID(const UT_UUID &u);
00165
00166
00167
00168
00169 virtual bool _getRandomBytes(void *buf, int nbytes) const;
00170
00171 private:
00172 bool _parse(const char * in, struct uuid &u) const;
00173
00174 bool _makeUUID(struct uuid & u);
00175 bool _toString(const struct uuid &uu, UT_UTF8String & s) const;
00176
00177
00178
00179
00180 static time_t _getTime(const struct uuid & uu);
00181 static UT_sint32 _getType(const struct uuid &uu);
00182 static UT_UUIDVariant _getVariant(const struct uuid &uu);
00183
00184 bool _getClock(UT_uint32 &iHigh, UT_uint32 &iLow, UT_uint16 &iSeq) const;
00185
00186 private:
00187 uuid m_uuid;
00188 bool m_bIsValid;
00189 static bool s_bInitDone;
00190 static unsigned char s_node[6];
00191 static UT_UUID s_Null;
00192 };
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 class ABI_EXPORT UT_UUIDGenerator
00204 {
00205 public:
00206 UT_UUIDGenerator()
00207 :m_pUUID(NULL)
00208 {
00209 #if defined(UT_UUID_HASH_TEST) && defined(DEBUG)
00210 __test();
00211 #endif
00212 };
00213
00214 virtual ~UT_UUIDGenerator(){if(m_pUUID) delete m_pUUID;};
00215
00216
00217
00218 virtual UT_UUID * createUUID(){UT_UUID *p = new UT_UUID(); if(p)p->makeUUID(); return p;}
00219
00220 virtual UT_UUID * createUUID(const UT_UTF8String &s){return new UT_UUID(s);}
00221 virtual UT_UUID * createUUID(const char *s){return new UT_UUID(s);}
00222 virtual UT_UUID * createUUID(const UT_UUID &u){return new UT_UUID(u);}
00223 virtual UT_UUID * createUUID(const struct uuid &u){return new UT_UUID(u);}
00224
00225 UT_uint32 getNewUUID32();
00226 UT_uint64 getNewUUID64();
00227
00228 #if defined(UT_UUID_HASH_TEST) && defined(DEBUG)
00229 public:
00230 void __test();
00231 #endif
00232
00233 private:
00234
00235 UT_UUID * m_pUUID;
00236 };
00237
00238 #endif