Simplified RunTime Type
Identification.
More...
|
Functions
|
|
template<typename T> |
| const T & |
getDefault () |
| |
Return a reference to a static
default instance of the corresponding class.
|
|
template<typename T> |
| void * |
getNew () |
| |
Return a void pointer to a new
instance of the class.
|
|
template<typename T> |
| const char * |
getName () |
| |
Return the name of the class.
|
|
template<typename T> |
| void * |
getClassID () |
| |
Return a void pointer that is unique
for each class.
|
|
template<typename T> |
| const char * |
getStreamName
() |
| |
Return the demangled class name.
|
|
template<typename T, typename U> |
| bool |
isKindOf (const U
&u) |
| |
Return true if u is a
kind of T.
|
|
template<typename T, typename U> |
| T * |
castTo (const U
&u) |
| |
Cast an object to a specialized
class.
|
|
template<typename T, typename U> |
| bool |
isInstanceOf
(const U &u) |
| |
Return true if a given object
is an instance of a given class.
|
Detailed Description
Simplified RunTime Type
Identification.
ANSI C++ provides support for runtime type identification
(RTTI).
However, the support is very basic. The template functions of
the RTTI
namespace provide a more readable support for RTTI. It defines
predicates such as isKindOf that simplify
tests on the hereditary relationship of different objects.
- To use the RTTI template functions,
parametrize it with the type you are interested in. For
example, to find out whether a given molecule is a protein,
the following code can be used:
-
Molecule& m =...;
...
if (RTTI::isKindOf<Protein>(m))
{
} else {
}
Function Documentation
| template<typename T,
typename U> |
| T*
castTo |
( |
const U
& |
u |
) |
|
|
| |
Cast an object to a specialized class.
Example:
-
Composite* composite = ...;
...
if (RTTI::isKindOf<Atom>(composite))
{
Atom* atom = RTTI::castTo<Atom>(*composite);
...
atom->setCharge(0);
...
}
|
| template<typename
T> |
| void*
getClassID |
( |
|
) |
|
|
| |
Return a void pointer that is unique for each
class.
|
| template<typename
T> |
| const
T& getDefault |
( |
|
) |
|
|
| |
Return a reference to a static default instance of the
corresponding class.
This method is basically intended to provide a default
object for certain operations that require an instance of
a certain class without really using this instance. It is
mainly used inside the RTTI class.
|
| template<typename
T> |
| const
char* getName |
( |
|
) |
|
|
| |
Return the name of the class.
This method returns the name of the class as given by
typeid(<class instance>.name()). No
additional name demangling and whitespace substitution
are performed.
|
| template<typename
T> |
| void*
getNew |
( |
|
) |
|
|
| |
Return a void pointer to a new instance of the
class.
Use this method to provide an easy factory for objects
of a certain class. The main use of this function lies in
object persistence. The PersistenceManager
needs a function for the dynamic creation of objects.
|
| template<typename
T> |
| const
char* getStreamName |
( |
|
) |
|
|
| |
Return the demangled class name.
The class name is demangled (as far as possible) and
in the resulting string blanks are substituted by
underscores, so the name can be read from a stream as one
string. The typical usage is something like
String class_name = RTTI::getStreamName<Residue>();
...
|
| template<typename T,
typename U> |
| bool
isInstanceOf |
( |
const U
& |
u |
) |
|
|
| |
Return true if a given object is an instance of
a given class.
If u is an instance of T,
this predicate returns true. If u is
an instance of a class that is derived from
T or a base class of T, it
returns false.
|
| template<typename T,
typename U> |
| bool
isKindOf |
( |
const U
& |
u |
) |
|
|
| |
Return true if u is a kind of T.
If u is an instance of a class derived
from T, this predicate returns true:
-
Protein p;
bool is_molecule = RTTI::isKindOf<Molecule>(p);
|