Open Inventor Reference
SoType.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 | Defines the SoType class. The SoType class is used for
48 | run-time typing. It is designed to be very small (it
49 | contains only two shorts) and to support comparison of types,
50 | single inheritence type hierarchies, and creation of a type
51 | from a name and create of a C++ instance from an SoType.
52 | No two types can share the same name, even if they are
53 | derived from different parents.
54 | SoTypes may also store an extra short with the type;
55 | this is used by nodes and actions to keep track of their
56 | place in the dispatch table.
57 |
58 | Author(s) : Nick Thompson, Gavin Bell
59 |
60 ______________ S I L I C O N G R A P H I C S I N C . ____________
61 _______________________________________________________________________
62 */
63
64#ifndef _SO_TYPE_
65#define _SO_TYPE_
66
69#include <Inventor/SbString.h>
70#include <Inventor/SbDict.h>
71
72class SoTypeList;
73struct SoTypeData;
74
80
102
104 public:
105
107 static SoType fromName(SbName name);
108
111
114
116 static SoType badType();
117
119 bool isBad() const
120 { return (storage.index == 0); }
121
123 bool isDerivedFrom(SoType t) const;
124
127 static int getAllDerivedFrom(SoType type,
128 SoTypeList &list);
129
133 bool canCreateInstance() const;
134
143 void * createInstance() const;
144
146 bool operator ==(const SoType t) const
147 { return (storage.index == t.storage.index);}
149 bool operator !=(const SoType t) const
150 { return (storage.index != t.storage.index);}
151
154 bool operator <(const SoType t) const
155 { return (storage.index < t.storage.index); }
156
157 SoEXTENDER public:
158
160 static SoType createType(SoType parent, SbName name,
161 void * (*createMethod)() = NULL,
162 short data = 0);
163
169 static SoType overrideType(SoType existingType,
170 void * (*createMethod)() = NULL);
171
172 SoINTERNAL public:
174 static void init();
175
177 short getData() const { return storage.data; }
178
180 short getKey() const { return storage.index; }
181
185
188 static int getNumTypes() { return nextIndex; }
189
190 private:
193 struct {
194 unsigned int data : 16;
195 unsigned int index : 15;
197 unsigned int isPublic :1;
198 } storage;
199
201 static SbDict *nameDict;
202
204 static int nextIndex;
205 static int arraySize;
206 static SoTypeData *typeData;
207
208 static void expandTypeData();
209};
210
211#endif /* _SO_TYPE_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#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 INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
Character string stored in a hash table.
Definition SbString.h:264
Maintains a list of SoTypes.
Definition SoLists.h:295
SoType has no virtual functions to keep it small...
Definition SoType.h:103
static SoType fromName(SbName name)
Returns the type associated with the given name.
static int getAllDerivedFrom(SoType type, SoTypeList &list)
Adds all types derived from the given type to the given type list.
bool isDerivedFrom(SoType t) const
Returns TRUE if the type is derived from type t.
void * createInstance() const
Creates and returns a pointer to an instance of the type.
unsigned int isPublic
0 if is an internal class
Definition SoType.h:197
unsigned int index
Assumes we have fewer than 32,768 types.
Definition SoType.h:195
short getData() const
Get data.
Definition SoType.h:177
void makeInternal()
Mark this type as internal; if internal, getAllDerivedFrom and fromName will not return the type.
bool isBad() const
Returns TRUE if the type is a bad type.
Definition SoType.h:119
static SoType overrideType(SoType existingType, void *(*createMethod)()=NULL)
Make an new type act like an existing type.
bool canCreateInstance() const
Some types are able to create instances; for example, most nodes and engines (those which are not abs...
static SoType badType()
Returns an always-illegal type. Useful for returning errors.
static SoType createType(SoType parent, SbName name, void *(*createMethod)()=NULL, short data=0)
Create a new type.
SbName getName() const
Returns the name associated with a type.
short getKey() const
Returns the type key as a short.
Definition SoType.h:180
static int getNumTypes()
Get the number of types currently registed in the types dictionary.
Definition SoType.h:188
SoType getParent() const
Returns the type of the parent class.
static void init()
Initialize the type system.
unsigned int data
Definition SoType.h:194