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:
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:
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.
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:
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.
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.
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.
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.
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.
|