HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Guid.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Guid.h ( UT Library, C++)
7  *
8  * COMMENTS: This class is a globally unique identifier. Simply creating
9  * one of these objects assigns a new unique value. These values
10  * are keyed to the host machine, process id, time, and are
11  * incremented on each request.
12  *
13  * ****************** IMPORTANT NOTE: *********************
14  * This implementation isn't guaranteed to produce unique values
15  * because we use the IP address rather than a MAC address. It
16  * has a privacy hole because the IP address is hashed in a way
17  * that allows the original address to be recovered (which
18  * would be more of a concern if we actualy used the MAC
19  * address).
20  *
21  * Current usage of this class is in the SIM library only,
22  * which doesn't require true global uniqueness or thread
23  * safety. But future uses of this class should beware of
24  * these limitations and fix these problems as required.
25  */
26 
27 #ifndef __UT_Guid__
28 #define __UT_Guid__
29 
30 #include "UT_API.h"
31 #include <iosfwd>
32 #include "UT_Hash.h"
33 
34 class UT_String;
35 class UT_StringHolder;
36 class UT_WorkBuffer;
37 class UT_IStream;
38 class UT_Lock;
39 
41 {
42 public:
43  UT_Guid();
44  UT_Guid(const UT_Guid &src);
45  ~UT_Guid();
46 
47  enum { theStringSize = 43 };
48  enum { theBinarySize = 16 };
49  bool setString(const char *str);
50  void getString(UT_String &str) const;
51  void getString(UT_StringHolder &str) const;
52  void getString(UT_WorkBuffer &str) const;
53 
54  bool operator==(const UT_Guid &cmp) const;
55  bool operator!=(const UT_Guid &cmp) const;
56  const UT_Guid &operator=(const UT_Guid &src);
57 
58  void writeBinary(std::ostream &os) const;
59  bool readBinary(UT_IStream &is);
60  bool readAscii(UT_IStream &is);
61 
62  /// This hash only is unique within this session.
63  size_t hash() const { return SYSwang_inthash(myUniqueCount); }
64 
65  /// A unique number for this run of Houdini.
66  int64 sessionId() const;
67 
68  friend UT_API std::ostream &operator<<(std::ostream &os,
69  const UT_Guid &guid);
70 
71 private:
72  static void initializeValues();
73 
74  int myRandom;
75  int myPid;
76  int myTime;
77  int myUniqueCount;
78 
79  static int theRandomBase;
80  static int thePid;
81  static int theStartTime;
82  static bool theValuesInitialized;
83  static UT_Lock theValuesInitializeLock;
84 
85  friend class UT_GuidHash;
86 };
87 
88 inline size_t hash_value(const UT_Guid &guid)
89 {
90  return guid.hash();
91 }
92 
94 
95 class SYS_DEPRECATED_REPLACE(16.0, "SYShash<UT_Guid>") UT_API UT_GuidHash : public UT_Hash
96 {
97 public:
98  UT_GuidHash(const UT_Guid &uniqueid)
99  : myGuid(uniqueid)
100  { }
101  virtual ~UT_GuidHash()
102  { }
103 
104  virtual int compare(const UT_Hash &a) const
105  {
106  const UT_GuidHash &b = (const UT_GuidHash &)a;
107  int d;
108 
109  d = myGuid.myUniqueCount - b.myGuid.myUniqueCount;
110  if( d ) return ((d < 0) ? -1 : 1);
111  d = myGuid.myTime - b.myGuid.myTime;
112  if( d ) return ((d < 0) ? -1 : 1);
113  d = myGuid.myPid - b.myGuid.myPid;
114  if( d ) return ((d < 0) ? -1 : 1);
115  d = myGuid.myRandom - b.myGuid.myRandom;
116  if( d ) return ((d < 0) ? -1 : 1);
117 
118  return 0;
119  }
120  virtual void copy(const UT_Hash &a)
121  {
122  myGuid = static_cast<const UT_GuidHash&>(a).myGuid;
123  }
124  virtual unsigned hash() const
125  {
126  return SYSwang_inthash(myGuid.myUniqueCount);
127  }
128  virtual UT_Hash *copy() const
129  {
130  return new UT_GuidHash(myGuid);
131  }
132  virtual int64 getMemoryUsage(bool inclusive) const
133  {
134  return inclusive ? sizeof(*this) : 0;
135  }
136 
137 private:
138  UT_Guid myGuid;
139 };
140 
142 
143 #endif
144 
virtual UT_Hash * copy() const
Definition: UT_Guid.h:128
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
virtual void copy(const UT_Hash &a)
Definition: UT_Guid.h:120
#define UT_API
Definition: UT_API.h:13
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
Definition: DataType.h:133
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:107
size_t hash_value(const UT_Guid &guid)
Definition: UT_Guid.h:88
virtual int64 getMemoryUsage(bool inclusive) const
Definition: UT_Guid.h:132
size_t hash() const
This hash only is unique within this session.
Definition: UT_Guid.h:63
virtual ~UT_GuidHash()
Definition: UT_Guid.h:101
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
UT_GuidHash(const UT_Guid &uniqueid)
Definition: UT_Guid.h:98
int cmp(T a, T b)
Definition: ImathFun.h:119
virtual unsigned hash() const
Definition: UT_Guid.h:124
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
virtual int compare(const UT_Hash &a) const
Definition: UT_Guid.h:104
GLenum src
Definition: glcorearb.h:1792