Fawkes API  Fawkes Development Version
skill_wrapper.h
00001 
00002 /***************************************************************************
00003  *  skill_wrapper.h - Wrap a skill as XABSL basic behavior
00004  *
00005  *  Created: Sun Aug 10 10:22:22 2008
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __PLUGINS_XABSL_SKILL_WRAPPER_H_
00024 #define __PLUGINS_XABSL_SKILL_WRAPPER_H_
00025 
00026 #include <XabslEngine/XabslBasicBehavior.h>
00027 
00028 #include <map>
00029 #include <list>
00030 #include <utility>
00031 #include <string>
00032 
00033 class XabslSkillWrapper : public xabsl::BasicBehavior
00034 {
00035  public:
00036   /** Parameter list.
00037    * Defines the parameters of a skill. It's a list of name/type pairs. The name
00038    * is the name of the parameter, the type is the value type.
00039    */
00040   typedef std::list<std::pair<std::string, std::string> > ParameterList;
00041 
00042   XabslSkillWrapper(const char *name, xabsl::ErrorHandler &error_handler,
00043                     ParameterList &params);
00044   ~XabslSkillWrapper();
00045 
00046   virtual void registerParameters();
00047   virtual void execute();
00048 
00049   const char * name();
00050 
00051   std::string skill_string();
00052 
00053  private:
00054   bool __execute;
00055 
00056   /// @cond INTERNALS
00057   class ParameterValueBase
00058   {
00059    public:
00060     virtual ~ParameterValueBase() {}
00061   };
00062 
00063   template <typename T>
00064     class ParameterValue : public ParameterValueBase
00065   {
00066    public:
00067     ParameterValue()
00068     {
00069       __value = 0;
00070     }
00071 
00072     T    get_value() const
00073     {
00074       return __value;
00075     }
00076 
00077     T *  get_value_ptr()
00078     {
00079       return &__value;
00080     }
00081 
00082     void set_value(T value)
00083     {
00084       __value = value;
00085     }
00086    private:
00087     T __value;
00088   };
00089   /// @endcond
00090 
00091   std::map<std::string, ParameterValueBase *> __param_values;
00092   ParameterList __params;
00093 };
00094 
00095 
00096 #endif