Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoType.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 : Nick Thompson (MMM yyyy)
25** Modified by : Gavin Bell (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-2023 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_TYPE_
52#define _SO_TYPE_
53
54#include <Inventor/SbString.h>
55#include <Inventor/SbDict.h>
56#include <Inventor/STL/ostream>
57
58class SoTypeList;
59struct SoTypeData;
60class ScDataInputStream;
61
62typedef void *SoTypeFromNameCB(SbName name);
63
64#ifndef HIDDEN_FROM_DOC
65//Int32 value of a badtype
66#define SO_BAD_TYPE_INT_INTERNAL 0x80000000
67#endif
68
98class SoType {
99
100#ifdef __DELTA
101# pragma __nondynamic_class
102#endif
103
104 public:
105
109 static SoType fromName(const SbName &name);
110
115
120
124 inline static SoType badType()
125 {
126 return (SoType)SO_BAD_TYPE_INT_INTERNAL;
127 }
128
132 SbBool isBad() const;
133
137 SbBool isDerivedFrom(const SoType &t) const;
138
144 template<typename TypedObjectClass>
146 {
147 return isDerivedFrom( TypedObjectClass::getClassTypeId() );
148 }
149
154 static int getAllDerivedFrom(const SoType &type, SoTypeList &list);
155
162
163 // Internal note: Only "if_cpp" is needed here.
164 // .NET and Java API do not use this class.
165
178 void *createInstance(SoType *overrideType=NULL) const;
179
183 bool operator ==(const SoType t) const;
184
188 bool operator !=(const SoType t) const;
189
194 bool operator <(const SoType t) const;
195
199 friend std::ostream& operator << (std::ostream& os, const SoType& t)
200 {
201 return os << "<" << t.getName() << "," << t.getKey() << ">";
202 }
203
204 private:
205
206 // set a callback that will be called if unknown node are found
207 static SoTypeFromNameCB *setUnknownNameCB(SoTypeFromNameCB *func);
208
209 // Create a new type
210 static SoType createType(const SoType &parent, const SbName &name,
211 void * (*createMethod)(SoType *) = NULL,
212 short data = 0);
213
214 // Make an new type act like an existing type. The new type MUST
215 // be a C++ subclass of the original (e.g. MyCubeClass must be
216 // derived from SoCube), but there is no way for us to check that.
217 // This can be used to get the database to create a different
218 // subclass whenever it reads in an SoNode class from a file.
219 static SoType overrideType(const SoType &existingType,
220 void * (*createMethod)(SoType *) = NULL);
221
222 static SbBool removeType( const SbName &name );
223
224 private:
225
226 // Constructor.
227 SoType() { storage.intValue = SO_BAD_TYPE_INT_INTERNAL; }
228
229 SoType(unsigned int storageValue) { storage.intValue = storageValue; }
230
231 // Initialize the type system
232 static void init();
233 static void finish();
234
235 // get max key value
236 static int maxKey() { return nextIndex; }
237
238 // Get data
239 short getData() const;
240
241 // Returns the type key as a short
242 short getKey() const;
243
244 // Mark this type as internal; if internal, getAllDerivedFrom and
245 // fromName will not return the type.
246 void makeInternal();
247 bool isInternal() const;
248
249 // Get the number of types currently registed in the types dictionary.
250 // This is used by SoAction when setting up the action method list.
251 static int getNumTypes();
252
253 // Get the name of the types currently registered with the key 'key'.
254 static SbName getTypeName(const short key);
255
256 inline unsigned int getStorageValue() const { return storage.intValue; }
257
263 bool isDerivedFrom( const SbName& name ) const;
264
274 static SoType getType(const SbName& name);
275
276 private:
277
278 // SoTypes are passed around on the stack a lot, and are cast to
279 // void *'s; they MUST fit into a single word.
280 union
281 {
282 struct {
283 unsigned int data : 16;
284 unsigned int index : 15; // Assumes we have fewer than 32,768 types
285 unsigned int isPublic :1; // 0 if is an internal class
287 unsigned int intValue;
288 } storage;
289
290 // name->sotype dictionary
291 static SbDict *nameDict;
292
293 // array of SoTypeData
294 static int nextIndex;
295 static int arraySize;
296 static SoTypeData *typeData;
297
298 static void expandTypeData();
299 static SoType fromNameExt(const SbName &name, bool extent);
300
301 static SoTypeFromNameCB *unknownNameFunc;
302 static void *unknownNameData;
303};
304
305#include <Inventor/lists/SoTypeList.h>
306
307#endif /* _SO_TYPE_ */
Character string stored in a hash table.
Definition SbName.h:162
Stores runtime type information.
Definition SoType.h:98
unsigned int intValue
Definition SoType.h:287
friend std::ostream & operator<<(std::ostream &os, const SoType &t)
Writes the SoType to the specified output stream.
Definition SoType.h:199
SbBool isBad() const
Returns TRUE if the type is a bad type.
SbBool isDerivedFrom() const
Returns TRUE if the type is derived from the type of class TypedObjectClass.
Definition SoType.h:145
SbBool canCreateInstance() const
Some types are able to create instances; for example, most nodes and engines (those which are not abs...
unsigned int isPublic
Definition SoType.h:285
unsigned int index
Definition SoType.h:284
void * createInstance(SoType *overrideType=NULL) const
Creates and returns a pointer to an instance of the type.
static int getAllDerivedFrom(const SoType &type, SoTypeList &list)
Adds all types derived from the given type to the given type list.
bool operator!=(const SoType t) const
Returns TRUE if this type is not the same as the given type.
static SoType badType()
Returns an always-illegal type.
Definition SoType.h:124
SbName getName() const
Returns the name associated with a type.
bool operator<(const SoType t) const
Less-than comparison operator that can be used to sort types.
SbBool isDerivedFrom(const SoType &t) const
Returns TRUE if the type is derived from type t.
struct SoType::@11::@12 storageStruct
SoType getParent() const
Returns the type of the parent class.
bool operator==(const SoType t) const
Returns TRUE if this type is the same as the given type.
static SoType fromName(const SbName &name)
Returns the type associated with the given name.
unsigned int data
Definition SoType.h:283
Maintains a list of SoTypes.
Definition SoTypeList.h:72
int SbBool
Boolean type.
Definition SbBase.h:87