Kernel SDK Developer's Guide > Run-Time Type Identification > Overview of Classes that Implement RTTI
Overview of Classes that Implement RTTI

The C++ platform supports RTTI (Run-Time Type Identification) technology which provides a way to verify and obtain various information about classes at run-time and create class instances. To work with RTTI, use the following:

  • OdRxObject abstract class
  • OdRxClass abstract class
  • OdRxClassProtocolExtImpl, OdRxBaseClassImpl, OdRxClassConsImpl, OdRxNamedClassImpl, OdDxfClassImpl classes
  • newOdRxClass and deleteOdRxClass global functions
  • Class dictionary
  • RTTI Macros

OdRxObject class

The OdRxObject abstract class provides the base interface for all classes that use RTTI and is used only for deriving classes. You cannot create an instance of this class. Its pure virtual methods do not have an implementation and are the declaration of the RTTI interface for derived classes. It declares the following RTTI methods:

  • desc() static method — Returns the class describing instance statically associated with the class.
  • isA() virtual method — Returns the class describing instance dynamically associated with the class.
  • isKindOf() method, queryX() virtual method, x() virtual method — Checks whether the instance belongs to the specified class or its subclass.
  • pseudoConstructor() static method — Creates an instance of the class using the default static pseudo-constructor and returns the typified smart pointer to the created instance.
  • createObject() static method — Creates an instance of the class using the pseudo-constructor defined by the class describing instance and returns the non-typified smart pointer to the created instance.
  • rxInit() static method — Registers the class.
  • rxUninit() static method — Unregisters the class.

Classes derived from the OdRxObject class must redefine the RTTI methods. You can either implement these methods in the derived class or you can use the RTTI macros that generate cpp-code for the RTTI methods.

OdRxClass class

The OdRxClass abstract class provides the base interface for class identification functionality and the creation of instances. The OdRxClass class is a successor of the OdRxObject class and inherits its functionality. You cannot create an instance of this class. Its pure virtual methods do not have an implementation and are the declaration of the RTTI interface. The OdRxClass class declares the base interface for the class describing instances that store information about registered classes. It declares the following RTTI methods:

  • name() pure virtual method — Returns the class name.
  • dxfName() pure virtual method — Returns the dxf class name.
  • appName() pure virtual method — Returns the application class name.
  • getClassVersion() pure virtual method — Returns the maintenance version and .dwg file version of the class.
  • proxyFlags() pure virtual method — Returns the proxy flags.
  • customFlags() pure virtual method — Returns the custom flags.
  • constructor() pure virtual method — Returns the pseudo-constructor of the class.
  • setConstructor() pure virtual method — Sets the pseudo-constructor of the class.
  • appNameCallbackPtr() pure virtual method — Returns a pointer to the function called when a drawing is being saved to a file.
  • module() pure virtual method — Returns the raw pointer to the module in which the class resides.
  • myParent() pure virtual method — Returns the raw pointer to the class describing instance that is the parent class.
  • isDerivedFrom() virtual method — Checks whether the class belongs to the specified class or its subclass.
  • create() pure virtual method — Creates an instance of the class using the dynamic pseudo-constructor and returns the non-typified smart pointer to the created instance.

OdRxClassProtocolExtImpl, OdRxBaseClassImpl, OdRxClassConsImpl, OdRxNamedClassImpl, OdDxfClassImpl classes

The OdRxClassProtocolExtImpl, OdRxBaseClassImpl, OdRxClassConsImpl, OdRxNamedClassImpl, and OdDxfClassImpl classes implement the class describing instance. They add new members and create the standard implementation of the pure virtual methods for classes derived from the OdRxClass class.

newOdRxClass and deleteOdRxClass global functions

The newOdRxClass global function registers the class in the program. It creates and initializes the class that describes the instance using the implementing classes listed above. The main class whose instance is used as the class describing instance is the OdDxfClassImpl class. The OdRxClass class is a successor of the OdRxObject class and inherits the numRefs(), addRef(), and release() virtual methods; the newOdRxClass() function additionally uses the OdRxObjectImpl class to wrap the OdDxfClassImpl class in the standard implementation of reference counting. Then the newOdRxClass() function calls the init() method of the OdDxfClassImpl class to initialize information about the class and adds a new record about this class in the class dictionary.

The deleteOdRxClass global function unregisters the class in the program. It removes the class information from the class dictionary and destroys the class description instance using the release() method.

The rxInit() static method registers the class in the program using the newOdRxClass() global function. The rxUninit() static method unregisters the class from the program using the deleteOdRxClass() global function.

Class dictionary

The class dictionary is the existing dictionary object that stores information about all classes registered in the program. The odInitialize() global function creates the class dictionary and initializes it using the predefined class names. The odrxClassDictionary() global function returns the smart pointer to the class dictionary object. The class dictionary allows a developer to manipulate the class described at run-time. The odrxCreateObject() global function allows the creation of class instances using the class name and class dictionary object.

RTTI macros

The ODRX_DECLARE_MEMBERS, ODRX_DEFINE_RTTI_MEMBERS, ODRX_DEFINE_INIT_MEMBERS, ODRX_DEFINE_PSEUDOCONSTRUCTOR, ODRX_DEFINE_MEMBERS2, ODRX_DEFINE_MEMBERS, ODRX_DXF_DEFINE_MEMBERS, ODRX_NO_CONS_DEFINE_MEMBERS, ODRX_CONS_DEFINE_MEMBERS, ODRX_NO_CONS_DEFINE_MEMBERS_ALTNAME, ODRX_CONS_DEFINE_MEMBERS_ALTNAME, ODRX_DXF_CONS_DEFINE_MEMBERS macros generate the implementation for the RTTI methods.

See Also

Concept of RTTI Technology

Functionality of RTTI

Implementing RTTI Methods for the Derived Class

Implementing the Class Describing Structure

Registering and Unregistering Classes in a Program

Belonging to an Instance of a Class

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.