Changeset 9739 in orxonox.OLD for branches/new_class_id/src
- Timestamp:
- Sep 16, 2006, 12:52:02 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util/executor
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/executor/executor_const_member.h
r9738 r9739 19 19 20 20 21 #ifndef __EXECUTOR_ MEMBER_H_22 #define __EXECUTOR_ MEMBER_H_21 #ifndef __EXECUTOR_CONST_MEMBER_H_ 22 #define __EXECUTOR_CONST_MEMBER_H_ 23 23 24 24 /// Define all Constructs, that define an Executor. … … 49 49 #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE 50 50 51 #endif /* __EXECUTOR_ MEMBER_H_ */51 #endif /* __EXECUTOR_CONST_MEMBER_H_ */ -
branches/new_class_id/src/lib/util/executor/executor_static.h
r9738 r9739 19 19 20 20 21 #ifndef __EXECUTOR_ MEMBER_H_22 #define __EXECUTOR_ MEMBER_H_21 #ifndef __EXECUTOR_STATIC_H_ 22 #define __EXECUTOR_STATIC_H_ 23 23 24 24 /// Define all Constructs, that define an Executor. … … 49 49 #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE 50 50 51 #endif /* __EXECUTOR_ MEMBER_H_ */51 #endif /* __EXECUTOR_STATIC_H_ */ -
branches/new_class_id/src/lib/util/executor/functor_member.h
r9738 r9739 20 20 21 21 22 #ifndef __ EXECUTOR_FUNCTIONAL_H_23 #define __ EXECUTOR_FUNCTIONAL_H_22 #ifndef __FUNCTOR_MEMBER_H_ 23 #define __FUNCTOR_MEMBER_H_ 24 24 25 #include "executor .h"25 #include "executor_member.h" 26 26 #include "substring.h" 27 28 29 template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; };30 template<> bool fromString<bool>(const std::string& input, bool defaultValue);31 template<> int fromString<int>(const std::string& input, int defaultValue);32 template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue);33 template<> float fromString<float>(const std::string& input, float defaultValue);34 template<> char fromString<char>(const std::string& input, char defaultValue);35 template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue);36 37 template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ };38 template<> bool fromMulti<bool>(const MultiType& multi);39 template<> int fromMulti<int>(const MultiType& multi);40 template<> unsigned int fromMulti<unsigned int>(const MultiType& multi);41 template<> float fromMulti<float>(const MultiType& multi);42 template<> char fromMulti<char>(const MultiType& multi);43 template<> const std::string& fromMulti<const std::string&>(const MultiType& multi);44 45 46 template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };47 template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i);48 template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i);49 template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i);50 template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i);51 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i);52 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i);53 54 55 /**56 * @brief this is a Template Class used as an evaluater.57 *58 * Trait to determine a default Value for any Type,59 * and to define the Convertible, and how it is transformed into the60 * corresponding SubTypes over the operator().61 *62 * This Class must be reimplemented for each Convertible and all of its63 * conversion-members.64 *65 * e.g: Convertible SubSting, that splits up into many Stings66 * conversion-members: (int) can be transformed from a String.67 */68 template<typename FromType> class ExecutorEvaluater69 {70 public:71 /** @brief Executes the Evaluater72 * @param CallValue the Value that should be converted73 * @param defaults the default Values.74 */75 template <typename ToType, int index>76 ToType operator()(FromType& CallValue, const MultiType* const defaults)77 {78 return defaultValue; /*(CallValue.size() > index) ?79 fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :80 fromMulti<ToType>(defaults[index]); */81 }82 static FromType& defaultValue() { return FromType(); };83 };84 85 /**86 * @brief to remove writing errors, this function is Used.87 * @param sub The SubString to use88 * @param default The default Values.89 */90 template<> class ExecutorEvaluater <const SubString>91 {92 public:93 /** @brief Executes the Evaluater94 * @param CallValue the Value that should be converted95 * @param defaults the default Values.96 */97 template <typename ToType, int index>98 ToType operator()(const SubString& CallValue, const MultiType* const defaults)99 {100 return (CallValue.size() > index) ?101 fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :102 fromMulti<ToType>(defaults[index]);103 }104 static const SubString& defaultValue() { return SubString::NullSubString; };105 };106 107 108 109 110 #endif /* __EXECUTOR_FUNCTIONAL_H_ */111 112 //! if Functional is constant calling113 #define __EXECUTOR_FUNCTIONAL_CONST114 //! The Name to be attached to the functional (for normal, static, and const modes)115 #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params116 //! The Execution-mode (either static or objective)117 #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC dynamic_cast<T*>(object)->*(functionPointer)118 //! The Function-Pointer, and how to save it internally.119 #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER T::*functionPointer120 #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionMember121 122 #ifdef EXECUTOR_FUNCTIONAL_USE_CONST //! USING CONST FUNCTIONALS123 #ifdef __EXECUTOR_FUNCTIONAL_CONST_INCLUDED //!< CHECK IF ALREADY INCLUED CONST FUNCTIONALS124 #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS125 #else126 #define __EXECUTOR_FUNCTIONAL_CONST_INCLUDED127 #endif128 #undef __EXECUTOR_FUNCTIONAL_CONST129 #define __EXECUTOR_FUNCTIONAL_CONST const130 #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE131 #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionConstMember132 #undef __EXECUTOR_FUNCTIONAL_NAME133 #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_const134 //#endif /* EXECUTOR_FUNCTIONAL_USE_CONST */135 136 #elif defined EXECUTOR_FUNCTIONAL_USE_STATIC137 #ifdef EXECUTOR_FUNCTIONAL_USE_CONST138 #error you obviously do not know what you are doing !! ask the bensch139 #endif140 141 #ifdef __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED142 #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS143 #else144 #define __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED145 #endif146 147 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC148 #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC functionPointer149 #undef __EXECUTOR_FUNCTIONAL_NAME150 #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_static151 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER152 #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER *functionPointer153 #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE154 #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionStatic155 156 //#endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */157 #else158 #ifdef __EXECUTOR_FUNCTIONAL_PLAIN_INCLUDED159 #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS160 #else161 #define __EXECUTOR_FUNCTIONAL_PLAIN_INCLUDED162 #endif163 #endif164 165 #ifndef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS166 167 168 169 170 ///////////171 //// 0 ////172 ///////////173 //! @brief ExecutorClass, that can execute Functions without any parameters.174 template<class T, typename CallType, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>175 class __EXECUTOR_FUNCTIONAL_NAME(0) :public Executor<CallType, BaseClass>176 {177 private:178 /** @brief the FunctioPointer. */179 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST;180 181 public:182 /**183 * @brief constructs the Executor.184 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.185 */186 __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST )187 : Executor<CallType, BaseClass>(false, __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)188 {189 this->functionPointer = functionPointer;190 };191 192 /**193 * @brief executes the Functional194 * @param object the Object the action should be executed on.195 * @param sub the SubString to get the Parameters from.196 */197 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const198 {199 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();200 };201 202 /**203 * @brief copies the Executor204 * @returns a new Executor that's a copy of this one.205 */206 virtual Executor<CallType, BaseClass>* clone() const207 {208 return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, CallType>(this->functionPointer);209 };210 };211 212 213 214 215 216 ///////////217 //// 1 ////218 ///////////219 //! @brief ExecutorClass, that can execute Functions with one parameter.220 template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>221 class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType, BaseClass>222 {223 private:224 /** @brief the FunctioPointer. */225 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;226 227 public:228 /**229 * @brief constructs the Executor.230 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.231 */232 __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)233 : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)234 {235 this->functionPointer = functionPointer;236 };237 238 /**239 * @brief executes the Functional240 * @param object the Object the action should be executed on.241 * @param sub the SubString to get the Parameters from.242 */243 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const244 {245 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(246 Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue));247 };248 249 /**250 * @brief copies the Executor251 * @returns a new Executor that's a copy of this one.252 */253 virtual Executor<CallType, BaseClass>* clone() const254 {255 return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, CallType, type0>(this->functionPointer);256 };257 };258 259 260 261 262 263 ///////////264 //// 2 ////265 ///////////266 //! @brief ExecutorClass, that can execute Functions with two parameters.267 template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>268 class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType, BaseClass>269 {270 private:271 /** @brief the FunctioPointer. */272 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;273 274 public:275 /**276 * @brief constructs the Executor.277 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.278 */279 __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)280 : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)281 {282 this->functionPointer = functionPointer;283 };284 285 /**286 * @brief executes the Functional287 * @param object the Object the action should be executed on.288 * @param sub the SubString to get the Parameters from.289 */290 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const291 {292 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(293 Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),294 Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue));295 };296 297 /**298 * @brief copies the Executor299 * @returns a new Executor that's a copy of this one.300 */301 virtual Executor<CallType, BaseClass>* clone() const302 {303 return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, CallType, type0, type1>(this->functionPointer);304 };305 };306 307 308 309 310 311 ///////////312 //// 3 ////313 ///////////314 //! @brief ExecutorClass, that can execute Functions with three parameters.315 template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>316 class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType, BaseClass>317 {318 private:319 /** @brief the FunctioPointer. */320 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST;321 322 public:323 /**324 * @brief constructs the Executor.325 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.326 */327 __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)328 : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)329 {330 this->functionPointer = functionPointer;331 };332 333 /**334 * @brief executes the Functional335 * @param object the Object the action should be executed on.336 * @param sub the SubString to get the Parameters from.337 */338 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const339 {340 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(341 Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),342 Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),343 Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue));344 };345 346 /**347 * @brief copies the Executor348 * @returns a new Executor that's a copy of this one.349 */350 virtual Executor<CallType, BaseClass>* clone() const351 {352 return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, CallType, type0, type1, type2>(this->functionPointer);353 };354 };355 356 357 358 359 360 ///////////361 //// 4 ////362 ///////////363 //! @brief ExecutorClass, that can execute Functions with four parameters.364 template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>365 class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType, BaseClass>366 {367 private:368 /** @brief the FunctioPointer. */369 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST;370 371 public:372 /**373 * @brief constructs the Executor.374 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.375 */376 __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)377 : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)378 {379 this->functionPointer = functionPointer;380 };381 382 /**383 * @brief executes the Functional384 * @param object the Object the action should be executed on.385 * @param sub the SubString to get the Parameters from.386 */387 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const388 {389 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(390 Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),391 Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),392 Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue),393 Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue));394 };395 396 /**397 * @brief copies the Executor398 * @returns a new Executor that's a copy of this one.399 */400 virtual Executor<CallType, BaseClass>* clone() const401 {402 return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, CallType, type0, type1, type2, type3>(this->functionPointer);403 };404 };405 406 407 408 409 410 411 ///////////412 //// 5 ////413 ///////////414 //! @brief ExecutorClass, that can execute Functions with five parameters.415 template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>416 class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType, BaseClass>417 {418 private:419 /** @brief the FunctioPointer. */420 void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST;421 422 public:423 /**424 * @brief constructs the Executor.425 * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.426 */427 __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)428 : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)429 {430 this->functionPointer = functionPointer;431 };432 433 /**434 * @brief executes the Functional435 * @param object the Object the action should be executed on.436 * @param sub the SubString to get the Parameters from.437 */438 virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const439 {440 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(441 Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue),442 Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue),443 Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue),444 Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue),445 Evaluater<CallType>().template operator()<type4, 4>(sub, this->defaultValue));446 };447 448 /**449 * @brief copies the Executor450 * @returns a new Executor that's a copy of this one.451 */452 virtual Executor<CallType, BaseClass>* clone() const453 {454 return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer);455 };456 };457 458 459 460 461 462 463 464 465 27 466 28 // // // // // // // // // // // // // … … 536 98 } 537 99 538 539 100 /** 540 * Creates the FunctionCallers 101 * Creates the FunctionCallers imediately 541 102 */ 542 103 #define FUNCTOR_LIST(x) EXECUTOR_FUNCTIONAL_CREATOR ## x … … 545 106 546 107 547 548 #undef __EXECUTOR_FUNCTIONAL_CONST549 #undef __EXECUTOR_FUNCTIONAL_NAME550 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC551 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER552 #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE553 554 #ifdef EXECUTOR_FUNCTIONAL_USE_CONST555 #undef EXECUTOR_FUNCTIONAL_USE_CONST556 #endif557 #ifdef EXECUTOR_FUNCTIONAL_USE_STATIC558 #undef EXECUTOR_FUNCTIONAL_USE_STATIC559 #endif560 561 562 #endif /* __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS */563 108 #undef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS
Note: See TracChangeset
for help on using the changeset viewer.