00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_TOKENSTRING_H__
00022 #define __UT_TOKENSTRING_H__
00023
00024 #include "UT_API.h"
00025 class UT_String;
00026 class UT_WorkBuffer;
00027 #include "UT_Endian.h"
00028 #include "UT_Hash.h"
00029
00030
00031
00032
00033
00034
00035
00036 class UT_API UT_TokenString
00037 {
00038 public:
00039 static UT_TokenString *allocString();
00040 static UT_TokenString *dupString(const UT_TokenString &);
00041 static void freeString(UT_TokenString *&);
00042
00043 unsigned operator==(const UT_TokenString &str) const;
00044 int strcmp(const UT_TokenString &str) const;
00045 UT_TokenString &operator=(const UT_TokenString &str);
00046 UT_TokenString &operator+=(const UT_TokenString &str);
00047
00048 void append(int value, bool hashonly = false);
00049 void append(unsigned value, bool hashonly = false);
00050 void append(short value, bool hashonly = false);
00051 void append(unsigned short value, bool hashonly = false);
00052 void append(long value, bool hashonly = false);
00053 void append(fpreal32 value, bool hashonly = false);
00054 void append(fpreal64 value, bool hashonly = false);
00055 void append(char value, bool hashonly = false);
00056 void append(const char *value, bool hashonly = false);
00057 void append(const UT_String &value, bool hashonly = false);
00058 void append(const UT_WorkBuffer &value, bool hashonly=false);
00059
00060 void clear();
00061 unsigned int getHashCode() const { return myHashCode; }
00062
00063
00064 int getMemSize() const;
00065 int copyToMem(void *mem, int *length) const;
00066 void copyFromMem(void *mem, int *length);
00067
00068 void print() const;
00069
00070 void getPrintable(UT_String &string) const;
00071
00072 void compress();
00073
00074 private:
00075 UT_TokenString();
00076 virtual ~UT_TokenString();
00077
00078
00079
00080
00081 void resizeString(int size);
00082
00083 void append(const void *str, int length, bool hashonly);
00084
00085 unsigned int myHashCode;
00086 int myLength;
00087 int myTrueSize;
00088
00089 union {
00090 unsigned char *myString;
00091 UT_TokenString *myNext;
00092 };
00093
00094 #ifdef UT_TS_DETECT_BUFFER_ERRORS
00095 unsigned char *myMemString;
00096 #endif
00097
00098 friend class OP_Node;
00099 };
00100
00101
00102 class UT_API UT_Hash_TokenString : public UT_Hash
00103 {
00104 private:
00105 UT_TokenString *myTs;
00106 public:
00107 UT_Hash_TokenString( UT_TokenString *a )
00108 {
00109 myTs = UT_TokenString::dupString(*a);
00110 }
00111
00112 ~UT_Hash_TokenString()
00113 {
00114 UT_TokenString::freeString(myTs);
00115 }
00116
00117 int compare( const UT_Hash & a) const
00118 {
00119 return !(*myTs == *((const UT_Hash_TokenString&)a).myTs);
00120 }
00121
00122 void copy(const UT_Hash &a)
00123 {
00124 myTs = UT_TokenString::dupString(
00125 *static_cast<const UT_Hash_TokenString &>(a).myTs);
00126 }
00127
00128 unsigned hash() const
00129 {
00130 return myTs->getHashCode();
00131 }
00132
00133 UT_Hash* copy() const
00134 {
00135 return new UT_Hash_TokenString( myTs );
00136 }
00137
00138 int64 getMemUsage() const
00139 {
00140 return (sizeof(*this) + myTs->getMemSize());
00141 }
00142 };
00143
00144 #endif