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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _SB_NAME_
00051 #define _SB_NAME_
00052
00053 #ifndef HIDDEN_FROM_DOC
00054
00055 #include <Inventor/SbString.h>
00056
00058
00059
00060
00061
00062
00064
00065
00066
00067
00068
00069 {
00070 public:
00071
00072
00073 static const char* insert(const char *s);
00074
00075
00076 static SbBool remove(const char *s);
00077
00078
00079 static void initClass();
00080 static void exitClass();
00081
00082 struct SbNameEntry
00083 {
00084 SbNameEntry* next;
00085 uint32_t hashValue;
00086
00087 struct SbNameEntryUsage
00088 {
00089 uint32_t _isStrDup : 1;
00090 uint32_t _refCount : 31;
00091 } usage;
00092
00093 union SbNameEntryString
00094 {
00095 char _const;
00096 char* _ptr;
00097 } nameString;
00098
00099 const char* getString() const
00100 {
00101 if (usage._isStrDup)
00102 return nameString._ptr;
00103 return (const char*)&(nameString._const);
00104 }
00105 };
00106
00107 private:
00108 SbNameChunk();
00109 ~SbNameChunk();
00110
00111 char* mem;
00112 char* curByte;
00113 size_t bytesLeft;
00114 SbNameChunk* next;
00115
00116 static int nameTableSize;
00117 static SbNameEntry** nameTable;
00118 static SbNameChunk* chunk;
00119 static int chunkSize;
00120
00121 static SbNameEntry*& findEntry(const char *s);
00122 };
00123
00124 #endif // HIDDEN_FROM_DOC
00125
00127
00128
00129
00130
00131
00132
00133
00134
00135
00137
00138
00161 class SbName
00162 {
00163 public:
00167 SbName() { string = SbNameChunk::insert(""); }
00168
00172 SbName(const char *s) { string = SbNameChunk::insert(s); }
00173
00177 SbName(const SbString &s) { string = SbNameChunk::insert(s.toLatin1()); }
00178
00182 SbName(const SbName &n) { string = n.string; }
00183
00187 ~SbName() {};
00188
00192 const char* getString() const
00193 {
00194 return string;
00195 }
00196
00200 int getLength() const
00201 {
00202 return static_cast<int>(strlen(string));
00203 }
00204
00208 static SbBool isIdentStartChar(char c);
00209
00214 static SbBool isIdentChar(char c);
00215
00220 static SbBool isBaseNameStartChar(char c);
00221
00226 static SbBool isBaseNameChar(char c);
00227
00231 int operator !() const
00232 {
00233 return ( string[0] == '\0');
00234 }
00235
00239 friend int operator ==(const SbName &n, const char *s)
00240 {
00241 return (n.string[0] == s[0] && ! strcmp(n.string, s));
00242 }
00243
00247 friend int operator ==(const char *s, const SbName &n)
00248 {
00249 return (n.string[0] == s[0] && ! strcmp(n.string, s));
00250 }
00251
00255 friend int operator ==(const SbName &n1, const SbName &n2)
00256 {
00257 return (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string));
00258 }
00259
00263 friend int operator !=(const SbName &n, const char *s)
00264 {
00265 return ! (n.string[0] == s[0] && ! strcmp(n.string, s));
00266 }
00267
00271 friend int operator !=(const char *s, const SbName &n)
00272 { return ! (n.string[0] == s[0] && ! strcmp(n.string, s)); }
00273
00277 friend int operator !=(const SbName &n1, const SbName &n2)
00278 { return ! (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string)); }
00279
00285 friend bool operator < (const SbName &n1, const SbName &n2)
00286 {
00287 return (strcmp(n1.string, n2.string) < 0);
00288 }
00289
00293 friend std::ostream& operator << (std::ostream& os, const SbName& n)
00294 {
00295 return os << n.getString();
00296 }
00297
00298 private:
00299 static void enableUseNameCompat( const SbBool enable )
00300 { s_useNameCompat = enable; }
00301
00302 static SbBool useNameCompat()
00303 { return s_useNameCompat; }
00304
00305 private:
00306
00307 const char* string;
00308
00309
00310 static SbBool s_useNameCompat;
00311 };
00312
00313 #endif // _SB_NAME_
00314
00315
00316