- Timestamp:
- Nov 18, 2005, 6:08:36 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor.cc
r5632 r5633 47 47 if (paramCount > FUNCTOR_MAX_ARGUMENTS) 48 48 paramCount = FUNCTOR_MAX_ARGUMENTS; 49 // reading in Parameters. 49 50 this->paramCount = paramCount; 50 this->parameters = new unsigned int[paramCount];51 51 this->defaultValue = new MultiType[paramCount]; 52 52 … … 56 56 // What Parameters we have got 57 57 for (unsigned int i = 0; i < paramCount; i++) 58 this-> parameters[i] = va_arg(parameterList, int);58 this->defaultValue[i].setType(va_arg(parameterList, int)); 59 59 } 60 60 … … 64 64 Executor::~Executor() 65 65 { 66 delete[] this->parameters;67 66 delete[] this->defaultValue; 68 67 } … … 106 105 for (unsigned int i = 0; i < count; i++) 107 106 { 108 109 110 switch (this->parameters[i]) 107 switch (this->defaultValue[i].getType()) 111 108 { 112 case ParameterBool:109 case MT_BOOL: 113 110 this->defaultValue[i].setInt(va_arg(defaultList, int)); 114 111 break; 115 case ParameterChar:112 case MT_CHAR: 116 113 this->defaultValue[i].setChar((char)va_arg(defaultList, int)); 117 114 break; 118 case ParameterString:115 case MT_STRING: 119 116 this->defaultValue[i].setString(va_arg(defaultList, char*)); 120 117 break; 121 case ParameterInt:118 case MT_INT: 122 119 this->defaultValue[i].setInt(va_arg(defaultList, int)); 123 120 break; 124 case ParameterUInt:121 /* case MT_UINT: 125 122 this->defaultValue[i].setInt((int)va_arg(defaultList, unsigned int)); 126 break; 127 case ParameterFloat:123 break;*/ 124 case MT_FLOAT: 128 125 this->defaultValue[i].setFloat(va_arg(defaultList, double)); 129 126 break; 130 case ParameterLong:127 /* case MT_LONG: 131 128 this->defaultValue[i].setInt((int) va_arg(defaultList, long)); 132 break; 129 break;*/ 133 130 default: 134 131 break; -
trunk/src/lib/util/executor/executor.h
r5632 r5633 37 37 Executor* defaultValues(unsigned int count, ...); 38 38 39 /** @returns the CommandList of the Shell */ 40 static void unregisterCommand(const char* commandName, const char* className); 39 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 40 virtual void execute (BaseObject* object, const char* parameters) = 0; 41 41 42 42 43 static void debug(); … … 49 50 inline Executor_Type getType() { return this->functorType; }; 50 51 51 static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...);52 static const char* paramToString(long parameter);53 54 private:55 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */56 virtual void executeCommand (BaseObject* object, const char* parameters) = 0;57 58 52 protected: 59 53 Executor_Type functorType; //!< The type of Function we've got (either static or objective). 60 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )61 54 unsigned int paramCount; //!< the count of parameters. 62 unsigned int* parameters; //!< Parameters the function of this Command takes.63 55 MultiType* defaultValue; //!< Default Values. 64 56 … … 93 85 // EXECUTORINCLASS 94 86 // EXECUTORTYPE 95 //! registers a command without any parameters96 #define ExecutorRegister0() \97 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)()) \98 { \99 if (isRegistered(commandName, className, 0)== true) \100 return NULL; \101 return new EXECUTOR<T>(commandName, className, function); \102 }103 104 //! registers a command with 1 parameter105 #define ExecutorRegister1(t1) \106 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE)) \107 { \108 if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \109 return NULL; \110 return new EXECUTOR<T>(commandName, className, function); \111 }112 113 //! registers a command with 2 parameters114 #define ExecutorRegister2(t1,t2) \115 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \116 { \117 if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \118 return NULL; \119 return new EXECUTOR<T>(commandName, className, function); \120 }121 122 //! registers a command with 3 parameters123 #define ExecutorRegister3(t1,t2,t3) \124 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \125 { \126 if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \127 return NULL; \128 return new EXECUTOR<T>(commandName, className, function); \129 }130 131 //! registers a command with 4 parameters132 #define ExecutorRegister4(t1,t2,t3,t4) \133 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \134 { \135 if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \136 return NULL; \137 return new EXECUTOR<T>(commandName, className, function); \138 }139 140 //! registers a command with 5 parameters141 #define ExecutorRegister5(t1,t2,t3,t4,t5) \142 static EXECUTOR<T>* registerCommand(const char* commandName, const char* className, void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \143 { \144 if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \145 return NULL; \146 return new EXECUTOR<T>(commandName, className, function); \147 }148 87 149 88 /////////////////////// … … 238 177 //! execute-macro for functions with one parameter 239 178 #define ExecutorExecute1(t1) \ 240 else if (this->paramCount == 1 && this-> parameters[0]== t1##_PARAM) \179 else if (this->paramCount == 1 && this->defaultValue[0].getType() == t1##_PARAM) \ 241 180 EXECUTOREXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0))) 242 181 243 182 //! execute-macro for functions with two parameters 244 183 #define ExecutorExecute2(t1,t2) \ 245 else if (this->paramCount == 2 && this-> parameters[0] == t1##_PARAM && this->parameters[1]== t2##_PARAM) \184 else if (this->paramCount == 2 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM) \ 246 185 EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1))) 247 186 248 187 //! execute-macro for functions with three parameters 249 188 #define ExecutorExecute3(t1,t2,t3) \ 250 else if (this->paramCount == 3 && this-> parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2]== t3##_PARAM) \189 else if (this->paramCount == 3 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM) \ 251 190 EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2))) 252 191 253 192 //! execute-macro for functions with four parameters 254 193 #define ExecutorExecute4(t1,t2,t3,t4) \ 255 else if (this->paramCount == 4 && this-> parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3]== t4##_PARAM) \194 else if (this->paramCount == 4 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM && this->defaultValue[3].getType() == t4##_PARAM) \ 256 195 EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) 257 196 258 197 //! execute-macro for functions with five parameters 259 198 #define ExecutorExecute5(t1,t2,t3,t4,t5) \ 260 else if (this->paramCount == 5 && this-> parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4]== t5##_PARAM) \199 else if (this->paramCount == 5 && this->defaultValue[0].getType() == t1##_PARAM && this->defaultValue[1].getType() == t2##_PARAM && this->defaultValue[2].getType() == t3##_PARAM && this->defaultValue[3].getType() == t4##_PARAM && this->defaultValue[4].getType() == t5##_PARAM) \ 261 200 EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4))) 262 201 … … 268 207 // DYNAMIC FUNCTOR // 269 208 ///////////\///////// 209 #ifdef FUNCTOR_LIST 210 #undef FUNCTOR_LIST 211 #endif 212 #ifdef EXECUTOR 213 #undef EXECUTOR 214 #endif 215 #define EXECUTOR ExecutorObjective 216 #ifdef EXECUTOREXECUTER 217 #undef EXECUTOREXECUTER 218 #endif 219 #define EXECUTOREXECUTER(nameExt) (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt)) 220 #ifdef EXECUTORINCLASS 221 #undef EXECUTORINCLASS 222 #endif 223 #define EXECUTORINCLASS(FUNCTION) (T::FUNCTION) 224 #ifdef EXECUTORTYPE 225 #undef EXECUTORTYPE 226 #endif 227 #define EXECUTORTYPE Executor_Objective 270 228 //! keeps information about a Executor 271 229 template<class T> class ExecutorObjective : public Executor 272 230 { 231 273 232 public: 274 #ifdef FUNCTOR_LIST 275 #undef FUNCTOR_LIST 276 #endif 277 #ifdef EXECUTOR 278 #undef EXECUTOR 279 #endif 280 #define EXECUTOR ExecutorObjective 281 #ifdef EXECUTOREXECUTER 282 #undef EXECUTOREXECUTER 283 #endif 284 #define EXECUTOREXECUTER(nameExt) (dynamic_cast<T*>(object)->*(fp.functionPointer##nameExt)) 285 #ifdef EXECUTORINCLASS 286 #undef EXECUTORINCLASS 287 #endif 288 #define EXECUTORINCLASS(FUNCTION) (T::FUNCTION) 289 #ifdef EXECUTORTYPE 290 #undef EXECUTORTYPE 291 #endif 292 #define EXECUTORTYPE Executor_Objective 293 //! FUNCTOR_LIST is the List of command-registerers 294 #define FUNCTOR_LIST(x) ExecutorRegister ## x 295 #include "functor_list.h" 296 #undef FUNCTOR_LIST 297 233 //! FUNCTOR_LIST is the List of CommandConstructors 234 #define FUNCTOR_LIST(x) ExecutorConstructor ## x 235 #include "functor_list.h" 236 #undef FUNCTOR_LIST 298 237 299 238 private: … … 305 244 } fp; 306 245 307 //! FUNCTOR_LIST is the List of CommandConstructors 308 #define FUNCTOR_LIST(x) ExecutorConstructor ## x 309 #include "functor_list.h" 310 #undef FUNCTOR_LIST 311 312 virtual void executeCommand (BaseObject* object, const char* parameters) 246 virtual void execute (BaseObject* object, const char* parameters) 313 247 { 314 248 SubString sub(parameters, true); … … 321 255 322 256 323 324 257 //////////////////// 325 258 // STATIC FUNCTOR // 326 259 //////////////////// 260 #ifdef FUNCTOR_LIST 261 #undef FUNCTOR_LIST 262 #endif 263 #ifdef EXECUTOR 264 #undef EXECUTOR 265 #endif 266 #define EXECUTOR ExecutorStatic 267 #ifdef EXECUTOREXECUTER 268 #undef EXECUTOREXECUTER 269 #endif 270 #define EXECUTOREXECUTER(nameExt) fp.functionPointer##nameExt 271 #ifdef EXECUTORINCLASS 272 #undef EXECUTORINCLASS 273 #endif 274 #define EXECUTORINCLASS(FUNCTION) (FUNCTION) 275 #ifdef EXECUTORTYPE 276 #undef EXECUTORTYPE 277 #endif 278 #define EXECUTORTYPE Executor_Static 279 327 280 //! keeps information about a Executor, that points to a Static Function 328 281 template<class T> class ExecutorStatic : public Executor 329 282 { 330 283 public: 331 #ifdef FUNCTOR_LIST 332 #undef FUNCTOR_LIST 333 #endif 334 #ifdef EXECUTOR 335 #undef EXECUTOR 336 #endif 337 #define EXECUTOR ExecutorStatic 338 #ifdef EXECUTOREXECUTER 339 #undef EXECUTOREXECUTER 340 #endif 341 #define EXECUTOREXECUTER(nameExt) fp.functionPointer##nameExt 342 #ifdef EXECUTORINCLASS 343 #undef EXECUTORINCLASS 344 #endif 345 #define EXECUTORINCLASS(FUNCTION) (FUNCTION) 346 #ifdef EXECUTORTYPE 347 #undef EXECUTORTYPE 348 #endif 349 #define EXECUTORTYPE Executor_Static 350 351 //! FUNCTOR_LIST is the List of command-registerers 352 #define FUNCTOR_LIST(x) ExecutorRegister ## x 284 //! FUNCTOR_LIST is the List of CommandConstructors 285 #define FUNCTOR_LIST(x) ExecutorConstructor ## x 353 286 #include "functor_list.h" 354 287 #undef FUNCTOR_LIST … … 362 295 } fp; 363 296 364 //! FUNCTOR_LIST is the List of CommandConstructors365 #define FUNCTOR_LIST(x) ExecutorConstructor ## x366 #include "functor_list.h"367 #undef FUNCTOR_LIST368 297 369 298 virtual void executeCommand (BaseObject* object, const char* parameters) -
trunk/src/lib/util/multi_type.cc
r5552 r5633 120 120 121 121 122 void MultiType::setType(MT_Type) 123 { 122 void MultiType::setType(int type) 123 { 124 this->type = (MT_Type)type; 125 126 /// @todo check if this works... 124 127 125 128 } -
trunk/src/lib/util/multi_type.h
r5552 r5633 15 15 MT_BOOL = 1, //!< A bool Value. 16 16 MT_INT = 2, //!< An int Value. 17 MT_UINT = 2, 18 MT_LONG = 2, 17 19 MT_FLOAT = 4, //!< A float Value. 18 20 MT_CHAR = 8, //!< A single char. 19 21 MT_STRING = 16, //!< An entire String. 22 MT_EXT1 = 32, //!< An external Type. 23 MT_EXT2 = 64, //!< An external Type. 20 24 21 25 } MT_Type; … … 40 44 MultiType operator= (const MultiType& mt); 41 45 42 void setType( MT_Type);46 void setType(int type); 43 47 44 48 void setBool(bool value);
Note: See TracChangeset
for help on using the changeset viewer.