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 SbNameChunk
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
00162 class SbName
00163 {
00164 public:
00168 SbName() { string = SbNameChunk::insert(""); }
00169
00173 SbName(const char *s) { string = SbNameChunk::insert(s); }
00174
00178 SbName(const SbString &s) { string = SbNameChunk::insert(s.toLatin1()); }
00179
00183 SbName(const SbName &n) { string = n.string; }
00184
00188 ~SbName() {};
00189
00193 const char* getString() const
00194 {
00195 return string;
00196 }
00197
00201 int getLength() const
00202 {
00203 return static_cast<int>(strlen(string));
00204 }
00205
00209 static SbBool isIdentStartChar(char c);
00210
00215 static SbBool isIdentChar(char c);
00216
00221 static SbBool isBaseNameStartChar(char c);
00222
00227 static SbBool isBaseNameChar(char c);
00228
00232 int operator !() const
00233 {
00234 return ( string[0] == '\0');
00235 }
00236
00240 friend int operator ==(const SbName &n, const char *s)
00241 {
00242 return (n.string[0] == s[0] && ! strcmp(n.string, s));
00243 }
00244
00248 friend int operator ==(const char *s, const SbName &n)
00249 {
00250 return (n.string[0] == s[0] && ! strcmp(n.string, s));
00251 }
00252
00256 friend int operator ==(const SbName &n1, const SbName &n2)
00257 {
00258 return (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string));
00259 }
00260
00264 friend int operator !=(const SbName &n, const char *s)
00265 {
00266 return ! (n.string[0] == s[0] && ! strcmp(n.string, s));
00267 }
00268
00272 friend int operator !=(const char *s, const SbName &n)
00273 { return ! (n.string[0] == s[0] && ! strcmp(n.string, s)); }
00274
00278 friend int operator !=(const SbName &n1, const SbName &n2)
00279 { return ! (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string)); }
00280
00286 friend bool operator < (const SbName &n1, const SbName &n2)
00287 {
00288 return (strcmp(n1.string, n2.string) < 0);
00289 }
00290
00294 friend std::ostream& operator << (std::ostream& os, const SbName& n)
00295 {
00296 return os << n.getString();
00297 }
00298
00299 private:
00300 static void enableUseNameCompat( const SbBool enable )
00301 { s_useNameCompat = enable; }
00302
00303 static SbBool useNameCompat()
00304 { return s_useNameCompat; }
00305
00306 private:
00307
00308 const char* string;
00309
00310
00311 static SbBool s_useNameCompat;
00312 };
00313
00314 #endif // _SB_NAME_
00315
00316
00317