.TH "SoType" 3 "Tue Dec 26 2023 17:59:22" "Version 4.0.2" "Coin" \" -*- nroff -*- .ad l .nh .SH NAME SoType \- The \fBSoType\fP class is the basis for the runtime type system in Coin\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .SS "Public Types" .in +1c .ti -1c .RI "\fBtypedef\fP \fBvoid\fP *(* \fBinstantiationMethod\fP) (\fBvoid\fP)" .br .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBSbName\fP \fBgetName\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "\fBconst\fP \fBSoType\fP \fBgetParent\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "SbBool \fBisDerivedFrom\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBcanCreateInstance\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "\fBvoid\fP * \fBcreateInstance\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "uint16_t \fBgetData\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "int16_t \fBgetKey\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator==\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator!=\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator<\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator<=\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator>=\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBoperator>\fP (\fBconst\fP \fBSoType\fP type) \fBconst\fP" .br .ti -1c .RI "SbBool \fBisBad\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "\fBvoid\fP \fBmakeInternal\fP (\fBvoid\fP)" .br .ti -1c .RI "SbBool \fBisInternal\fP (\fBvoid\fP) \fBconst\fP" .br .ti -1c .RI "\fBinstantiationMethod\fP \fBgetInstantiationMethod\fP (\fBvoid\fP) \fBconst\fP" .br .in -1c .SS "Static Public Member Functions" .in +1c .ti -1c .RI "\fBstatic\fP \fBSoType\fP \fBfromName\fP (\fBconst\fP \fBSbName\fP name)" .br .ti -1c .RI "\fBstatic\fP int \fBgetAllDerivedFrom\fP (\fBconst\fP \fBSoType\fP type, \fBSoTypeList\fP &\fBlist\fP)" .br .ti -1c .RI "\fBstatic\fP \fBconst\fP \fBSoType\fP \fBcreateType\fP (\fBconst\fP \fBSoType\fP parent, \fBconst\fP \fBSbName\fP name, \fBconst\fP \fBinstantiationMethod\fP method=\fBNULL\fP, \fBconst\fP uint16_t data=0)" .br .ti -1c .RI "\fBstatic\fP \fBconst\fP \fBSoType\fP \fBoverrideType\fP (\fBconst\fP \fBSoType\fP \fBoriginalType\fP, \fBconst\fP \fBinstantiationMethod\fP method=\fBNULL\fP)" .br .ti -1c .RI "\fBstatic\fP SbBool \fBremoveType\fP (\fBconst\fP \fBSbName\fP &name)" .br .ti -1c .RI "\fBstatic\fP \fBvoid\fP \fBinit\fP (\fBvoid\fP)" .br .ti -1c .RI "\fBstatic\fP \fBSoType\fP \fBfromKey\fP (uint16_t key)" .br .ti -1c .RI "\fBstatic\fP \fBSoType\fP \fBbadType\fP (\fBvoid\fP)" .br .ti -1c .RI "\fBstatic\fP int \fBgetNumTypes\fP (\fBvoid\fP)" .br .in -1c .SH "Detailed Description" .PP The \fBSoType\fP class is the basis for the runtime type system in Coin\&. Many of the classes in the Coin library must have their type information registered before any instances are created (including, but not limited to: engines, nodes, fields, actions, nodekits and manipulators)\&. The use of \fBSoType\fP to store this information provides lots of various functionality for working with class hierarchies, comparing class types, instantiating objects from class names, etc etc\&. .PP It is for instance possible to do things like this: .PP .PP .nf void cleanLens(SoNode * anode) { assert(anode\->getTypeId()\&.isDerivedFrom(SoCamera::getClassTypeId())); if (anode\->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { // do something\&.\&. } else if (anode\->getTypeId() == SoOrthographicCamera::getClassTypeId()) { // do something\&.\&. } else { SoDebugError::postWarning("cleanLens", "Unknown camera type %s!\\n", anode\->getTypeId()\&.getName()); } } .fi .PP .PP A notable feature of the \fBSoType\fP class is that it is only 16 bits long and therefore should be passed around by value for efficiency reasons\&. .PP One important note about the use of \fBSoType\fP to register class information: super classes must be registered before any of their derived classes are\&. .PP See also \fBDynamic Loading of Extension Nodes\fP for some additional SoType-related information\&. .SH "Member Typedef Documentation" .PP .SS "SoType::instantiationMethod" This is a convenience typedef for the function signature of a typed class' instantiation method\&. It is an extension on the original Inventor API\&. Mostly only useful for internal purposes\&. .PP An instantiation method will take no arguments and returns a void pointer to a newly allocated and initialized object of the class type\&. .SH "Member Function Documentation" .PP .SS "\fBSoType\fP SoType::fromName (\fBconst\fP \fBSbName\fP name)\fC [static]\fP" This static function returns the \fBSoType\fP object associated with name \fIname\fP\&. .PP Type objects for built-in types can be retrieved by name both with and without the 'So' prefix\&. For dynamically loadable extension nodes, the name given to this function must match exactly\&. .PP If no node type with the given name has been initialized, a dynamically loadable extension node with the given name is searched for\&. If one is found, it is loaded and initialized, and the \fBSoType\fP object for the newly initialized class type returned\&. If no module is found, or the initialization of the module fails, \fBSoType::badType()\fP is returned\&. .PP Support for dynamically loadable extension nodes varies from platform to platform, and from compiler suite to compiler suite\&. .PP So far code built with the following compilers are supported: GNU GCC v2-4, Microsoft Visual C++ v6, 2003, 2005 and 2008), SGI MIPSPro v7\&. .PP Extensions built with compilers that are known to be binary compatible with the above compilers are also supported, such as e\&.g\&. the Intel x86 compiler compatible with MSVC++\&. .PP To support dynamic loading for other compilers, we need to know how the compiler mangles the 'static void classname::initClass(void)' symbol\&. If your compiler is not supported, tell us at \fCcoin-support@coin3d.org\fP which it is and send us the output of a symbol-dump on the shared object\&. Typically you can do .PP .PP .nf $ nm \&.so | grep initClass .fi .PP .PP to find the relevant mangled symbol\&. .SS "\fBSbName\fP SoType::getName (\fBvoid\fP) const" This method returns the name of the SoBase-derived class type the \fBSoType\fP object is configured for\&. .SS "\fBconst\fP \fBSoType\fP SoType::getParent (\fBvoid\fP) const" This method returns the \fBSoType\fP type for the parent class of the SoBase-derived class the \fBSoType\fP object is configured for\&. .SS "SbBool SoType::isDerivedFrom (\fBconst\fP \fBSoType\fP parent) const" This method returns \fCTRUE\fP if the given type is derived from (or \fIis\fP) the \fIparent\fP type, and \fCFALSE\fP otherwise\&. .SS "int SoType::getAllDerivedFrom (\fBconst\fP \fBSoType\fP type, \fBSoTypeList\fP & list)\fC [static]\fP" This method appends all the class types derived from \fItype\fP to \fIlist\fP, and returns the number of types added to the list\&. Internal types are not included in the list, nor are they counted\&. .PP \fItype\fP itself is also added to the list, as a type is seen as a derivation of its own type\&. .PP NB: do not write code which depends in any way on the order of the elements returned in \fIlist\fP\&. .PP Here is a small, standalone example which shows how this method can be used for introspection, listing all subclasses of the \fBSoBase\fP superclass: .PP .PP .nf #include #include #include static void list_subtypes(SoType t, unsigned int indent = 0) { SoTypeList tl; SoType::getAllDerivedFrom(t, tl); for (unsigned int i=0; i < indent; i++) { printf(" "); } printf("%s\\n", t\&.getName()\&.getString()); indent++; for (int j=0; j < tl\&.getLength(); j++) { if (tl[j]\&.getParent() == t) { // only interested in direct descendents list_subtypes(tl[j], indent); } } } int main(void) { SoDB::init(); list_subtypes(SoType::fromName("SoBase")); return 0; } .fi .PP .SS "SbBool SoType::canCreateInstance (\fBvoid\fP) const" This method returns \fCFALSE\fP for abstract base classes, and \fCTRUE\fP for class types that can be instantiated\&. .SS "\fBvoid\fP * SoType::createInstance (\fBvoid\fP) const" This method instantiates an object of the current type\&. .PP For types that cannot be instantiated, \fCNULL\fP is returned\&. .PP \fBNote that if the Coin library has been built as a DLL under Microsoft Windows and you use this method from application code, you \fImust\fP make sure that both the Coin DLL and the application executable are using the same instance of a C Run-Time (CRT) library\&. Otherwise, you \fIwill\fP get memory heap corruption upon deallocating the returned instances, eventually leading to mysterious crashes\&.\fP .br .br This is not harmful if you only call \fBSoType::createInstance()\fP on types for reference counted class-types, though\&. These include all nodes, engines, paths, nodekits, draggers and manipulators\&. .SS "uint16_t SoType::getData (\fBvoid\fP) const" This method returns a type specific data variable\&. .SS "int16_t SoType::getKey (\fBvoid\fP) const\fC [inline]\fP" This method returns the type's index in the internal type list\&. .SS "SbBool SoType::operator== (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Check type equality\&. .SS "SbBool SoType::operator!= (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Check type inequality\&. .SS "SbBool SoType::operator< (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Comparison operator for sorting type data according to some internal criterion\&. .SS "SbBool SoType::operator<= (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Comparison operator for sorting type data according to some internal criterion\&. .SS "SbBool SoType::operator>= (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Comparison operator for sorting type data according to some internal criterion\&. .SS "SbBool SoType::operator> (\fBconst\fP \fBSoType\fP type) const\fC [inline]\fP" Comparison operator for sorting type data according to some internal criterion\&. .SS "\fBconst\fP \fBSoType\fP SoType::createType (\fBconst\fP \fBSoType\fP parent, \fBconst\fP \fBSbName\fP name, \fBconst\fP \fBinstantiationMethod\fP method = \fC\fBNULL\fP\fP, \fBconst\fP uint16_t data = \fC0\fP)\fC [static]\fP" This method creates and registers a new class type\&. .PP Classes that do not inherit any other class should use \fBSoType::badType()\fP for the first argument\&. Abstract classes should use \fCNULL\fP for the \fImethod\fP argument\&. .PP The value passed in for the \fIdata\fP parameter can be retrieved with \fBSoType::getData()\fP\&. .SS "\fBconst\fP \fBSoType\fP SoType::overrideType (\fBconst\fP \fBSoType\fP originalType, \fBconst\fP \fBinstantiationMethod\fP method = \fC\fBNULL\fP\fP)\fC [static]\fP" This method makes a new class's instantiation method override the instantiation method of an existing class\&. .PP The new type should be a C++ subclass of the original class type, but this won't be checked though\&. .PP If \fCNULL\fP is passed as the second argument, the type will be considered uninstantiable -- it does not revert the configuration to the default setting as one might think\&. .PP Here's a \fIcomplete\fP code examples which shows how to fully override a built-in Coin node class, so that a) your application-specific extension class gets instantiated instead of the built-in class upon scene graph import, and b) it gets written out properly upon export: .PP .PP .nf #include #include #include #include #include class MyWWWInline : public SoWWWInline { SO_NODE_HEADER(MyWWWInline); public: static void initClass(void); MyWWWInline(void); protected: virtual ~MyWWWInline(); virtual SbBool readInstance(SoInput * in, unsigned short flags); virtual const char * getFileFormatName(void) const; }; SO_NODE_SOURCE(MyWWWInline); MyWWWInline::MyWWWInline(void) { SO_NODE_CONSTRUCTOR(MyWWWInline); // Fool the library to believe this is an internal class, so it gets // written out in the same manner as the built\-in classes, instead // of as en extension class\&. There are slight differences, which you // want to avoid when overriding a class like we do with MyWWWInline // vs SoWWWInline here\&. this\->isBuiltIn = TRUE; } MyWWWInline::~MyWWWInline() { } void MyWWWInline::initClass(void) { SO_NODE_INIT_CLASS(MyWWWInline, SoWWWInline, "SoWWWInline"); // Override instantiation method, so we get MyWWWInline instead of // SoWWWInline instances upon scene graph import\&. (void)SoType::overrideType(SoWWWInline::getClassTypeId(), MyWWWInline::createInstance); } // Override SoBase::getFileFormatName() to make node get written as // "WWWInline" instead of "MyWWWInline"\&. const char * MyWWWInline::getFileFormatName(void) const { return "WWWInline"; } SbBool MyWWWInline::readInstance(SoInput * in, unsigned short flags) { SoDebugError::postInfo("MyWWWInline::readInstance", "hepp"); return SoWWWInline::readInstance(in, flags); } int main(int argc, char ** argv) { SoDB::init(); MyWWWInline::initClass(); const char * ivscene = "#Inventor V2\&.1 ascii\\n\\n" "Separator {" " WWWInline { }" "}"; SoInput in; in\&.setBuffer(ivscene, strlen(ivscene)); SoSeparator * root = SoDB::readAll(&in); root\->ref(); SoOutput out; SoWriteAction wa(&out); wa\&.apply(root); root\->unref(); return 0; } .fi .PP .SS "SbBool SoType::removeType (\fBconst\fP \fBSbName\fP & name)\fC [static]\fP" This method removes class type from the class system\&. Returns FALSE if a type with the given name doesn't exist\&. .PP \fBSince\fP .RS 4 Coin \fB3\&.0\fP .RE .PP .SS "\fBvoid\fP SoType::init (\fBvoid\fP)\fC [static]\fP" This static method initializes the type system\&. .SS "\fBSoType\fP SoType::fromKey (uint16_t key)\fC [static]\fP" Find and return a type from the given key ID\&. .SS "\fBSoType\fP SoType::badType (\fBvoid\fP)\fC [static]\fP" This method returns an illegal type, useful for returning errors\&. .PP \fBSee also\fP .RS 4 SbBool \fBSoType::isBad() const\fP .RE .PP .SS "SbBool SoType::isBad (\fBvoid\fP) const\fC [inline]\fP" This method returns TRUE if the \fBSoType\fP object represents an illegal class type\&. .SS "\fBvoid\fP SoType::makeInternal (\fBvoid\fP)" This method turns the specific type into an internal type\&. .SS "SbBool SoType::isInternal (\fBvoid\fP) const" This function returns TRUE if the type is an internal type\&. .SS "int SoType::getNumTypes (\fBvoid\fP)\fC [static]\fP" This function returns the number of types registered in the runtime type system\&. .SS "\fBSoType::instantiationMethod\fP SoType::getInstantiationMethod (\fBvoid\fP) const" Returns a pointer to the method used to instantiate objects of the given type\&. .PP This function is an extension for Coin, and it is not available in the original SGI Open Inventor \fBv2\&.1\fP API\&. .br .PP \fBSince\fP .RS 4 Coin \fB2\&.0\fP .RE .PP .SH "Author" .PP Generated automatically by Doxygen for Coin from the source code\&.