Robot Simulator of the Robotics Group for Self-Organization of Control: backcaller.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# backcaller.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *    guettler@informatik.uni-leipzig.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  *  DESCRIPTION                                                            *
    00025  *  Uses design pattern mediator:                                          *
    00026  *  BackCaller - subject and changemanager (combined)              *
    00027  *  Callbackable       - observer                                          *
    00028  *                                                                         *
    00029  *  $Log: backcaller.h,v $
    00030  *  Revision 1.1  2009/08/10 07:31:04  guettler
    00031  *  -new BackCaller class to provide common
    00032  *    functions used for callback
    00033  *  -Callbackable interface modified
    00034  *  -callBack now supports different types
    00035  *    of CallBackable types
    00036  *                                                                                 *
    00037  *                                                                         *
    00038  **************************************************************************/
    00039 #ifndef __BACKCALLER_H_
    00040 #define __BACKCALLER_H_
    00041
    00042 #include <vector>
    00043 #include <ext/hash_map>
    00044
    00045
    00046 class Callbackable;
    00047
    00048 /**
    00049  * Class prototype which provides functions to handle callbackable classes.
    00050  * If a class implements this class, just use the function callBack which
    00051  * calls all registered callbackable classes.
    00052  * If you use different callbackable pools, just use the overloaded functions
    00053  * callBack(CallbackableType type),
    00054  * addCallbackable(CallbackableType, Callbackable* cb) and
    00055  * removeCallbackable(CallbackableType, Callbackable* cb).
    00056  */
    00057 class BackCaller
    00058 {
    00059   public:
    00060     typedef unsigned long CallbackableType;
    00061
    00062     /**
    00063      * This is the default Callbackable type.
    00064      * If you derive from BackCaller, just define your own CallbackableTypes.
    00065      */
    00066     static const CallbackableType DEFAULT_CALLBACKABLE_TYPE = 0;
    00067
    00068     BackCaller();
    00069     virtual ~BackCaller();
    00070
    00071     /**
    00072      * Adds a Callbackable instance to this caller instance.
    00073      * @param type the desired CallbackableType of the Callbackable class.
    00074      * @param callbackableInstance the instance to add
    00075      */
    00076     virtual void addCallbackable(Callbackable* callbackableInstance, CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
    00077
    00078     /**
    00079      * Removes a Callbackable instance from this caller instance.
    00080      * @param type the CallbackableType of the Callbackable class.
    00081      * @param callbackableInstance
    00082      */
    00083     virtual void removeCallbackable(Callbackable* callbackableInstance, CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
    00084
    00085     /**
    00086      * Removes all Callbackable instances from this caller instance
    00087      * @param type the CallbackableType of the Callbackable class to be removed.
    00088      */
    00089     virtual void removeAllCallbackables(CallbackableType type /* = BackCaller::DEFAULT_CALLBACKABLE_TYPE */);
    00090
    00091
    00092     /**
    00093      * Calls all registered callbackable classes of the determined type.
    00094      * This is done by Callbackable::doOnCallback(CallbackableType type).
    00095      * You can make this function private/protected if you like.
    00096      * @param type the CallbackableType of the Callbackable classes.
    00097      */
    00098     virtual void callBack(CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
    00099
    00100     /**
    00101      * Calls all registered callbackable classes of the determined type.
    00102      * This is done by Callbackable::doOnCallback(CallbackableType type).
    00103      * This function uses QUICKMP in order to parallelise the callbacks.
    00104      * Remember that there is only shared the used CallbackableList. So if you
    00105      * have other variables/objects to share, implement your own version.
    00106      * You can make this function private/protected if you like.
    00107      * @param type the CallbackableType of the Callbackable classes.
    00108      */
    00109     virtual void callBackQMP(CallbackableType type = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
    00110
    00111   private:
    00112     struct CallbackableTypeHash
    00113     {
    00114       size_t operator() (const CallbackableType& type) const { return type; }
    00115     };
    00116
    00117     typedef std::vector<Callbackable*> callbackableListType;
    00118     typedef __gnu_cxx::hash_map<CallbackableType, callbackableListType*, CallbackableTypeHash> callbackableMapType;
    00119     /**
    00120      * This hashmap holds every list of Callbackables for each CallbackableType.
    00121      */
    00122     callbackableMapType callbackableMap;
    00123 };
    00124
    00125 #endif /* __BACKCALLER_H_ */