casa
5.7.0-16
|
Primitive Run Time Type Information (RTTI) More...
#include <Register.h>
Public Member Functions | |
template<class t > | |
uInt | Register (const t *) |
This is a templated function which takes a pointer to any class as a parameter. More... | |
Primitive Run Time Type Information (RTTI)
Public interface
This function is called Register because the user is registering a type with the run-time type mechanism.
This function returns a unique unsigned integer (uInt) for each type of pointer the user passes in as a parameter. It will always return the same number for a given type during a particular execution. The unsigned integer which is returned can be use to identify the particular type.
Warning: This function does not work correctly for multiple inheritance, but ONLY for single inheritance; In addition, the type number which is returned is NOT unique across program executions;
This RTTI mechanism is simple, it does not require extra functions to be added to the classes which are to be identified, and it is similar to the RTTI mechanism which will be a part of the C++ language in the future.
To be useful, however, this mechanism must be used as part of the implementation of a virtual member function. For example:
The output of this code would look something like:
f: type()=1 Register()=1 b: type()=2 Register()=1
Without the virtual function, type()
, the output of Register()
is deceiving and of little use.
Needed a simple type identification mechanism for the Notice class. This was necessary so that multiple notices could be distinguished. It can be replaced by the future standard RTTI.
Definition at line 107 of file Register.h.
uInt casacore::Register_global_functions_register::Register | ( | const t * | ) |
This is a templated function which takes a pointer to any class as a parameter.
The parameter's type is then used to generate a unique id. The parameter is a pointer rather than a value for efficiency reasons. With a value parameter, it would be difficult to do things like:
to find the Register
type id for a random class.