1.5. Runtime Types

The SoType class keeps track of runtime type information in Inventor. When initialized, many classes request a unique SoType . You can then use this type to find out the actual class of an instance when only its base class is known, or to create an instance of a particular class, given its type or name. Useful type-related methods, which are provided by the macros for implementing most classes, include

getClassTypeId()

a static method that returns the type identifier for a specific class

getTypeId()

a virtual method that returns the type identifier for an entity (for example, a node, field, or action) whose class is unknown

isOfType()

returns TRUE if this entity (for example, node, field, or action) is of the specified type or is derived from that type

All nodes, node kits, manipulators, actions, elements, fields, engines, events, and details in Inventor must have a static method to initialize the class. This method, which must be called initClass(), sets up the type-identifier and file-format name information for the class. Standard Inventor classes are initialized during SoDB::init(), SoInteraction::init(), SoNodeKit::init(), or SoXt::init(). For extender classes, the initClass() method must be called after the database is initialized and before any instance of the class is constructed. The order for initializing is elements first, actions, then nodes.

For any new class that supports runtime typing, the initClass() method must be defined in the header file and implemented in the source file. Most classes have associated macros that can be used within the initClass() method.