backcaller.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef __BACKCALLER_H_
00025 #define __BACKCALLER_H_
00026 
00027 #include <vector>
00028 #include <cstddef>
00029 #include "stl_map.h"
00030 
00031 class Callbackable;
00032 
00033 /**
00034  * Class prototype which provides functions to handle callbackable classes.
00035  * If a class implements this class, just use the function callBack which
00036  * calls all registered callbackable classes.
00037  * If you use different callbackable pools, just use the overloaded functions
00038  * callBack(CallbackableType type),
00039  * addCallbackable(CallbackableType, Callbackable* cb) and
00040  * removeCallbackable(CallbackableType, Callbackable* cb).
00041  */
00042 class BackCaller
00043 {
00044   public:
00045     typedef unsigned long CallbackableType;
00046 
00047     /**
00048      * This is the default Callbackable type.
00049      * If you derive from BackCaller, just define your own CallbackableTypes.
00050      */
00051     static const CallbackableType DEFAULT_CALLBACKABLE_TYPE = 0;
00052 
00053     BackCaller();
00054     virtual ~BackCaller();
00055 
00056     /**
00057      * Adds a Callbackable instance to this caller instance.
00058      * @param type the desired CallbackableType of the Callbackable class.
00059      * @param callbackableInstance the instance to add
00060      */
00061     virtual void addCallbackable(Callbackable* callbackableInstance, CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
00062 
00063     /**
00064      * Removes a Callbackable instance from this caller instance.
00065      * @param type the CallbackableType of the Callbackable class.
00066      * @param callbackableInstance
00067      */
00068     virtual void removeCallbackable(Callbackable* callbackableInstance, CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
00069 
00070     /**
00071      * Removes all Callbackable instances from this caller instance
00072      * @param type the CallbackableType of the Callbackable class to be removed.
00073      */
00074     virtual void removeAllCallbackables(CallbackableType type /* = BackCaller::DEFAULT_CALLBACKABLE_TYPE */);
00075 
00076 
00077     /**
00078      * Calls all registered callbackable classes of the determined type.
00079      * This is done by Callbackable::doOnCallback(CallbackableType type).
00080      * You can make this function private/protected if you like.
00081      * @param type the CallbackableType of the Callbackable classes.
00082      */
00083     virtual void callBack(CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
00084 
00085     /**
00086      * Calls all registered callbackable classes of the determined type.
00087      * This is done by Callbackable::doOnCallback(CallbackableType type).
00088      * This function uses QUICKMP in order to parallelise the callbacks.
00089      * Remember that there is only shared the used CallbackableList. So if you
00090      * have other variables/objects to share, implement your own version.
00091      * You can make this function private/protected if you like.
00092      * @param type the CallbackableType of the Callbackable classes.
00093      */
00094     virtual void callBackQMP(CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
00095 
00096   private:
00097     struct CallbackableTypeHash
00098     {
00099       size_t operator() (const CallbackableType& type) const { return type; }
00100     };
00101 
00102     typedef std::vector<Callbackable*> callbackableListType;
00103     typedef HashMap<CallbackableType, callbackableListType*, CallbackableTypeHash> callbackableMapType;
00104     /**
00105      * This hashmap holds every list of Callbackables for each CallbackableType.
00106      */
00107     callbackableMapType callbackableMap;
00108 };
00109 
00110 #endif /* __BACKCALLER_H_ */
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3