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-2019 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 00064 #ifndef HIDDEN_FROM_DOC 00065 //Int32 value of a badtype 00066 #define SO_BAD_TYPE_INT_INTERNAL 0x80000000 00067 #endif 00068 00098 class SoType { 00099 00100 #ifdef __DELTA 00101 # pragma __nondynamic_class 00102 #endif 00103 00104 public: 00105 00109 static SoType fromName(const SbName &name); 00110 00114 SbName getName() const; 00115 00119 SoType getParent() const; 00120 00124 inline static SoType badType() 00125 { 00126 return (SoType)SO_BAD_TYPE_INT_INTERNAL; 00127 } 00128 00132 SbBool isBad() const; 00133 00137 SbBool isDerivedFrom(const SoType &t) const; 00138 00144 template<typename TypedObjectClass> 00145 SbBool isDerivedFrom() const 00146 { 00147 return isDerivedFrom( TypedObjectClass::getClassTypeId() ); 00148 } 00149 00154 static int getAllDerivedFrom(const SoType &type, SoTypeList &list); 00155 00161 SbBool canCreateInstance() const; 00162 00163 // Internal note: Only "if_cpp" is needed here. 00164 // .NET and Java API do not use this class. 00165 00178 void *createInstance(SoType *overrideType=NULL) const; 00179 00183 bool operator ==(const SoType t) const; 00184 00188 bool operator !=(const SoType t) const; 00189 00194 bool operator <(const SoType t) const; 00195 00199 friend std::ostream& operator << (std::ostream& os, const SoType& t) 00200 { 00201 return os << "<" << t.getName() << "," << t.getKey() << ">"; 00202 } 00203 00204 private: 00205 00206 // set a callback that will be called if unknown node are found 00207 static SoTypeFromNameCB *setUnknownNameCB(SoTypeFromNameCB *func); 00208 00209 // Create a new type 00210 static SoType createType(const SoType &parent, const SbName &name, 00211 void * (*createMethod)(SoType *) = NULL, 00212 short data = 0); 00213 00214 // Make an new type act like an existing type. The new type MUST 00215 // be a C++ subclass of the original (e.g. MyCubeClass must be 00216 // derived from SoCube), but there is no way for us to check that. 00217 // This can be used to get the database to create a different 00218 // subclass whenever it reads in an SoNode class from a file. 00219 static SoType overrideType(const SoType &existingType, 00220 void * (*createMethod)(SoType *) = NULL); 00221 00222 static SbBool removeType( const SbName &name ); 00223 00224 private: 00225 00226 // Constructor. 00227 SoType() { storage.intValue = SO_BAD_TYPE_INT_INTERNAL; } 00228 00229 SoType(unsigned int storageValue) { storage.intValue = storageValue; } 00230 00231 // Initialize the type system 00232 static void init(); 00233 static void finish(); 00234 00235 // get max key value 00236 static int maxKey() { return nextIndex; } 00237 00238 // Get data 00239 short getData() const; 00240 00241 // Returns the type key as a short 00242 short getKey() const; 00243 00244 // Mark this type as internal; if internal, getAllDerivedFrom and 00245 // fromName will not return the type. 00246 void makeInternal(); 00247 bool isInternal() const; 00248 00249 // Get the number of types currently registed in the types dictionary. 00250 // This is used by SoAction when setting up the action method list. 00251 static int getNumTypes(); 00252 00253 // Get the name of the types currently registered with the key 'key'. 00254 static SbName getTypeName(const short key); 00255 00256 inline unsigned int getStorageValue() const { return storage.intValue; } 00257 00263 bool isDerivedFrom( const SbName& name ) const; 00264 00265 private: 00266 00267 // SoTypes are passed around on the stack a lot, and are cast to 00268 // void *'s; they MUST fit into a single word. 00269 union 00270 { 00271 struct { 00272 unsigned int data : 16; 00273 unsigned int index : 15; // Assumes we have fewer than 32,768 types 00274 unsigned int isPublic :1; // 0 if is an internal class 00275 } storageStruct; 00276 unsigned int intValue; 00277 } storage; 00278 00279 // name->sotype dictionary 00280 static SbDict *nameDict; 00281 00282 // array of SoTypeData 00283 static int nextIndex; 00284 static int arraySize; 00285 static SoTypeData *typeData; 00286 00287 static void expandTypeData(); 00288 static SoType fromNameExt(const SbName &name, bool extent); 00289 00290 static SoTypeFromNameCB *unknownNameFunc; 00291 static void *unknownNameData; 00292 }; 00293 00294 #include <Inventor/lists/SoTypeList.h> 00295 00296 #endif /* _SO_TYPE_ */ 00297