Run-time type identification (RTTI) technology provides the ability to dynamically identify a class and get various information about it at run-time. RTTI allows developers to:
If an instance belongs to or is derived from the specified class, a pointer to the instance can be converted to the specified class type and applying methods is correct for the instance. After identification of the instance, a developer can perform the specific processing of its data, can call the specific functions or methods, and can apply the admissible operations.
The idea of run-time type identification is to use the special structure of data that stores information about a class and refer to this structure from instances of the class. Each instance of the class derived from the OdRxObject class stores the raw pointer to the structure that describes its class. Information about a class is stored in the special structure. Using the pointer to the describing structure, the instance can get information about its own class at any time. Additionally, each derived class must define the methods that allow its own object to get the pointer to the describing structure, check whether it belongs to the class or its subclass, verify the parent class, and obtain the identity information. All describing structures are usually united in a dictionary of classes; repeating the description of a single class is not necessary.
The implementation of the run-time type identification technology includes declaring and implementing the special classes that store the descriptions of classes, declaring and implementing the methods for getting and checking the class information of classes derived from the OdRxObject class, declaring and implementing the special functions for registering and unregistering class types, and implementing the function for manipulating the describing structures. One instance of the describing structure stores information about one class type. Multiple instances of a class type can refer to one describing structure. Each describing structure stores a reference to the structure that describes its own parent in the hierarchy of classes. The implementation also includes a special dictionary that relates the class name with its describing structure.
The implementation of run-time type identification technology provides the following functionality:
Overview of Classes that Implement RTTI
Understanding Pseudo-Constructors
Understanding the Dictionary of Classes
Registering and Unregistering Classes in a Program
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|