Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SbName.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25** Modified by : Nick Thompson (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (oct 2011)
48**=======================================================================*/
49
50#ifndef _SB_NAME_
51#define _SB_NAME_
52
53#ifndef HIDDEN_FROM_DOC
54
55#include <Inventor/SbString.h>
56
58//
59// Class: SbNameEntry (internal to SB)
60//
61// This is used to make lists of SbName instances.
62//
64
65
66// The size of a chunk is about a page (4K) minus room for other stuff
67// in the structure
68
69{
70public:
71
72 // Inserts string in table
73 static const char* insert(const char *s);
74
75 // Removes string from table
76 static SbBool remove(const char *s);
77
78 // Initializes/Unload SbNameEntry class
79 static void initClass();
80 static void exitClass();
81
82 struct SbNameEntry
83 {
84 SbNameEntry* next; // Pointer to next entry
85 uint32_t hashValue; // Its hash value
86
87 struct SbNameEntryUsage
88 {
89 uint32_t _isStrDup : 1; // String allocated in chunk (0) or elsewhere (1)
90 uint32_t _refCount : 31; // Place for ref counting names
91 } usage;
92
93 union SbNameEntryString // Data depends on _isStrDup
94 {
95 char _const; // _isStrDup == 0 : this is the string.
96 char* _ptr; // _isStrDup == 1 : this is a pointer to the string.
97 } nameString;
98
99 const char* getString() const // Access to the string.
100 {
101 if (usage._isStrDup)
102 return nameString._ptr;
103 return (const char*)&(nameString._const);
104 }
105 };
106
107private:
108 SbNameChunk();
109 ~SbNameChunk();
110
111 char* mem; // Chunk o'memory
112 char* curByte; // Current byte of chunk
113 size_t bytesLeft; // Bytes left in chunk
114 SbNameChunk* next; // Pointer to next chunk
115
116 static int nameTableSize; // Number of buckets in name table
117 static SbNameEntry** nameTable; // Array of name entries
118 static SbNameChunk* chunk; // Chunk of memory for string storage
119 static int chunkSize;
120
121 static SbNameEntry*& findEntry(const char *s); // Finds string entry in table
122};
123
124#endif // HIDDEN_FROM_DOC
125
127//
128// Class: SbName
129//
130// An SbName is a character string that is stored in a special table.
131// When a string is stored in this table, a pointer to the storage is
132// returned. Two identical strings will return the same pointer. This
133// means that comparison of two SbNames for equality can be
134// accomplished by comparing their pointers!
135//
137
138
162{
163 public:
167 SbName() { string = SbNameChunk::insert(""); }
168
172 SbName(const char *s) { string = SbNameChunk::insert(s); }
173
177 SbName(const SbString &s) { string = SbNameChunk::insert(s.toLatin1()); }
178
182 SbName(const SbName &n) { string = n.string; }
183
188
192 const char* getString() const
193 {
194 return string;
195 }
196
200 int getLength() const
201 {
202 return static_cast<int>(strlen(string));
203 }
204
208 static SbBool isIdentStartChar(char c);
209
214 static SbBool isIdentChar(char c);
215
221
226 static SbBool isBaseNameChar(char c);
227
231 int operator !() const
232 {
233 return ( string[0] == '\0');
234 }
235
239 friend int operator ==(const SbName &n, const char *s)
240 {
241 return (n.string[0] == s[0] && ! strcmp(n.string, s));
242 }
243
247 friend int operator ==(const char *s, const SbName &n)
248 {
249 return (n.string[0] == s[0] && ! strcmp(n.string, s));
250 }
251
255 friend int operator ==(const SbName &n1, const SbName &n2)
256 {
257 return (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string));
258 }
259
263 friend int operator !=(const SbName &n, const char *s)
264 {
265 return ! (n.string[0] == s[0] && ! strcmp(n.string, s));
266 }
267
271 friend int operator !=(const char *s, const SbName &n)
272 { return ! (n.string[0] == s[0] && ! strcmp(n.string, s)); }
273
277 friend int operator !=(const SbName &n1, const SbName &n2)
278 { return ! (n1.string[0] == n2.string[0] && ! strcmp(n1.string, n2.string)); }
279
285 friend bool operator < (const SbName &n1, const SbName &n2)
286 {
287 return (strcmp(n1.string, n2.string) < 0);
288 }
289
293 friend std::ostream& operator << (std::ostream& os, const SbName& n)
294 {
295 return os << n.getString();
296 }
297
298private:
299 static void enableUseNameCompat( const SbBool enable )
300 { s_useNameCompat = enable; }
301
302 static SbBool useNameCompat()
303 { return s_useNameCompat; }
304
305 private:
306 // Name string storage
307 const char* string;
308
309 // Flag to control use of valid names
310 static SbBool s_useNameCompat;
311};
312
313#endif // _SB_NAME_
314
315
Character string stored in a hash table.
Definition SbName.h:162
SbName()
Constructor.
Definition SbName.h:167
friend int operator!=(const SbName &n, const char *s)
Inequality operator for SbName/char* and SbName/SbName comparison.
Definition SbName.h:263
static SbBool isBaseNameChar(char c)
Returns TRUE if given character is a legal nonstarting character for an SoBase's name.
static SbBool isIdentChar(char c)
Returns TRUE if given character is a legal nonstarting character for an identifier.
friend int operator==(const SbName &n, const char *s)
Equality operator for SbName/char* and SbName/SbName comparison.
Definition SbName.h:239
SbName(const char *s)
Constructor.
Definition SbName.h:172
SbName(const SbString &s)
Constructor.
Definition SbName.h:177
friend bool operator<(const SbName &n1, const SbName &n2)
"less than" relational operator for SbName / SbName that returns TRUE if the first operand is less th...
Definition SbName.h:285
int operator!() const
Unary "not" operator; returns TRUE if string is empty ("").
Definition SbName.h:231
friend std::ostream & operator<<(std::ostream &os, const SbName &n)
Writes the SbName to the specified output stream.
Definition SbName.h:293
~SbName()
Destructor.
Definition SbName.h:187
int getLength() const
Returns length of string.
Definition SbName.h:200
static SbBool isIdentStartChar(char c)
Returns TRUE if given character is a legal starting character for an identifier.
SbName(const SbName &n)
Constructor.
Definition SbName.h:182
const char * getString() const
Returns pointer to the character string.
Definition SbName.h:192
static SbBool isBaseNameStartChar(char c)
Returns TRUE if given character is a legal starting character for an SoBase's name.
Class for smart character strings.
Definition SbString.h:202
const char * toLatin1() const
Returns the string as a Latin-1/ASCII C string.
int SbBool
Boolean type.
Definition SbBase.h:87