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-2017 BY FEI S.A.S, *** 00043 *** MERIGNAC, 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 00143 static int getAllDerivedFrom(const SoType &type, SoTypeList &list); 00144 00150 SbBool canCreateInstance() const; 00151 00152 // Internal note: Only "if_cpp" is needed here. 00153 // .NET and Java API do not use this class. 00154 00167 void *createInstance(SoType *overrideType=NULL) const; 00168 00172 bool operator ==(const SoType t) const; 00173 00177 bool operator !=(const SoType t) const; 00178 00183 bool operator <(const SoType t) const; 00184 00188 friend std::ostream& operator << (std::ostream& os, const SoType& t) 00189 { 00190 return os << "<" << t.getName() << "," << t.getKey() << ">"; 00191 } 00192 00193 private: 00194 00195 // set a callback that will be called if unknown node are found 00196 static SoTypeFromNameCB *setUnknownNameCB(SoTypeFromNameCB *func); 00197 00198 // Create a new type 00199 static SoType createType(const SoType &parent, const SbName &name, 00200 void * (*createMethod)(SoType *) = NULL, 00201 short data = 0); 00202 00203 // Make an new type act like an existing type. The new type MUST 00204 // be a C++ subclass of the original (e.g. MyCubeClass must be 00205 // derived from SoCube), but there is no way for us to check that. 00206 // This can be used to get the database to create a different 00207 // subclass whenever it reads in an SoNode class from a file. 00208 static SoType overrideType(const SoType &existingType, 00209 void * (*createMethod)(SoType *) = NULL); 00210 00211 static SbBool removeType( const SbName &name ); 00212 00213 private: 00214 00215 // Constructor. 00216 SoType() { storage.intValue = SO_BAD_TYPE_INT_INTERNAL; } 00217 00218 SoType(unsigned int storageValue) { storage.intValue = storageValue; } 00219 00220 // Initialize the type system 00221 static void init(); 00222 static void finish(); 00223 00224 // get max key value 00225 static int maxKey() { return nextIndex; } 00226 00227 // Get data 00228 short getData() const; 00229 00230 // Returns the type key as a short 00231 short getKey() const; 00232 00233 // Mark this type as internal; if internal, getAllDerivedFrom and 00234 // fromName will not return the type. 00235 void makeInternal(); 00236 bool isInternal() const; 00237 00238 // Get the number of types currently registed in the types dictionary. 00239 // This is used by SoAction when setting up the action method list. 00240 static int getNumTypes(); 00241 00242 // Get the name of the types currently registered with the key 'key'. 00243 static SbName getTypeName(const short key); 00244 00245 inline unsigned int getStorageValue() const { return storage.intValue; } 00246 00252 bool isDerivedFrom( const SbName& name ) const; 00253 00254 private: 00255 00256 // SoTypes are passed around on the stack a lot, and are cast to 00257 // void *'s; they MUST fit into a single word. 00258 union 00259 { 00260 struct { 00261 unsigned int data : 16; 00262 unsigned int index : 15; // Assumes we have fewer than 32,768 types 00263 unsigned int isPublic :1; // 0 if is an internal class 00264 } storageStruct; 00265 unsigned int intValue; 00266 } storage; 00267 00268 // name->sotype dictionary 00269 static SbDict *nameDict; 00270 00271 // array of SoTypeData 00272 static int nextIndex; 00273 static int arraySize; 00274 static SoTypeData *typeData; 00275 00276 static void expandTypeData(); 00277 static SoType fromNameExt(const SbName &name, bool extent); 00278 00279 static SoTypeFromNameCB *unknownNameFunc; 00280 static void *unknownNameData; 00281 }; 00282 00283 #include <Inventor/lists/SoTypeList.h> 00284 00285 #endif /* _SO_TYPE_ */ 00286