Changeset 9730 in orxonox.OLD for branches/new_class_id/src/lib/util
- Timestamp:
- Sep 15, 2006, 12:09:12 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/executor/executor.cc
r9728 r9730 61 61 break; 62 62 } 63 else 64 this->defaultValue[i].storeString(); 63 65 } 64 66 } … … 106 108 { 107 109 this->defaultValue[i].setValueOf(*value[i]); 110 this->defaultValue[i].storeString(); 108 111 } 109 112 } -
branches/new_class_id/src/lib/util/executor/executor.h
r9728 r9730 15 15 //! an enumerator for the definition of the Type. 16 16 typedef enum { 17 Executor_Objective = 1,18 Executor_Static = 2,17 Executor_Objective, 18 Executor_Static, 19 19 } Executor_Type; 20 20 … … 51 51 inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; }; 52 52 53 // EXECUTE54 /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */55 // virtual void operator()(BaseObject* object, int& count, void* values) const = 0;56 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */57 // virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;58 59 53 // RETRIEVE INFORMATION 60 54 /** @returns the Type of this Function (either static or objective) */ 61 inline long getType() const { return this->functorType; }; 55 inline Executor_Type getType() const { return this->functorType; }; 56 62 57 /** @returns the Count of Parameters this Executor takes */ 63 58 inline unsigned int getParamCount() const { return this->paramCount; }; … … 84 79 85 80 protected: 86 shortfunctorType; //!< The type of Function we've got (either static or objective).81 Executor_Type functorType; //!< The type of Function we've got (either static or objective). 87 82 unsigned int paramCount; //!< the count of parameters. 88 83 MultiType defaultValue[7]; //!< Default Values. 89 84 90 boolbRetVal; //!< True if the Executor has a return Value.85 const bool bRetVal; //!< True if the Executor has a return Value. 91 86 }; 92 87 -
branches/new_class_id/src/lib/util/executor/executor_functional.cc
r9728 r9730 15 15 16 16 #include "executor_functional.h" 17 std::string ExecutorFunctional_returningString_from[7];18 19 17 20 18 template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); }; … … 39 37 template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); }; 40 38 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); }; 41 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return ExecutorFunctional_returningString_from[i] = defaultValues[i].getString(); };39 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getStoredString(); }; 42 40 43 41 -
branches/new_class_id/src/lib/util/executor/executor_functional.h
r9728 r9730 51 51 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i); 52 52 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i); 53 54 55 /** 56 * @brief to remove writing errors, this function is Used. 57 * @param sub The SubString to use 58 * @param default The default Values. 59 */ 60 template<typename type, int index> type Evaluate(const SubString& sub, const MultiType* const defaults) 61 { 62 return (sub.size() > index) ? 63 fromString<type>(sub[index], getDefault<type>(defaults, index)) : 64 fromMulti<type>(defaults[index]); 65 }; 66 53 67 54 68 #endif /* __EXECUTOR_FUNCTIONAL_H_ */ … … 80 94 #endif 81 95 82 96 #ifdef __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED 83 97 #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS 84 98 #else … … 103 117 104 118 #ifndef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS 119 105 120 /////////// 106 121 //// 0 //// … … 177 192 { 178 193 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 179 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])));194 Evaluate<type0, 0>(sub, this->defaultValue)); 180 195 }; 181 196 … … 220 235 { 221 236 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 222 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),223 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])));237 Evaluate<type0, 0>(sub, this->defaultValue), 238 Evaluate<type1, 1>(sub, this->defaultValue)); 224 239 }; 225 240 … … 265 280 { 266 281 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 267 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),268 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),269 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])));282 Evaluate<type0, 0>(sub, this->defaultValue), 283 Evaluate<type1, 1>(sub, this->defaultValue), 284 Evaluate<type2, 2>(sub, this->defaultValue)); 270 285 }; 271 286 … … 312 327 { 313 328 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 314 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),315 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),316 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])),317 (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3])));329 Evaluate<type0, 0>(sub, this->defaultValue), 330 Evaluate<type1, 1>(sub, this->defaultValue), 331 Evaluate<type2, 2>(sub, this->defaultValue), 332 Evaluate<type3, 3>(sub, this->defaultValue)); 318 333 }; 319 334 … … 360 375 { 361 376 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 362 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),363 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),364 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])),365 (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3])),366 (sub.size() > 4) ? fromString<type4>(sub[4], getDefault<type4>(this->defaultValue, 4)) : (fromMulti<type4>(this->defaultValue[4])));377 Evaluate<type0, 0>(sub, this->defaultValue), 378 Evaluate<type1, 1>(sub, this->defaultValue), 379 Evaluate<type2, 2>(sub, this->defaultValue), 380 Evaluate<type3, 3>(sub, this->defaultValue), 381 Evaluate<type4, 4>(sub, this->defaultValue)); 367 382 }; 368 383 -
branches/new_class_id/src/lib/util/multi_type.cc
r9406 r9730 33 33 { 34 34 default: 35 36 35 this->value.Float = 0.0f; 36 break; 37 37 case MT_BOOL: 38 39 38 this->value.Bool = false; 39 break; 40 40 case MT_INT: 41 42 41 this->value.Int = 0; 42 break; 43 43 case MT_FLOAT: 44 45 44 this->value.Float = 0.0f; 45 break; 46 46 case MT_CHAR: 47 48 47 this->value.Char = '\0'; 48 break; 49 49 case MT_STRING: 50 51 50 this->storedString = ""; 51 break; 52 52 } 53 53 } … … 142 142 { 143 143 case MT_NULL: 144 144 return true; 145 145 case MT_BOOL: 146 146 return (this->value.Bool == mt.value.Bool); 147 147 case MT_INT: 148 148 return (this->value.Int == mt.value.Int); 149 149 case MT_CHAR: 150 150 return (this->value.Char == mt.value.Char); 151 151 case MT_FLOAT: 152 152 return (this->value.Float == mt.value.Float); 153 153 case MT_STRING: 154 154 return (this->storedString == mt.storedString); 155 155 default: 156 156 return false; 157 157 } 158 158 } … … 171 171 { 172 172 case MT_BOOL: 173 174 173 this->setBool(this->getBool()); 174 break; 175 175 case MT_INT: 176 177 176 this->setInt(this->getInt()); 177 break; 178 178 case MT_FLOAT: 179 180 179 this->setFloat(this->getFloat()); 180 break; 181 181 case MT_CHAR: 182 183 182 this->setChar(this->getChar()); 183 break; 184 184 case MT_STRING: 185 186 185 this->setString(this->getString()); 186 break; 187 187 default: 188 188 this->type = type; 189 189 } 190 190 } … … 257 257 } 258 258 259 /** 260 * @brief stores any value to the string. 261 * @note this Value can be grabbed by using the getStoredString function. 262 */ 263 void MultiType::storeString() 264 { 265 if (!(this->type & MT_STRING)) 266 this->storedString = this->getString(); 267 } 259 268 260 269 /************************** … … 381 390 * @brief returns a Constant string (actually this is slower than getString() 382 391 * @returns a constant string of the stored version's one. 383 * @note this could lead to a inconsistency of data 392 * @note this could lead to a inconsistency of data AND IS HIGHLY NON_THREAD_SAFE! 393 * PLEASE THINK ABOUT USING THE getStoredString function in conjunction with storeString(). 384 394 */ 385 395 const std::string& MultiType::getConstString() const 386 396 { 387 388 397 MultiType::constString = this->getString(); 389 398 return MultiType::constString; 390 399 } 391 400 401 /** 402 * @brief returns the currently stored string. 403 * @returns the Stored string. 404 * @note Storing a string works as follows: \\ 405 * MultiType a(3); // Creates a MultiType of Type int with value 3 \\ 406 * a.storeString(); // Stores the String in the internal structure. \\ 407 * std::string name = a.getStoredString(); 408 * 409 * This would be the same as 410 * name = a.getString(); 411 * but with much more const'ness. 412 */ 413 const std::string& MultiType::getStoredString() const 414 { 415 MultiType::constString = this->getString(); 416 return MultiType::constString; 417 } 392 418 393 419 /** … … 433 459 { 434 460 case MT_BOOL: 435 436 461 this->setBool(false); 462 break; 437 463 case MT_INT: 438 439 464 this->setInt(0); 465 break; 440 466 case MT_FLOAT: 441 442 467 this->setFloat(0.0f); 468 break; 443 469 case MT_CHAR: 444 445 470 this->setChar('\0'); 471 break; 446 472 case MT_STRING: 447 448 473 this->setString(""); 474 break; 449 475 default: 450 476 #ifdef DEBUG 451 477 PRINTF(2)("Unknown Type not reseting\n"); 452 478 #endif 453 479 break; 454 480 } 455 481 } … … 465 491 { 466 492 case MT_BOOL: 467 493 return MultiType::typeNames[1]; 468 494 case MT_INT: 469 495 return MultiType::typeNames[2]; 470 496 case MT_FLOAT: 471 497 return MultiType::typeNames[3]; 472 498 case MT_CHAR: 473 499 return MultiType::typeNames[4]; 474 500 case MT_STRING: 475 501 return MultiType::typeNames[5]; 476 502 default: 477 503 return MultiType::typeNames[0]; 478 504 } 479 505 } -
branches/new_class_id/src/lib/util/multi_type.h
r8035 r9730 79 79 inline MT_Type getType() const { return this->type; }; 80 80 81 void storeString(); 81 82 82 83 /* RETRIEVING FUNCTIONS */ … … 88 89 std::string getString() const; 89 90 const std::string& getConstString() const; 91 const std::string& getStoredString() const; 90 92 91 93 void reset();
Note: See TracChangeset
for help on using the changeset viewer.