Orxonox  0.0.5 Codename: Arcturus
Classes | Namespaces | Functions
Identifier.h File Reference

Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object. More...

#include "core/CorePrereqs.h"
#include <cassert>
#include <map>
#include <set>
#include <string>
#include <typeinfo>
#include <loki/TypeTraits.h>
#include "util/Output.h"
#include "util/OrxAssert.h"
#include "core/object/ObjectList.h"
#include "core/object/Listable.h"
#include "core/object/Context.h"
#include "core/object/Destroyable.h"
#include "core/object/WeakPtr.h"
#include "IdentifierManager.h"
#include "Super.h"

Go to the source code of this file.

Classes

class  orxonox::ClassIdentifier< T >
 The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. More...
 
class  orxonox::Identifier
 The Identifier is used to identify the class of an object and to store information about the class. More...
 
struct  orxonox::Identifier::InheritsFrom
 helper class to manually define inheritance More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Functions

std::ostream & orxonox::operator<< (std::ostream &out, const std::set< const Identifier * > &list)
 Lists the names of all Identifiers in a std::set<const Identifier*>. More...
 
template<class T , class U >
ORX_FORCEINLINEorxonox::orxonox_cast (U *source)
 Casts on object of type Identifiable to any derived type that is registered in the class hierarchy. More...
 

Detailed Description

Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object.

An Identifier "identifies" the class of an object. It contains different information about the class: Its name and ID, a list of all instances of this class, a factory to create new instances of this class, and more.

It also contains information about the inheritance of this class: It stores a list of the Identifiers of all parent-classes as well as a list of all child-classes. These relationships can be tested using functions like isA(), isChildOf(), isParentOf(), and more.

Every Identifier is in fact a ClassIdentifier<T> (where T is the class that is identified by the Identifier), Identifier is just the common base-class.

Example:

MyClass* object = new MyClass(); // create an instance of MyClass
object->getIdentifier()->getName(); // returns "MyClass"
Identifiable* other = object->getIdentifier()->fabricate(nullptr); // fabricates a new instance of MyClass
// test the class hierarchy
object->getIdentifier()->isA(Class(MyClass)); // returns true
object->isA(Class(MyClass)); // returns true (short version)
object->isA(Class(BaseClass)); // returns true if MyClass is a child of BaseClass
Class(ChildClass)->isChildOf(object->getIdentifier()); // returns true if ChildClass is a child of MyClass