[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.5.1 GiNaC's run-time type information system
All algebraic classes (that is, all classes that can appear in expressions)
in GiNaC are direct or indirect subclasses of the class basic
. So a
basic *
(which is essentially what an ex
is) represents a
generic pointer to an algebraic class. Occasionally it is necessary to find
out what the class of an object pointed to by a basic *
really is.
Also, for the unarchiving of expressions it must be possible to find the
unarchive()
function of a class given the class name (as a string). A
system that provides this kind of information is called a run-time type
information (RTTI) system. The C++ language provides such a thing (see the
standard header file ‘<typeinfo>’) but for efficiency reasons GiNaC
implements its own, simpler RTTI.
The RTTI in GiNaC is based on two mechanisms:
-
The
basic
class declares a member variabletinfo_key
which holds a variable oftinfo_t
type (which is actually justconst void*
) that identifies the object's class. -
By means of some clever tricks with static members, GiNaC maintains a list
of information for all classes derived from
basic
. The information available includes the class names, thetinfo_key
s, and pointers to the unarchiving functions. This class registry is defined in the ‘registrar.h’ header file.
The disadvantage of this proprietary RTTI implementation is that there's a little more to do when implementing new classes (C++'s RTTI works more or less automatically) but don't worry, most of the work is simplified by macros.