Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.1.1.1 $ 00045 | 00046 | Description: 00047 | Defines the SoType class. The SoType class is used for 00048 | run-time typing. It is designed to be very small (it 00049 | contains only two shorts) and to support comparison of types, 00050 | single inheritence type hierarchies, and creation of a type 00051 | from a name and create of a C++ instance from an SoType. 00052 | No two types can share the same name, even if they are 00053 | derived from different parents. 00054 | SoTypes may also store an extra short with the type; 00055 | this is used by nodes and actions to keep track of their 00056 | place in the dispatch table. 00057 | 00058 | Author(s) : Nick Thompson, Gavin Bell 00059 | 00060 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00061 _______________________________________________________________________ 00062 */ 00063 00064 #ifndef _SO_TYPE_ 00065 #define _SO_TYPE_ 00066 00067 #include <Inventor/system/SbSystem.h> 00068 #include <Inventor/misc/SoBasic.h> 00069 #include <Inventor/SbString.h> 00070 #include <Inventor/SbDict.h> 00071 00072 class SoTypeList; 00073 struct SoTypeData; 00074 00080 00101 00102 00103 class INVENTOR_API SoType { 00104 #ifdef __DELTA 00105 # pragma __nondynamic_class 00106 #endif 00107 public: 00108 00110 static SoType fromName(SbName name); 00111 00113 SbName getName() const; 00114 00116 SoType getParent() const; 00117 00119 static SoType badType(); 00120 00122 SbBool isBad() const 00123 { return (storage.index == 0); } 00124 00126 SbBool isDerivedFrom(SoType t) const; 00127 00130 static int getAllDerivedFrom(SoType type, 00131 SoTypeList &list); 00132 00136 SbBool canCreateInstance() const; 00137 00146 void * createInstance() const; 00147 00149 int operator ==(const SoType t) const 00150 { return (storage.index == t.storage.index);} 00152 int operator !=(const SoType t) const 00153 { return (storage.index != t.storage.index);} 00154 00157 int operator <(const SoType t) const 00158 { return (storage.index < t.storage.index); } 00159 00160 SoEXTENDER public: 00161 00163 static SoType createType(SoType parent, SbName name, 00164 void * (*createMethod)() = NULL, 00165 short data = 0); 00166 00172 static SoType overrideType(SoType existingType, 00173 void * (*createMethod)() = NULL); 00174 00175 SoINTERNAL public: 00177 static void init(); 00178 00180 short getData() const { return storage.data; } 00181 00183 short getKey() const { return storage.index; } 00184 00187 void makeInternal(); 00188 00191 static int getNumTypes() { return nextIndex; } 00192 00193 private: 00196 struct { 00197 unsigned int data : 16; 00198 unsigned int index : 15; 00199 00200 unsigned int isPublic :1; 00201 } storage; 00202 00204 static SbDict *nameDict; 00205 00207 static int nextIndex; 00208 static int arraySize; 00209 static SoTypeData *typeData; 00210 00211 static void expandTypeData(); 00212 }; 00213 00214 #endif /* _SO_TYPE_ */