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

Declaration of the orxonox::Executor class and the createExecutor() functions. More...

#include "core/CorePrereqs.h"
#include <string>
#include "util/MultiType.h"
#include "Functor.h"
#include "ExecutorPtr.h"

Go to the source code of this file.

Classes

class  orxonox::Executor
 This class is used to wrap a Functor and to store default values for any of its parameters. More...
 
class  orxonox::ExecutorMember< T >
 A child class of Executor, used for easier handling of non-static member-functions. More...
 
class  orxonox::ExecutorStatic
 A child class of Executor, used to distinguish executors that wrap static functions from executors that wrap member-functions. More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Functions

ExecutorPtr orxonox::createExecutor (const FunctorPtr &functor, const std::string &name="")
 Creates a new Executor that wraps a given Functor. More...
 
template<class T >
ExecutorMemberPtr< T > orxonox::createExecutor (const FunctorMemberPtr< T > &functor, const std::string &name="")
 Creates a new ExecutorMember that wraps a given FunctorMember. More...
 
ExecutorStaticPtr orxonox::createExecutor (const FunctorStaticPtr &functor, const std::string &name="")
 Creates a new ExecutorStatic that wraps a given FunctorStatic. More...
 

Detailed Description

Declaration of the orxonox::Executor class and the createExecutor() functions.

orxonox::Executor is used to wrap an orxonox::Functor and to store default values for its parameters. Usually one uses the function createExecutor() to create a new executor. This function returns an orxonox::ExecutorPtr which is a typedef of "std::shared_ptr<Executor>", used to manage the pointer to the executor.

Executors are mostly used to execute callbacks. Because some callback functions need arguments, Executor provides an easy interface to store these arguments as default values, so the executor can also be executed without arguments because it will use these default values.

The Executor doesn't contain the function-pointer directly. Instead it wraps an instance of orxonox::Functor. See Functor.h for more information and some examples.

Example:

void myFunction(int a, int b) // declare a static function
{
orxout() << "The sum is " << (a + b) << endl; // print the sum of a and b to the console
}
FunctorPtr functor = createFunctor(&myFunction); // create a functor that wraps the function-pointer
ExecutorPtr executor = createExecutor(functor); // create an executor that wraps the functor
(*executor)(2, 5); // calls the executor with arguments 2 and 5, prints "The sum is 7" to the console
executor->setDefaultValue(1, 10); // sets the default-value for the second parameter (note: paramters start at index 0) to 10
(*executor)(2); // calls the executor with argument 2 and default-value 10, prints "The sum is 12"
executor->setDefaultValue(0, 5); // sets the default-value for the first parameter to 5
(*executor)(); // calls the executor with default-values only, prints "The sum is 15"

Executors don't need to be deleted after usage normally because they are managed by an std::shared_ptr when they were created with createExecutor().