00001 /* Copyright (C) 2002 Dominic Letourneau (dominic.letourneau@usherbrooke.ca) 00002 00003 This library is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU Lesser General Public 00005 License as published by the Free Software Foundation; either 00006 version 2.1 of the License, or (at your option) any later version. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Lesser General Public License for more details. 00012 00013 You should have received a copy of the GNU Lesser General Public 00014 License along with this library; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 */ 00017 #ifndef _BEHAVIOR_H_ 00018 #define _BEHAVIOR_H_ 00019 00020 #include "BufferedNode.h" 00021 #include "Exploitation.h" 00022 //#include <vector> 00023 #include "Vector.h" 00024 #include <string> 00025 00026 00027 namespace RobotFlow { 00028 00029 //The Sub classes must always contain in the input/output overflow toolbox definitions : 00030 00031 /* 00032 * 00033 * @input_name ACTIVATED 00034 * @input_description No description available 00035 * 00036 * @output_name EXPLOITATION 00037 * @output_description No description available 00038 * 00039 */ 00040 00041 /** 00042 * 00043 * \brief Behavior base class, every behavior should derive from this class. 00044 * 00045 * This class offers basic functionnality that every behavior should have. This class takes care to 00046 * update the exploitation value and verifies if the Behavior is activated before 00047 * calling calculate_behavior method. Users should always provide the input/output/parameters overflow description 00048 * at the beginning of the class as usual Overflow nodes. Also, a Behavior should always register itself with the 00049 * REGISTER_BEHAVIOR(BehaviorClassName) macro. 00050 * 00051 * 00052 * \author Dominic Létourneau 00053 * \version $Revision: 1.7 $ 00054 * \date $Date: 2005/03/29 15:20:18 $ 00055 * \par History: 00056 * version $Revision: 1.7 $ 00057 * <ul> 00058 * <li>07/05/2003 Added doxygen documentation. 00059 * <li>07/05/2003 Fixed member variable names with m_ 00060 * </ul> 00061 */ 00062 class Behavior : public FD::BufferedNode { 00063 00064 public: 00065 00066 /** 00067 * Constructor, called from the overflow core modules. 00068 * 00069 * \param nodeName The name (alias) given to the node by the overflow core modules. 00070 * \param params Parameters passed to the node for its construction. 00071 * \param BehaviorName The behavior name should be the name of the class. 00072 * Every behavior should have a different name. 00073 */ 00074 Behavior(std::string nodeName, FD::ParameterSet params, std::string BehaviorName); 00075 00076 /** 00077 * This function is required by the BufferedNode class. That's the core 00078 * processing function called by the overflow engine. This function takes care to 00079 * update the exploitation value and verifies if the Behavior is activated before 00080 * calling calculate_behavior. 00081 * 00082 * \param output_id The output identification we are interested in. 00083 * \param count The iteration number we are calculating. 00084 * \param out The output buffer where th put the result. 00085 */ 00086 virtual void calculate(int output_id, int count, FD::Buffer &out); 00087 00088 /** 00089 * calculate_behavior is a pure virtual function. It should be implemented in 00090 * every derived class. Processing of the behaviors is done inside this function. 00091 * 00092 * \param output_id The output identification we are interested in. 00093 * \param count The iteration number we are calculating. 00094 * \param out The output buffer where th put the result. 00095 */ 00096 virtual void calculate_behavior(int output_id, int count, FD::Buffer &out) = 0; 00097 00098 /** 00099 * This function is called by the REGISTER_BEHAVIOR macro. It should not be called 00100 * from anything else. 00101 * 00102 * \param name The name of the behavior we want to register. 00103 * \retval int The identification number of the new behavior. 00104 */ 00105 static int register_behavior(const std::string &name); 00106 00107 /** 00108 * Translation of the behavior name into the behavior identification number. 00109 * 00110 * \param name The behavior name that we are looking for. 00111 * \retval int the behavior identification number. 00112 */ 00113 static int find_behavior(const std::string &name); 00114 00115 /** 00116 * Verifies if a behavior is registered. 00117 * 00118 * \param name The behavior name that we are looking for. 00119 * \retval bool Returns true if the behavior name is registered, else returns false. 00120 */ 00121 static bool behavior_exists(const std::string &name); 00122 00123 00124 /** 00125 * Returns the number of registered behaviors. 00126 * 00127 * \retval int The number of registered behaviors. 00128 */ 00129 static int get_behavior_size() {return get_behaviors().size();} 00130 00131 /** 00132 * Returns the data structure containing the registered behavior names. This function should not be used by derived classes. 00133 * 00134 * \retval std::vector<std::string>& The data structure containing the registered behavior names. 00135 */ 00136 static FD::Vector<std::string>& get_behaviors(); 00137 00138 /** 00139 * Remove the behavior 00140 * 00141 * \param name The behavior name that we want remove 00142 */ 00143 static void remove_behavior(const std::string &name); 00144 00145 /** 00146 * Get the behavior id 00147 * 00148 * \retval int The behavior id 00149 */ 00150 int get_behavior_id(); 00151 00152 protected: 00153 00154 /** activation vector or bool input */ 00155 int m_activationID; 00156 00157 /** exploitation output */ 00158 int m_exploitationID; 00159 00160 /** last exploitation output id */ 00161 int m_last_exploitation; 00162 00163 /** behavior identification number */ 00164 int m_behaviorID; 00165 00166 /** last exploitation value */ 00167 FD::ObjectRef m_exploitationValue; 00168 00169 }; 00170 00171 /** 00172 This macro is useful to automatically register a behavior when the dynamic library is opened. The static integer 00173 dummy_behavior_initializer_for_??? (??? = NodeTypeName = class name) is initialized by calling the Behavior::register_behavior function. 00174 If this macro is not called, behavior will be unknown by the system. 00175 */ 00176 #define REGISTER_BEHAVIOR(NodeTypeName) int dummy_behavior_initializer_for ## NodeTypeName = \ 00177 Behavior::register_behavior (# NodeTypeName); 00178 00179 00180 00181 }//namespace RobotFlow 00182 00183 #endif