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 class UT_StringHolder;
20 #include "UT_Endian.h"
21 #include "UT_Map.h"
22 #include "UT_Set.h"
23 #include "UT_UniquePtr.h"
24 #include <SYS/SYS_Inline.h>
25 
26 
27 // Turning on the following define will cause checks to be put in place to
28 // detect buffer over/underruns.
29 //
30 //#define UT_TS_DETECT_BUFFER_ERRORS
31 
33 {
34 public:
35  static UT_TokenString *allocString();
36  static UT_TokenString *dupString(const UT_TokenString &);
37  static void freeString(UT_TokenString *&);
38 
39  bool operator==(const UT_TokenString &str) const;
40  bool operator!=(const UT_TokenString &str) const
41  { return !(*this == str); }
42  int strcmp(const UT_TokenString &str) const;
45 
46  void append(int16 value, bool hashonly = false);
47  void append(uint16 value, bool hashonly = false);
48  void append(int32 value, bool hashonly = false);
49  void append(uint32 value, bool hashonly = false);
50  void append(int64 value, bool hashonly=false);
51  void append(uint64 value, bool hashonly=false);
52  void append(fpreal32 value, bool hashonly = false);
53  void append(fpreal64 value, bool hashonly = false);
54  void append(char value, bool hashonly = false);
55  void append(const char *value, bool hashonly = false);
56  void append(const UT_String &value, bool hashonly = false);
57  void append(const UT_WorkBuffer &value, bool hashonly=false);
58  void appendPointer(const void *, bool hashonly=false);
59 
60  void clear();
61  unsigned int getHashCode() const { return myHashCode; }
62 
63  // NOTE: getMemoryUsage(true) must return a value large enough to be
64  // the length of a buffer passed to copyToMem.
65  int64 getMemoryUsage(bool inclusive) const;
66 
67  // for writing to disk with direct IO
68  int copyToMem(void *mem, int *length) const;
69  void copyFromMem(void *mem, int *length);
70 
71  void print() const; // for debug
72 
73  void getPrintable(UT_String &string) const;
74  void getPrintable(UT_StringHolder &string) const;
75 
76  void compress();
77 
78  struct PtrDeleter
79  {
82  };
83 
85 
87  {
89  size_t operator()(const Ptr &p) const
90  {
91  if (!p)
92  return 0;
93  return p->getHashCode();
94  }
95  };
97  {
99  bool operator()(const Ptr &a, const Ptr &b) const
100  {
101  if (!a)
102  return !b;
103  if (!b)
104  return false;
105  return *a == *b;
106  }
107  };
109 
110  template<typename V>
111  class Map : public UT_Map<Ptr,V,PtrHashFunctor,PtrEqualFunctor>
112  {};
113 
114  UT_TokenString();
115  ~UT_TokenString();
116 
117 private:
118 
119  // This will realloc myString and ensure it is at least the given
120  // size. It does nothing if there is already room, so call this
121  // wherever you want to grow or are not sure.
122  void resizeString(int size);
123 
124  void append(const void *str, int length, bool hashonly);
125 
126  unsigned int myHashCode;
127  int myLength;
128  int myTrueSize;
129 
130  union {
131  unsigned char *myString;
133  };
134 
135 #ifdef UT_TS_DETECT_BUFFER_ERRORS
136  unsigned char *myMemString;
137 #endif
138 
139  friend class OP_Node;
140 };
141 #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:109
UT_Set< Ptr, PtrHashFunctor, PtrEqualFunctor > Set
unsigned char * myString
GLsizei const GLfloat * value
Definition: glcorearb.h:824
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:4512
#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
LeafData & operator=(const LeafData &)=delete
SYS_FORCE_INLINE size_t operator()(const Ptr &p) const
unsigned int uint32
Definition: SYS_Types.h:40
unsigned int getHashCode() const
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2903
SYS_FORCE_INLINE void operator()(UT_TokenString *ts)