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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __UT_Guid__
00038 #define __UT_Guid__
00039
00040 #include "UT_API.h"
00041 #include <iostream.h>
00042 #include "UT_Hash.h"
00043
00044 class UT_String;
00045 class UT_IStream;
00046
00047 class UT_API UT_Guid
00048 {
00049 public:
00050 explicit UT_Guid();
00051 explicit UT_Guid(const UT_Guid &src);
00052 ~UT_Guid();
00053
00054 enum { theStringSize = 43 };
00055 enum { theBinarySize = 16 };
00056 bool setString(const char *str);
00057 void getString(UT_String &str) const;
00058
00059 bool operator==(const UT_Guid &cmp) const;
00060 bool operator!=(const UT_Guid &cmp) const;
00061 const UT_Guid &operator=(const UT_Guid &src);
00062
00063 void writeBinary(ostream &os) const;
00064 bool readBinary(UT_IStream &is);
00065 bool readAscii(UT_IStream &is);
00066
00067 friend UT_API ostream &operator<<(ostream &os, const UT_Guid &guid);
00068
00069 private:
00070 static void initializeValues();
00071
00072 int myRandom;
00073 int myPid;
00074 int myTime;
00075 int myUniqueCount;
00076
00077 static int theRandomBase;
00078 static int thePid;
00079 static int theStartTime;
00080 static int theNextUniqueCount;
00081 static bool theValuesInitialized;
00082
00083 friend class UT_GuidHash;
00084 };
00085
00086 class UT_API UT_GuidHash : public UT_Hash
00087 {
00088 public:
00089 UT_GuidHash(const UT_Guid &uniqueid)
00090 : myGuid(uniqueid)
00091 { }
00092 virtual ~UT_GuidHash()
00093 { }
00094
00095 virtual int compare(const UT_Hash &a) const
00096 {
00097 const UT_GuidHash &b = (const UT_GuidHash &)a;
00098 int d;
00099
00100 d = myGuid.myUniqueCount - b.myGuid.myUniqueCount;
00101 if( d ) return ((d < 0) ? -1 : 1);
00102 d = myGuid.myTime - b.myGuid.myTime;
00103 if( d ) return ((d < 0) ? -1 : 1);
00104 d = myGuid.myPid - b.myGuid.myPid;
00105 if( d ) return ((d < 0) ? -1 : 1);
00106 d = myGuid.myRandom - b.myGuid.myRandom;
00107 if( d ) return ((d < 0) ? -1 : 1);
00108
00109 return 0;
00110 }
00111 virtual void copy(const UT_Hash &a)
00112 {
00113 myGuid = static_cast<const UT_GuidHash&>(a).myGuid;
00114 }
00115 virtual unsigned hash() const
00116 {
00117 return SYSwang_inthash(myGuid.myUniqueCount);
00118 }
00119 virtual UT_Hash *copy() const
00120 {
00121 return new UT_GuidHash(myGuid);
00122 }
00123 virtual int64 getMemUsage() const
00124 {
00125 return sizeof(*this);
00126 }
00127
00128 private:
00129 UT_Guid myGuid;
00130 };
00131
00132 #endif
00133