00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Nick Thompson (MMM yyyy) 00025 ** Modified by : Gavin Bell (MMM yyyy) 00026 **=======================================================================*/ 00027 /*======================================================================= 00028 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00029 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00030 *** *** 00031 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00032 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00033 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00034 *** *** 00035 *** RESTRICTED RIGHTS LEGEND *** 00036 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00037 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00038 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00039 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00040 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00041 *** *** 00042 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00043 *** BORDEAUX, FRANCE *** 00044 *** ALL RIGHTS RESERVED *** 00045 **=======================================================================*/ 00046 /*======================================================================= 00047 ** Modified by : VSG (MMM YYYY) 00048 **=======================================================================*/ 00049 00050 00051 #ifndef _SO_TYPE_ 00052 #define _SO_TYPE_ 00053 00054 #include <Inventor/SbString.h> 00055 #include <Inventor/SbDict.h> 00056 #include <Inventor/STL/ostream> 00057 00058 class SoTypeList; 00059 struct SoTypeData; 00060 class ScDataInputStream; 00061 00062 typedef void *SoTypeFromNameCB(SbName name); 00063 00094 class SoType { 00095 00096 #ifdef __DELTA 00097 # pragma __nondynamic_class 00098 #endif 00099 00100 public: 00101 00105 static SoType fromName(const SbName &name); 00106 00110 SbName getName() const; 00111 00115 SoType getParent() const; 00116 00120 static SoType badType(); 00121 00125 SbBool isBad() const; 00126 00130 SbBool isDerivedFrom(const SoType &t) const; 00131 00136 static int getAllDerivedFrom(const SoType &type, SoTypeList &list); 00137 00143 SbBool canCreateInstance() const; 00144 00145 // Internal note: Only "if_cpp" is needed here. 00146 // .NET and Java API do not use this class. 00147 00160 void *createInstance(SoType *overrideType=NULL) const; 00161 00165 bool operator ==(const SoType t) const; 00166 00170 bool operator !=(const SoType t) const; 00171 00176 bool operator <(const SoType t) const; 00177 00181 friend std::ostream& operator << (std::ostream& os, const SoType& t) 00182 { 00183 return os << "<" << t.getName() << "," << t.getKey() << ">"; 00184 } 00185 00186 private: 00187 00188 // set a callback that will be called if unknown node are found 00189 static SoTypeFromNameCB *setUnknownNameCB(SoTypeFromNameCB *func); 00190 00191 // Create a new type 00192 static SoType createType(const SoType &parent, const SbName &name, 00193 void * (*createMethod)(SoType *) = NULL, 00194 short data = 0); 00195 00196 // Make an new type act like an existing type. The new type MUST 00197 // be a C++ subclass of the original (e.g. MyCubeClass must be 00198 // derived from SoCube), but there is no way for us to check that. 00199 // This can be used to get the database to create a different 00200 // subclass whenever it reads in an SoNode class from a file. 00201 static SoType overrideType(const SoType &existingType, 00202 void * (*createMethod)(SoType *) = NULL); 00203 00204 static SbBool removeType( const SbName &name ); 00205 00206 private: 00207 00208 // Constructor. 00209 SoType(); 00210 00211 SoType(unsigned int storageValue) { storage.intValue = storageValue; } 00212 00213 // Initialize the type system 00214 static void init(); 00215 static void finish(); 00216 00217 // Get data 00218 short getData() const; 00219 00220 // Returns the type key as a short 00221 short getKey() const; 00222 00223 // Mark this type as internal; if internal, getAllDerivedFrom and 00224 // fromName will not return the type. 00225 void makeInternal(); 00226 bool isInternal() const; 00227 00228 // Get the number of types currently registed in the types dictionary. 00229 // This is used by SoAction when setting up the action method list. 00230 static int getNumTypes(); 00231 00232 // Get the name of the types currently registered with the key 'key'. 00233 static SbName getTypeName(const short key); 00234 00235 inline unsigned int getStorageValue() const { return storage.intValue; } 00236 00242 bool isDerivedFrom( const SbName& name ) const; 00243 00244 private: 00245 00246 // SoTypes are passed around on the stack a lot, and are cast to 00247 // void *'s; they MUST fit into a single word. 00248 union 00249 { 00250 struct { 00251 unsigned int data : 16; 00252 unsigned int index : 15; // Assumes we have fewer than 32,768 types 00253 unsigned int isPublic :1; // 0 if is an internal class 00254 } storageStruct; 00255 unsigned int intValue; 00256 } storage; 00257 00258 // name->sotype dictionary 00259 static SbDict *nameDict; 00260 00261 // array of SoTypeData 00262 static int nextIndex; 00263 static int arraySize; 00264 static SoTypeData *typeData; 00265 00266 static void expandTypeData(); 00267 static SoType fromNameExt(const SbName &name, bool extent); 00268 00269 static SoTypeFromNameCB *unknownNameFunc; 00270 static void *unknownNameData; 00271 00272 }; 00273 00274 #include <Inventor/lists/SoTypeList.h> 00275 00276 #endif /* _SO_TYPE_ */ 00277