HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TokenString.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  *
7  * NAME: Utility Library (C++)
8  *
9  * COMMENTS: String class for quick exact comparison & hashing by using
10  * tokens (non-ASCII bytes).
11  *
12  */
13 #ifndef __UT_TOKENSTRING_H__
14 #define __UT_TOKENSTRING_H__
15 
16 #include "UT_API.h"
17 class UT_String;
18 class UT_WorkBuffer;
19 #include "UT_Endian.h"
20 #include "UT_Map.h"
21 #include "UT_Set.h"
22 #include "UT_UniquePtr.h"
23 #include <SYS/SYS_Inline.h>
24 
25 
26 // Turning on the following define will cause checks to be put in place to
27 // detect buffer over/underruns.
28 //
29 //#define UT_TS_DETECT_BUFFER_ERRORS
30 
32 {
33 public:
34  static UT_TokenString *allocString();
35  static UT_TokenString *dupString(const UT_TokenString &);
36  static void freeString(UT_TokenString *&);
37 
38  bool operator==(const UT_TokenString &str) const;
39  bool operator!=(const UT_TokenString &str) const
40  { return !(*this == str); }
41  int strcmp(const UT_TokenString &str) const;
42  UT_TokenString &operator=(const UT_TokenString &str);
44 
45  void append(int16 value, bool hashonly = false);
46  void append(uint16 value, bool hashonly = false);
47  void append(int32 value, bool hashonly = false);
48  void append(uint32 value, bool hashonly = false);
49  void append(int64 value, bool hashonly=false);
50  void append(uint64 value, bool hashonly=false);
51  void append(fpreal32 value, bool hashonly = false);
52  void append(fpreal64 value, bool hashonly = false);
53  void append(char value, bool hashonly = false);
54  void append(const char *value, bool hashonly = false);
55  void append(const UT_String &value, bool hashonly = false);
56  void append(const UT_WorkBuffer &value, bool hashonly=false);
57  void appendPointer(const void *, bool hashonly=false);
58 
59  void clear();
60  unsigned int getHashCode() const { return myHashCode; }
61 
62  // NOTE: getMemoryUsage(true) must return a value large enough to be
63  // the length of a buffer passed to copyToMem.
64  int64 getMemoryUsage(bool inclusive) const;
65 
66  // for writing to disk with direct IO
67  int copyToMem(void *mem, int *length) const;
68  void copyFromMem(void *mem, int *length);
69 
70  void print() const; // for debug
71 
72  void getPrintable(UT_String &string) const;
73 
74  void compress();
75 
76  struct PtrDeleter
77  {
80  };
81 
83 
85  {
87  size_t operator()(const Ptr &p) const
88  {
89  if (!p)
90  return 0;
91  return p->getHashCode();
92  }
93  };
95  {
97  bool operator()(const Ptr &a, const Ptr &b) const
98  {
99  if (!a)
100  return !b;
101  if (!b)
102  return false;
103  return *a == *b;
104  }
105  };
107 
108  template<typename V>
109  class Map : public UT_Map<Ptr,V,PtrHashFunctor,PtrEqualFunctor>
110  {};
111 
112 private:
113  UT_TokenString();
114  ~UT_TokenString();
115 
116  // This will realloc myString and ensure it is at least the given
117  // size. It does nothing if there is already room, so call this
118  // wherever you want to grow or are not sure.
119  void resizeString(int size);
120 
121  void append(const void *str, int length, bool hashonly);
122 
123  unsigned int myHashCode;
124  int myLength;
125  int myTrueSize;
126 
127  union {
128  unsigned char *myString;
130  };
131 
132 #ifdef UT_TS_DETECT_BUFFER_ERRORS
133  unsigned char *myMemString;
134 #endif
135 
136  friend class OP_Node;
137 };
138 #endif
UT_TokenString * myNext
UT_UniquePtr< UT_TokenString, PtrDeleter > Ptr
unsigned short uint16
Definition: SYS_Types.h:38
Definition: UT_Set.h:58
int int32
Definition: SYS_Types.h:39
Unsorted map container.
Definition: UT_Map.h:107
UT_Set< Ptr, PtrHashFunctor, PtrEqualFunctor > Set
unsigned char * myString
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
#define UT_API
Definition: UT_API.h:14
unsigned long long uint64
Definition: SYS_Types.h:117
float fpreal32
Definition: SYS_Types.h:200
bool operator!=(const UT_TokenString &str) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
double fpreal64
Definition: SYS_Types.h:201
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
SYS_FORCE_INLINE bool operator()(const Ptr &a, const Ptr &b) const
GLsizeiptr size
Definition: glcorearb.h:664
static void freeString(UT_TokenString *&)
short int16
Definition: SYS_Types.h:37
SYS_FORCE_INLINE size_t operator()(const Ptr &p) const
unsigned int uint32
Definition: SYS_Types.h:40
Definition: core.h:1131
unsigned int getHashCode() const
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
SYS_FORCE_INLINE void operator()(UT_TokenString *ts)