Changeset 7197 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Mar 8, 2006, 2:02:58 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor.cc
r6645 r7197 31 31 // SHELL COMMAND BASE // 32 32 //////////////////////// 33 // empty constructor34 Executor::Executor()35 {36 this->defaultValue = NULL;37 }38 39 33 /** 40 34 * constructs and registers a new Command … … 43 37 * @param paramCount the count of parameters this command takes 44 38 */ 45 Executor::Executor(unsigned int paramCount, ...) 39 Executor::Executor(const MultiType& param0, 40 const MultiType& param1, 41 const MultiType& param2, 42 const MultiType& param3, 43 const MultiType& param4) 46 44 { 47 45 this->setClassID(CL_EXECUTOR, "Executor"); 48 46 49 if (paramCount > FUNCTOR_MAX_ARGUMENTS)50 paramCount = FUNCTOR_MAX_ARGUMENTS;51 // reading in Parameters.52 this->paramCount = paramCount;53 this->defaultValue = new MultiType[paramCount];54 47 55 va_list parameterList; 56 va_start(parameterList, paramCount); 48 // What Parameters have we got 49 this->defaultValue[0] = param0; 50 this->defaultValue[1] = param1; 51 this->defaultValue[2] = param2; 52 this->defaultValue[3] = param3; 53 this->defaultValue[4] = param4; 57 54 58 // What Parameters we have got 59 for (unsigned int i = 0; i < paramCount; i++) 55 for (unsigned int i = 0; i < FUNCTOR_MAX_ARGUMENTS; i++) 60 56 { 61 int type = va_arg(parameterList, int); 62 this->defaultValue[i].setType((MT_Type)type); 57 printf("%d ", i); 58 if (this->defaultValue[i] == MT_NULL) 59 { 60 this->paramCount = i; 61 break; 62 } 63 63 64 } 65 printf("%d\n", this->paramCount); 66 67 assert (paramCount <= FUNCTOR_MAX_ARGUMENTS); 64 68 } 65 69 … … 68 72 */ 69 73 Executor::~Executor() 70 { 71 delete[] this->defaultValue; 72 } 74 {} 73 75 74 76 /** … … 79 81 executor->functorType = this->functorType; 80 82 executor->paramCount = this->paramCount; 81 executor->defaultValue = new MultiType[this->paramCount];82 83 for (unsigned int i = 0; i < this->paramCount; i++) 83 {84 84 executor->defaultValue[i] = this->defaultValue[i]; 85 // printf("1: %s 2: %s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType()), MultiType::MultiTypeToString(executor->defaultValue[i].getType()));86 }87 85 } 88 86 … … 132 130 this->defaultValue[i].setInt(va_arg(values, int)); 133 131 break; 134 /* case MT_UINT:135 this->defaultValue[i].setInt((int)va_arg(values, unsigned int));136 break;*/132 /* case MT_UINT: 133 this->defaultValue[i].setInt((int)va_arg(values, unsigned int)); 134 break;*/ 137 135 case MT_FLOAT: 138 136 this->defaultValue[i].setFloat(va_arg(values, double)); 139 137 break; 140 /* case MT_LONG:141 this->defaultValue[i].setInt((int) va_arg(values, long));142 break;*/138 /* case MT_LONG: 139 this->defaultValue[i].setInt((int) va_arg(values, long)); 140 break;*/ 143 141 default: 144 142 break; … … 153 151 void Executor::debug() 154 152 { 155 /* tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator(); 156 ExecutorClass* elemCL = iteratorCL->firstElement(); 157 while(elemCL != NULL) 158 { 159 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 160 tIterator<Executor>* iterator = elemCL->commandList->getIterator(); 161 const Executor* elem = iterator->firstElement(); 162 while(elem != NULL) 153 /* tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator(); 154 ExecutorClass* elemCL = iteratorCL->firstElement(); 155 while(elemCL != NULL) 163 156 { 164 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 165 for (unsigned int i = 0; i< elem->paramCount; i++) 166 printf("%s ", Executor::paramToString(elem->parameters[i])); 167 if (elem->description != NULL) 168 printf("- %s", elem->description); 169 printf("\n"); 157 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 158 tIterator<Executor>* iterator = elemCL->commandList->getIterator(); 159 const Executor* elem = iterator->firstElement(); 160 while(elem != NULL) 161 { 162 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 163 for (unsigned int i = 0; i< elem->paramCount; i++) 164 printf("%s ", Executor::paramToString(elem->parameters[i])); 165 if (elem->description != NULL) 166 printf("- %s", elem->description); 167 printf("\n"); 170 168 171 elem = iterator->nextElement(); 169 elem = iterator->nextElement(); 170 } 171 delete iterator; 172 elemCL = iteratorCL->nextElement(); 172 173 } 173 delete iterator; 174 elemCL = iteratorCL->nextElement(); 175 } 176 delete iteratorCL;*/ 174 delete iteratorCL;*/ 177 175 } -
trunk/src/lib/util/executor/executor.h
r5691 r7197 1 1 /*! 2 2 * @file executor.h 3 * Definition of a on-screen-shell3 * Definition of an Executor 4 4 */ 5 5 … … 16 16 #include <stdarg.h> 17 17 18 // FORWARD DECLARATION19 template<class T> class tList;20 21 18 //! an enumerator for the definition of the Type. 22 19 typedef enum { … … 30 27 // BASE CLASS // 31 28 //////////////// 32 //! a baseClass for all possible Executors 29 //! a BaseClass for all possible Executors 30 /** 31 * An Executor is an Object, that is able to call Objects of Any type (class) 32 * and execute a function with given parameters on it. 33 * 34 * The Executor is able to handle: 35 * Objects of any Class (Templated) 36 * Default Values 37 * Functions with up to 5 parameters (more seems useless) 38 * Functions with many types (see functor_list.h) 39 */ 33 40 class Executor: public BaseObject 34 41 { … … 52 59 53 60 protected: 54 Executor(); 55 Executor(unsigned int paramCount, ...); 61 Executor(const MultiType& param0 = MT_NULL, 62 const MultiType& param1 = MT_NULL, 63 const MultiType& param2 = MT_NULL, 64 const MultiType& param3 = MT_NULL, 65 const MultiType& param4 = MT_NULL); 56 66 57 67 void cloning(Executor* executor) const; 58 59 // const SubString& getSubString(const char* string) const { return SubString(string); };60 68 61 69 protected: 62 70 long functorType; //!< The type of Function we've got (either static or objective). 63 71 unsigned int paramCount; //!< the count of parameters. 64 MultiType * defaultValue;//!< Default Values.72 MultiType defaultValue[5]; //!< Default Values. 65 73 }; 66 74 … … 132 140 #define ExecutorConstructor1(t1) \ 133 141 EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE)) \ 134 : Executor( 1,t1##_PARAM) \142 : Executor(t1##_PARAM) \ 135 143 { \ 136 144 this->functorType = EXECUTORTYPE; \ … … 141 149 #define ExecutorConstructor2(t1,t2) \ 142 150 EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \ 143 : Executor( 2,t1##_PARAM, t2##_PARAM) \151 : Executor(t1##_PARAM, t2##_PARAM) \ 144 152 { \ 145 153 this->functorType = EXECUTORTYPE; \ … … 150 158 #define ExecutorConstructor3(t1,t2,t3) \ 151 159 EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \ 152 : Executor( 3,t1##_PARAM, t2##_PARAM, t3##_PARAM) \160 : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM) \ 153 161 { \ 154 162 this->functorType = EXECUTORTYPE; \ … … 159 167 #define ExecutorConstructor4(t1,t2,t3,t4) \ 160 168 EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \ 161 : Executor( 4,t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \169 : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \ 162 170 { \ 163 171 this->functorType = EXECUTORTYPE; \ … … 168 176 #define ExecutorConstructor5(t1,t2,t3,t4,t5) \ 169 177 EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \ 170 : Executor( 5,t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \178 : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \ 171 179 { \ 172 180 this->functorType = EXECUTORTYPE; \ -
trunk/src/lib/util/executor/executor_specials.h
r5944 r7197 29 29 */ 30 30 ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char* paramName) 31 : Executor( 1,MT_EXT1)31 : Executor(MT_EXT1) 32 32 { 33 33 PRINTF(4)("Loading %s from XML-element %p\n", paramName, root); -
trunk/src/lib/util/multi_type.cc
r6859 r7197 33 33 * creates a multiType without any stored value at all. 34 34 */ 35 MultiType::MultiType() 36 { 37 this->init(); 35 MultiType::MultiType(MT_Type type) 36 { 37 this->init(); 38 this->type = type; 38 39 } 39 40 /** … … 274 275 else if (this->type & MT_FLOAT) return (this->value.Float == 0.0f)? false : true; 275 276 else if (this->type & MT_CHAR) return (this->value.Char == '\0')? false : true; 276 else if (this->type & MT_STRING ) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false; //! @TODO make this better.277 else if (this->type & MT_STRING && this->value.String != NULL) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false; //! @TODO make this better. 277 278 278 279 return false; … … 290 291 else if (this->type & MT_FLOAT) return (int) this->value.Float; 291 292 else if (this->type & MT_CHAR) return (int) this->value.Char; 292 else if (this->type & MT_STRING ) {293 else if (this->type & MT_STRING && this->value.String != NULL) { 293 294 char* endPtr = NULL; 294 295 int result = strtol(this->value.String, &endPtr, 10); … … 313 314 else if (this->type & MT_INT) return (float) this->value.Int; 314 315 else if (this->type & MT_CHAR) return (float) this->value.Char; 315 else if (this->type & MT_STRING ) {316 else if (this->type & MT_STRING && this->value.String != NULL) { 316 317 char* endPtr = NULL; 317 318 double result = strtod(this->value.String, &endPtr); … … 337 338 else if (this->type & MT_INT) return (int) this->value.Int; 338 339 else if (this->type & MT_FLOAT) return (char) this->value.Float; 339 else if (this->type & MT_STRING ) return *this->value.String;340 else if (this->type & MT_STRING && this->value.String != NULL) return *this->value.String; 340 341 341 342 return '\0'; -
trunk/src/lib/util/multi_type.h
r6645 r7197 32 32 class MultiType { 33 33 public: 34 MultiType( );34 MultiType(MT_Type type = MT_NULL); 35 35 MultiType(bool value); 36 36 MultiType(int value);
Note: See TracChangeset
for help on using the changeset viewer.