Open Inventor Reference
SbString.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file contains definitions of the SbString and SbName
48 | classes, which are useful variations on our friend, the
49 | character string.
50 |
51 | Author(s) : Paul S. Strauss, Nick Thompson
52 |
53 ______________ S I L I C O N G R A P H I C S I N C . ____________
54 _______________________________________________________________________
55 */
56
57#ifndef _SB_STRING_
58#define _SB_STRING_
59
61#include <Inventor/SbBasic.h>
62
63#include <string.h>
64
65#ifdef WIN32
66#define oiv_strdup _strdup
67#else
68#define oiv_strdup strdup
69#endif
70
73
84
86 public:
87
89 SbString() { string = staticStorage;
90 string[0] = '\0'; }
91
93 SbString(const char *str) { string = staticStorage;
94 *this = str; }
95
97 SbString(const char *str, int start, int end);
98
100 SbString(const SbString &str) { string = staticStorage;
101 *this = str.string; }
102
111 SbString(int digitString);
112
115
117 uint32_t hash() { return SbString::hash(string); }
118
120 int getLength() const { return static_cast<int>(strlen(string)); }
121
124 void makeEmpty(bool freeOld = TRUE);
125
127 const char * getString() const { return string; }
128
132 SbString getSubString(int startChar, int endChar = -1) const;
133
137 void deleteSubString(int startChar, int endChar = -1);
138
140 SbString & operator =(const char *str);
142 SbString & operator =(const SbString &str)
143 { return (*this = str.string); }
144
146 SbString & operator +=(const char *str);
147
149 SbString & operator +=(const SbString &str);
150
152 bool operator !() const { return (string[0] == '\0'); }
153
155 friend INVENTOR_API bool operator ==(const SbString &str, const char *s);
156
157 friend INVENTOR_API bool operator ==(const char *s, const SbString &str)
158 { return (str == s); }
159
160
161 friend INVENTOR_API bool operator ==(const SbString &str1, const SbString &str2)
162 { return (str1 == str2.string); }
163
165 friend INVENTOR_API bool operator !=(const SbString &str, const char *s);
166
167 friend INVENTOR_API bool operator !=(const char *s, const SbString &str)
168 { return (str != s); }
169
170 friend INVENTOR_API bool operator !=(const SbString &str1,
171 const SbString &str2)
172 { return (str1 != str2.string); }
173
175 friend INVENTOR_API bool operator <(const SbString &str, const char *s);
176
177 friend INVENTOR_API bool operator <(const char *s, const SbString &str)
178 { return (str < s); }
179
180 friend INVENTOR_API bool operator <(const SbString &str1, const SbString &str2)
181 { return (str1 < str2.string); }
182
183 SoINTERNAL public:
184
186 static uint32_t hash(const char *s); // Hash function
187
188 private:
189 char *string;
190 int storageSize;
191
193#define SB_STRING_STATIC_STORAGE_SIZE 32
194 char staticStorage[SB_STRING_STATIC_STORAGE_SIZE];
195
196 void expand(int bySize);
197};
198
206
207
209
210 public:
212 bool isEmpty() const { return (string[0] == '\0'); }
213
215 bool isEqual(const char *s) const
216 { return (string[0] == s[0] && ! strcmp(string, s)); }
217
218 private:
219 static int nameTableSize;
220 static SbNameEntry **nameTable;
221 static struct SbNameChunk *chunk;
222
223 const char *string;
224 uint32_t hashValue;
225 SbNameEntry *next;
226
228 static void initClass();
229
231 SbNameEntry(const char *s, uint32_t h, SbNameEntry *n)
232 { string = s; hashValue = h; next = n; }
233
235 static const SbNameEntry * insert(const char *s);
236
237friend INVENTOR_API class SbName;
238};
239
240
241
244
263
265 public:
266
269
271 SbName(const char *s) { entry = SbNameEntry::insert(s); }
272
274 SbName(const SbString &s) { entry = SbNameEntry::insert(s.getString()); }
275
277 SbName(const SbName &n) { entry = n.entry; }
278
281
283 const char *getString() const { return entry->string; }
284
286 int getLength() const { return static_cast<int>(strlen(entry->string)); }
287
290 static bool isIdentStartChar(char c);
291
294 static bool isIdentChar(char c);
295
298 static bool isBaseNameStartChar(char c);
299
302 static bool isBaseNameChar(char c);
303
305 bool operator !() const { return entry->isEmpty(); }
306
308 friend INVENTOR_API bool operator ==(const SbName &n, const char *s)
309 { return n.entry->isEqual(s); }
310
311 friend INVENTOR_API bool operator ==(const char *s, const SbName &n)
312 { return n.entry->isEqual(s); }
313
314 friend INVENTOR_API bool operator ==(const SbName &n1, const SbName &n2)
315 { return n1.entry == n2.entry; }
316
318 friend INVENTOR_API bool operator !=(const SbName &n, const char *s)
319 { return ! n.entry->isEqual(s); }
320
321 friend INVENTOR_API bool operator !=(const char *s, const SbName &n)
322 { return ! n.entry->isEqual(s); }
323
324 friend INVENTOR_API bool operator !=(const SbName &n1, const SbName &n2)
325 { return n1.entry != n2.entry; }
326
327 private:
328 const SbNameEntry *entry;
329};
330
331#endif /* _SB_STRING_ */
#define TRUE
Definition SbBasic.h:76
#define SoINTERNAL
Definition SbBasic.h:155
INVENTOR_API bool operator!=(const SbBox3f &b1, const SbBox3f &b2)
Definition SbBox.h:207
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
#define SB_STRING_STATIC_STORAGE_SIZE
This is used if the string fits in a reasonably small space.
Definition SbString.h:193
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
This is used to make lists of SbName instances.
Definition SbString.h:208
bool isEmpty() const
Returns TRUE if entry's string is empty ("")
Definition SbString.h:212
bool isEqual(const char *s) const
Returns TRUE if entry's string is same as passed string.
Definition SbString.h:215
Character string stored in a hash table.
Definition SbString.h:264
SbName()
Constructors and destructor.
static bool isBaseNameChar(char c)
Returns TRUE if given character is a legal nonstarting character for an SoBase's name.
SbName(const char *s)
Constructor that initializes to given character string.
Definition SbString.h:271
SbName(const SbString &s)
Constructor that initializes to given SbString.
Definition SbString.h:274
~SbName()
Constructors and destructor.
Definition SbString.h:280
int getLength() const
Returns length of string.
Definition SbString.h:286
static bool isBaseNameStartChar(char c)
Returns TRUE if given character is a legal starting character for an SoBase's name.
static bool isIdentChar(char c)
Returns TRUE if given character is a legal nonstarting character for an identifier.
static bool isIdentStartChar(char c)
Returns TRUE if given character is a legal starting character for an identifier.
SbName(const SbName &n)
Constructors and destructor.
Definition SbString.h:277
const char * getString() const
Returns pointer to the character string.
Definition SbString.h:283
Class for smart character strings.
Definition SbString.h:85
SbString(const SbString &str)
Definition SbString.h:100
~SbString()
Destructor.
void makeEmpty(bool freeOld=TRUE)
Sets string to be the empty string ("").
static uint32_t hash(const char *s)
Returns a reasonable hash key for string.
SbString()
Definition SbString.h:89
SbString getSubString(int startChar, int endChar=-1) const
Returns new string representing sub-string from startChar to endChar, inclusive.
SbString(int digitString)
Constructors and destructor.
const char * getString() const
Returns pointer to the character string.
Definition SbString.h:127
void deleteSubString(int startChar, int endChar=-1)
Deletes the characters from startChar to endChar, inclusive, from the string.
uint32_t hash()
Returns a reasonable hash key for string.
Definition SbString.h:117
SbString(const char *str)
Definition SbString.h:93
int getLength() const
Returns length of string.
Definition SbString.h:120
SbString(const char *str, int start, int end)