Orxonox
0.0.5 Codename: Arcturus
|
Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functions. More...
#include "core/CorePrereqs.h"
#include <typeinfo>
#include "util/Output.h"
#include "util/MultiType.h"
#include "core/object/Destroyable.h"
#include "FunctorPtr.h"
Go to the source code of this file.
Classes | |
class | orxonox::Functor |
The Functor classes are used to wrap function pointers. More... | |
class | orxonox::FunctorMember< O > |
FunctorMember is a child class of Functor and expands it with an object-pointer, that is used for member-functions, as well as an overloaded execution operator. More... | |
class | orxonox::FunctorMember< void > |
Specialization of FunctorMember with T = void. More... | |
class | orxonox::FunctorPointer< F, O > |
FunctorPointer is a child class of FunctorMember and extends it with a function-pointer (or a function-object). More... | |
class | orxonox::FunctorTemplate< F, R, O, isconst, Params > |
FunctorTemplate is a child class of FunctorPointer and implements all functions that need to know the exact types of the parameters, return-value, and class. More... | |
Namespaces | |
orxonox | |
Die Wagnis Klasse hat die folgenden Aufgaben: | |
Typedefs | |
typedef FunctorMember< void > | orxonox::FunctorStatic |
FunctorStatic is just a typedef of FunctorMember with T = void. More... | |
Functions | |
template<class R , class O , class OO , class... Params> | |
FunctorMemberPtr< O > | orxonox::createFunctor (R(O::*functionPointer)(Params...), OO *object) |
Creates a new FunctorMember with the given function-pointer and an assigned object. More... | |
template<class R , class O , class... Params> | |
FunctorMemberPtr< O > | orxonox::createFunctor (R(O::*functionPointer)(Params...)) |
Creates a new FunctorMember with the given function-pointer. More... | |
template<class R , class... Params> | |
FunctorStaticPtr | orxonox::createFunctor (R(*functionPointer)(Params...)) |
Creates a new FunctorStatic with the given function-pointer. More... | |
template<class F > | |
FunctorStaticPtr | orxonox::createFunctor (const F &functionObject) |
Take care that this functor does not outlive objects that have been captured by reference in a lambda. More... | |
template<class T > | |
std::string | orxonox::typeToString () |
Returns the name of type T as string. More... | |
Variables | |
const unsigned int | orxonox::MAX_FUNCTOR_ARGUMENTS = 5 |
The maximum number of parameters of a function that is supported by Functor. More... | |
Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functions.
Functors can be used to wrap function-pointers. While function-pointers have a very complicated syntax in C++, Functors are always the same and you can call the wrapped function-pointer independently of its parameter with arguments of type MultiType. These arguments are then automatically converted to the right type.
To create a Functor, the helper function createFunctor() is used. It returns an instance of orxonox::FunctorPtr which is simply a typedef of "std::shared_ptr<Functor>". This means you don't have to delete the Functor after using it, because it is managed by the std::shared_ptr.
Example:
Functors can also be used if you work with member-functions. In this case createFunctor() returns an instance of orxonox::FunctorMemberPtr - this allows you to define the object that will be used to call the function.
Example:
Instead of assigning the object directly to the functor when creating it, you can also define it at any later point or when you call the functor. Note however that this works only with orxonox::FunctorMember.