Functions |
template<typename T > |
const T & | getDefault () |
template<typename T > |
void * | getNew () |
template<typename T > |
const char * | getName () |
template<typename T > |
void * | getClassID () |
template<typename T > |
const char * | getStreamName () |
template<typename T , typename U > |
bool | isKindOf (const U &u) |
template<typename T , typename U > |
T * | castTo (const U &u) |
template<typename T , typename U > |
bool | isInstanceOf (const U &u) |
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* BALL::RTTI::castTo |
( |
const U & |
u |
) |
[inline] |
Cast an object to a specialized class. Example:
Composite* composite = ...;
...
if (RTTI::isKindOf<Atom>(composite))
{
Atom* atom = RTTI::castTo<Atom>(*composite);
...
atom->setCharge(0);
...
}
Definition at line 215 of file rtti.h.
template<typename T >
void* BALL::RTTI::getClassID |
( |
|
) |
[inline] |
Return a void pointer that is unique for each class.
Definition at line 105 of file rtti.h.
template<typename T >
const T& BALL::RTTI::getDefault |
( |
|
) |
[inline] |
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.
Definition at line 75 of file rtti.h.
template<typename T >
const char* BALL::RTTI::getName |
( |
|
) |
[inline] |
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.
Definition at line 97 of file rtti.h.
template<typename T >
void* BALL::RTTI::getNew |
( |
|
) |
[inline] |
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.
Definition at line 87 of file rtti.h.
template<typename T >
const char* BALL::RTTI::getStreamName |
( |
|
) |
[inline] |
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>();
...
Definition at line 122 of file rtti.h.
template<typename T , typename U >
bool BALL::RTTI::isInstanceOf |
( |
const U & |
u |
) |
[inline] |
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.
Definition at line 226 of file rtti.h.
template<typename T , typename U >
bool BALL::RTTI::isKindOf |
( |
const U & |
u |
) |
[inline] |
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);
Definition at line 192 of file rtti.h.