Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
backcaller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __BACKCALLER_H_
25 #define __BACKCALLER_H_
26 
27 #include <vector>
28 #include <cstddef>
29 #include "stl_map.h"
30 
31 class Callbackable;
32 
33 /**
34  * Class prototype which provides functions to handle callbackable classes.
35  * If a class implements this class, just use the function callBack which
36  * calls all registered callbackable classes.
37  * If you use different callbackable pools, just use the overloaded functions
38  * callBack(CallbackableType type),
39  * addCallbackable(CallbackableType, Callbackable* cb) and
40  * removeCallbackable(CallbackableType, Callbackable* cb).
41  */
43 {
44  public:
45  typedef unsigned long CallbackableType;
46 
47  /**
48  * This is the default Callbackable type.
49  * If you derive from BackCaller, just define your own CallbackableTypes.
50  */
52 
53  BackCaller();
54  virtual ~BackCaller();
55 
56  /**
57  * Adds a Callbackable instance to this caller instance.
58  * @param type the desired CallbackableType of the Callbackable class.
59  * @param callbackableInstance the instance to add
60  */
61  virtual void addCallbackable(Callbackable* callbackableInstance, CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
62 
63  /**
64  * Removes a Callbackable instance from this caller instance.
65  * @param type the CallbackableType of the Callbackable class.
66  * @param callbackableInstance
67  */
69 
70  /**
71  * Removes all Callbackable instances from this caller instance
72  * @param type the CallbackableType of the Callbackable class to be removed.
73  */
74  virtual void removeAllCallbackables(CallbackableType type /* = BackCaller::DEFAULT_CALLBACKABLE_TYPE */);
75 
76 
77  /**
78  * Calls all registered callbackable classes of the determined type.
79  * This is done by Callbackable::doOnCallback(CallbackableType type).
80  * You can make this function private/protected if you like.
81  * @param type the CallbackableType of the Callbackable classes.
82  */
84 
85  /**
86  * Calls all registered callbackable classes of the determined type.
87  * This is done by Callbackable::doOnCallback(CallbackableType type).
88  * This function uses QUICKMP in order to parallelise the callbacks.
89  * Remember that there is only shared the used CallbackableList. So if you
90  * have other variables/objects to share, implement your own version.
91  * You can make this function private/protected if you like.
92  * @param type the CallbackableType of the Callbackable classes.
93  */
95 
96  private:
97  struct CallbackableTypeHash
98  {
99  size_t operator() (const CallbackableType& type) const { return type; }
100  };
101 
102  typedef std::vector<Callbackable*> callbackableListType;
103  typedef HashMap<CallbackableType, callbackableListType*, CallbackableTypeHash> callbackableMapType;
104  /**
105  * This hashmap holds every list of Callbackables for each CallbackableType.
106  */
107  callbackableMapType callbackableMap;
108 };
109 
110 #endif /* __BACKCALLER_H_ */
Interface class for a class which wants to be callback on a certain action.
Definition: callbackable.h:39
virtual void addCallbackable(Callbackable *callbackableInstance, CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
Adds a Callbackable instance to this caller instance.
Definition: backcaller.cpp:43
virtual void callBack(CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
Calls all registered callbackable classes of the determined type.
Definition: backcaller.cpp:86
static const CallbackableType DEFAULT_CALLBACKABLE_TYPE
This is the default Callbackable type.
Definition: backcaller.h:51
unsigned long CallbackableType
Definition: backcaller.h:45
virtual void removeCallbackable(Callbackable *callbackableInstance, CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
Removes a Callbackable instance from this caller instance.
Definition: backcaller.cpp:61
virtual void removeAllCallbackables(CallbackableType type)
Removes all Callbackable instances from this caller instance.
Definition: backcaller.cpp:74
virtual void callBackQMP(CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
Calls all registered callbackable classes of the determined type.
Definition: backcaller.cpp:101
BackCaller()
Definition: backcaller.cpp:31
Class prototype which provides functions to handle callbackable classes.
Definition: backcaller.h:42
virtual ~BackCaller()
Definition: backcaller.cpp:33