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

Definition of SubclassIdentifier. More...

#include "core/CorePrereqs.h"
#include <cstdlib>
#include "util/Output.h"
#include "Identifier.h"

Go to the source code of this file.

Classes

class  orxonox::SubclassIdentifier< T >
 The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Detailed Description

Definition of SubclassIdentifier.

SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.

Example:

You can assign an Identifier either through the constructor or by using the assignment operator=:

SubclassIdentifier<BaseClass> identifier = Class(SubClass);

The operator-> is overloaded an returns the assigned Identifier. That way you can just call functions of the assigned Identifier by using ->function():

SubclassIdentifier<BaseClass> identifier = Class(SubClass);
identifier->getName(); // returns "SubClass"

There are two possibilities to create an object out of a SubclassIdentifier: Either you just use the fabricate() function of the assigned Identifier through the overloaded operator->, which returns a OrxonoxClass* pointer, or you use the function of SubclassIdentifier, this time by using operator., which returns a BaseClass* pointer (BaseClass is the baseclass specified by the template argument):

identifier->fabricate(); // calls Identifier::fabricate(), creates a SubClass, returns a OrxonoxClass* pointer
identifier.fabricate(); // calls SubclassIdentifier::fabricate(), creates a SubClass, returns a BaseClass* pointer