- Timestamp:
- Apr 8, 2008, 1:51:25 AM (17 years ago)
- Location:
- code/branches/core2/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/OrxonoxStableHeaders.h
r871 r1001 83 83 84 84 #include "util/Math.h" 85 #include "util/Convert.h"86 85 #include "util/Sleep.h" 87 86 #include "util/String2Number.h" -
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r994 r1001 297 297 } 298 298 299 boolCommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)299 Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 300 300 { 301 301 CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor; 302 302 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor; 303 return true;303 return (*executor); 304 304 } 305 305 -
code/branches/core2/src/orxonox/core/CommandExecutor.h
r994 r1001 139 139 static CommandEvaluation evaluate(const std::string& command); 140 140 141 static booladdConsoleCommandShortcut(ExecutorStatic* executor);141 static Executor& addConsoleCommandShortcut(ExecutorStatic* executor); 142 142 static ExecutorStatic* getConsoleCommandShortcut(const std::string& name); 143 143 static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name); -
code/branches/core2/src/orxonox/core/ConsoleCommand.h
r993 r1001 50 50 51 51 #define ConsoleCommandShortcutGeneric(fakevariable, executor) \ 52 boolfakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)52 Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor) 53 53 54 54 -
code/branches/core2/src/orxonox/core/Functor.h
r967 r1001 325 325 void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 326 326 { \ 327 std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl; \ 328 std::cout << param1 << std::endl; \ 329 std::cout << this->getTypenameParam(0) << std::endl; \ 327 330 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 331 std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl; \ 328 332 } \ 329 333 \ -
code/branches/core2/src/orxonox/objects/Tickable.cc
r871 r1001 1 1 #include "core/CoreIncludes.h" 2 #include "core/ConsoleCommand.h" 2 3 #include "Tickable.h" 3 4 4 5 namespace orxonox 5 6 { 7 ConsoleCommandShortcutExtern(slomo, AccessLevel::Offline).setDefaultValue(0, 1.0); 8 ConsoleCommandShortcutExtern(setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 9 10 static float timefactor = 1.0; 11 void slomo(float factor) 12 { 13 setTimeFactor(factor); 14 } 15 void setTimeFactor(float factor) 16 { 17 timefactor = factor; 18 } 19 float getTimeFactor() 20 { 21 return timefactor; 22 } 23 6 24 /** 7 25 @brief Constructor: Registers the object in the Tickable-list -
code/branches/core2/src/orxonox/objects/Tickable.h
r871 r1001 50 50 class TickFrameListener; // Forward declaration 51 51 52 void slomo(float factor); 53 void setTimeFactor(float factor = 1.0); 54 float getTimeFactor(); 55 52 56 //! The Tickable interface provides a tick(dt) function, that gets called every frame. 53 57 class _OrxonoxExport Tickable : virtual public OrxonoxClass … … 71 75 bool frameStarted(const Ogre::FrameEvent &evt) 72 76 { 77 float dt = evt.timeSinceLastFrame * getTimeFactor(); 73 78 // Iterate through all Tickables and call their tick(dt) function 74 79 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 75 (it++)->tick( evt.timeSinceLastFrame);80 (it++)->tick(dt); 76 81 77 82 return FrameListener::frameStarted(evt); -
code/branches/core2/src/orxonox/tools/Timer.h
r995 r1001 63 63 #include "OrxonoxPrereqs.h" 64 64 #include "core/CorePrereqs.h" 65 #include "../objects/Tickable.h" 65 66 66 67 namespace orxonox … … 200 201 bool frameStarted(const Ogre::FrameEvent &evt) 201 202 { 203 float dt = evt.timeSinceLastFrame * getTimeFactor(); 202 204 // Iterate through all Timers 203 205 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; ) … … 206 208 { 207 209 // If active: Decrease the timer by the duration of the last frame 208 it->time_ -= evt.timeSinceLastFrame;210 it->time_ -= dt; 209 211 210 212 if (it->time_ <= 0) -
code/branches/core2/src/util/Convert.h
r994 r1001 41 41 #include "MultiTypeMath.h" 42 42 43 // DEFAULT CLASS 44 template <typename FromType, typename ToType> 45 class Converter 46 { 47 public: 48 bool operator()(ToType* output, const FromType& input) const 49 { 50 return false; 51 } 52 }; 53 54 // PARTIAL SPECIALIZATION TO CONVERT TO STRINGS 55 template<typename FromType> 56 class Converter<FromType, std::string> 57 { 58 public: 59 bool operator()(std::string* output, const FromType& input) const 60 { 61 std::ostringstream oss; 62 if (oss << input) 63 { 43 44 ////////// 45 // Main // 46 ////////// 47 /* 48 enum ConversionPreference 49 { 50 CP_ToType, 51 CP_FromType 52 }; 53 54 // Helper classes to determine the preferred partial template specialization 55 class _AnyType_ {}; 56 class _ToType_ {} static __to__; 57 class _FromType_ {} static __from__; 58 class _Explicit_ {} static __explicit__; 59 60 61 // The default convert functions 62 template <class FromType, class ToType> 63 static bool convert(ToType* output, const FromType& input, _ToType_* type) 64 { std::cout << "default to" << std::endl; return false; } 65 template <class FromType, class ToType> 66 static bool convert(ToType* output, const FromType& input, _FromType_* type) 67 { std::cout << "default from" << std::endl; return false; } 68 template <class FromType, class ToType> 69 static bool convert(ToType* output, const FromType& input, _Explicit_* type) 70 { std::cout << "default explicit" << std::endl; return false; } 71 72 73 // The default convert function if both types are the same 74 template <class BothTypes> 75 static bool convert(BothTypes* output, const BothTypes& input, _Explicit_* type) 76 { (*output) = input; return true; } 77 78 79 // The default conversion of primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) 80 template <class FromType, class ToType, class Type> 81 static bool convertDefault(ToType* output, const FromType& input, Type* type) 82 { return false; } 83 #define CONVERT_PRIMITIVE_DEFAULT(primitive) \ 84 template <class FromType> static bool convertDefault(primitive* output, const FromType& input, _ToType_* type) { return convertDefault(output, input, &__from__); } \ 85 template <class ToType> static bool convertDefault(ToType* output, const primitive& input, _FromType_* type) { (*output) = (ToType)input; return true; } 86 CONVERT_PRIMITIVE_DEFAULT(int) 87 CONVERT_PRIMITIVE_DEFAULT(unsigned int) 88 CONVERT_PRIMITIVE_DEFAULT(char) 89 CONVERT_PRIMITIVE_DEFAULT(unsigned char) 90 CONVERT_PRIMITIVE_DEFAULT(short) 91 CONVERT_PRIMITIVE_DEFAULT(unsigned short) 92 CONVERT_PRIMITIVE_DEFAULT(long) 93 CONVERT_PRIMITIVE_DEFAULT(unsigned long) 94 CONVERT_PRIMITIVE_DEFAULT(float) 95 CONVERT_PRIMITIVE_DEFAULT(double) 96 CONVERT_PRIMITIVE_DEFAULT(long double) 97 CONVERT_PRIMITIVE_DEFAULT(bool) 98 99 // Calls all four possibilities of converting two values: (the order of 2 and 3 can be changed by setting bPreferToType to false) 100 // 1) explicit specialization 101 // 2) partial specialization for ToType 102 // 3) partial specialization of the FromType 103 // 4) default conversion if available 104 template<class FromType, class ToType> 105 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 106 { 107 std::cout << "1_1\n"; 108 if (convert(output, input, &__explicit__)) 109 return true; 110 111 std::cout << "1_2\n"; 112 if (preference == CP_ToType) 113 { 114 std::cout << "1_3\n"; 115 if (convert(output, input, &__to__)) 116 return true; 117 std::cout << "1_4\n"; 118 if (convert(output, input, &__from__)) 119 return true; 120 std::cout << "1_5\n"; 121 } 122 else 123 { 124 std::cout << "1_6\n"; 125 if (convert(output, input, &__from__)) 126 return true; 127 std::cout << "1_7\n"; 128 if (convert(output, input, &__to__)) 129 return true; 130 std::cout << "1_8\n"; 131 } 132 std::cout << "1_9\n"; 133 return convertDefault(output, input, &__to__); 134 } 135 */ 136 137 // Enum to declare the wanted conversion preference in case of equal type-levels 138 enum ConversionPreference 139 { 140 CP_ToType, 141 CP_FromType 142 }; 143 144 // Helper classes to determine the preferred partial template specialization 145 class _AnyType_ {}; 146 class _ToType_ {} static __to__; 147 class _FromType_ {} static __from__; 148 class _Explicit_ {} static __explicit__; 149 150 151 // The default convert functions 152 template <class FromType, class ToType> 153 static bool convert(ToType* output, const FromType& input, _ToType_* type) 154 { std::cout << "default to" << std::endl; return false; } 155 template <class FromType, class ToType> 156 static bool convert(ToType* output, const FromType& input, _FromType_* type) 157 { std::cout << "default from" << std::endl; return false; } 158 template <class FromType, class ToType> 159 static bool convert(ToType* output, const FromType& input, _Explicit_* type) 160 { std::cout << "default explicit" << std::endl; return false; } 161 162 163 // The default convert function if both types are the same 164 template <class BothTypes> 165 static bool convert(BothTypes* output, const BothTypes& input, _Explicit_* type) 166 { (*output) = input; return true; } 167 168 169 // The possible levels 170 #define __low__ 0 171 #define __mid__ 1 172 #define __high__ 2 173 174 // Defines the levels of all types 175 template <class T> struct ConverterLeveL { enum { level = __high__ }; }; 176 template <> struct ConverterLeveL<std::string> { enum { level = __mid__ }; }; 177 template <> struct ConverterLeveL<int> { enum { level = __low__ }; }; 178 template <> struct ConverterLeveL<unsigned int> { enum { level = __low__ }; }; 179 template <> struct ConverterLeveL<char> { enum { level = __low__ }; }; 180 template <> struct ConverterLeveL<unsigned char> { enum { level = __low__ }; }; 181 template <> struct ConverterLeveL<short> { enum { level = __low__ }; }; 182 template <> struct ConverterLeveL<unsigned short> { enum { level = __low__ }; }; 183 template <> struct ConverterLeveL<long> { enum { level = __low__ }; }; 184 template <> struct ConverterLeveL<unsigned long> { enum { level = __low__ }; }; 185 template <> struct ConverterLeveL<float> { enum { level = __low__ }; }; 186 template <> struct ConverterLeveL<double> { enum { level = __low__ }; }; 187 template <> struct ConverterLeveL<long double> { enum { level = __low__ }; }; 188 template <> struct ConverterLeveL<bool> { enum { level = __low__ }; }; 189 190 191 // Calculates the preference based on the levels of FromType and ToType 192 template <int from, int to> 193 struct ConverterPreference 194 { 195 enum 196 { 197 max = (from > to) ? from : to, 198 diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) 199 }; 200 }; 201 202 203 // The default conversion: This usually does nothing 204 template <int max, class FromType, class ToType, class Type> 205 struct ConverterDefault 206 { 207 static bool convert(ToType* output, const FromType& input, Type* type) 208 { 209 return false; 210 } 211 }; 212 // The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) template <int max, class FromType, class ToType> 213 template <class FromType, class ToType, class Type> 214 struct ConverterDefault<0, FromType, ToType, Type> 215 { 216 static bool convert(ToType* output, const FromType& input, Type* type) 217 { 218 (*output) = (ToType)input; 219 return true; 220 } 221 }; 222 223 224 // Converter: Converts input of FromType into output of ToType 225 template <int diff, int max, class FromType, class ToType> 226 struct Converter 227 { 228 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 229 { 230 return false; 231 } 232 }; 233 // Converter: FromType-level > ToType-level 234 template <int max, class FromType, class ToType> 235 struct Converter<-1, max, FromType, ToType> 236 { 237 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 238 { 239 if (convert(output, input, &__explicit__)) 240 return true; 241 if (convert(output, input, &__from__)) 242 return true; 243 if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__)) 244 return true; 245 246 return false; 247 } 248 }; 249 // Converter: ToType-level > FromType-level 250 template <int max, class FromType, class ToType> 251 struct Converter<1, max, FromType, ToType> 252 { 253 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 254 { 255 if (convert(output, input, &__explicit__)) 256 return true; 257 if (convert(output, input, &__to__)) 258 return true; 259 if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__)) 260 return true; 261 262 return false; 263 } 264 }; 265 // Converter: ToType-level = ToType-level 266 template <int max, class FromType, class ToType> 267 struct Converter<0, max, FromType, ToType> 268 { 269 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 270 { 271 if (convert(output, input, &__explicit__)) 272 return true; 273 274 if (preference == CP_ToType) 275 { 276 if (convert(output, input, &__to__)) 277 return true; 278 if (convert(output, input, &__from__)) 279 return true; 280 } 281 else 282 { 283 if (convert(output, input, &__from__)) 284 return true; 285 if (convert(output, input, &__to__)) 286 return true; 287 } 288 289 if (ConverterDefault<max, FromType, ToType, _ToType_>::convert(output, input, &__to__)) 290 return true; 291 292 return false; 293 } 294 }; 295 296 297 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference 298 template <class FromType, class ToType> 299 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 300 { 301 return Converter<ConverterPreference<ConverterLeveL<FromType>::level, ConverterLeveL<ToType>::level>::diff, ConverterPreference<ConverterLeveL<FromType>::level, ConverterLeveL<ToType>::level>::max, FromType, ToType>::convertValue(output, input, preference); 302 } 303 304 305 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful 306 template<class FromType, class ToType> 307 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_ToType) 308 { 309 return convertValue(output, input, preference); 310 } 311 template<class FromType, class ToType> 312 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType) 313 { 314 if (convertValue(output, input, preference)) 315 return true; 316 317 (*output) = fallback; 318 return false; 319 } 320 321 // Helper function: Calls convertValue with and without default value and returns the converted value 322 template<class FromType, class ToType> 323 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_ToType) 324 { 325 ToType output = ToType(); 326 ConvertValue(&output, input, preference); 327 return output; 328 } 329 template<class FromType, class ToType> 330 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_ToType) 331 { 332 ToType output = fallback; 333 ConvertValue(&output, input, fallback, preference); 334 return output; 335 } 336 337 ///////////////////// 338 // SPECIALISATIONS // 339 ///////////////////// 340 341 /* 342 template <class FromType> 343 static bool convertDefault(primitive* output, const FromType& input, _ToType_* type) 344 { 345 346 } 347 348 template <class ToType> 349 static bool convertDefault(ToType* output, const primitive& input, _FromType_* type) 350 { 351 352 } 353 354 355 template <> 356 static bool convertDefault(ToType* output, const FromType& input, _Explicit_* type) 357 { 358 359 } 360 */ 361 362 //////////// 363 // String // 364 //////////// 365 366 // convert to string 367 template <class FromType> 368 static bool convert(std::string* output, const FromType& input, _ToType_* type) 369 { 370 std::ostringstream oss; 371 if (oss << input) 372 { 64 373 (*output) = oss.str(); 65 374 return true; 66 67 375 } 376 else 68 377 return false; 69 } 70 }; 71 72 // PARTIAL SPECIALIZATION TO CONVERT FROM STRING 73 template<typename ToType> 74 class Converter<std::string, ToType> 75 { 76 public: 77 bool operator()(ToType* output, const std::string& input) const 78 { 79 std::istringstream iss(input); 80 if (iss >> (*output)) 81 return true; 82 else 378 } 379 380 // convert from string 381 template <class ToType> 382 static bool convert(ToType* output, const std::string& input, _FromType_* type) 383 { 384 std::istringstream iss(input); 385 if (iss >> (*output)) 386 return true; 387 else 83 388 return false; 84 } 85 }; 86 87 // FUNCTION SO WE DO NOT HAVE TO TELL THE COMPILER ABOUT THE TYPE 88 template<typename FromType, typename ToType> 89 static bool ConvertValue(ToType* output, const FromType& input) 90 { 91 Converter<FromType, ToType> converter; 92 return converter(output, input); 93 } 94 95 // THE SAME, BUT WITH DEFAULT VALUE 96 template<typename FromType, typename ToType> 97 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback) 98 { 99 Converter<FromType, ToType> converter; 100 if (converter(output, input)) 101 return true; 102 103 (*output) = fallback; 104 return false; 105 } 106 107 // THE SAME LIKE BEFORE, BUT NEEDS NO POINTER TO THE OUTPUT 108 template<typename FromType, typename ToType> 109 static ToType ConvertValueAndReturn(const FromType& input) 110 { 111 ToType output = ToType(); 112 ConvertValue(&output, input); 113 return output; 114 } 115 116 // THE SAME, BUT WITH DEFAULT VALUE 117 template<typename FromType, typename ToType> 118 static ToType ConvertValueAndReturn(const FromType& input, const ToType& fallback) 119 { 120 ToType output = fallback; 121 ConvertValue(&output, input, fallback); 122 return output; 123 } 124 125 ////////////////////////// 126 // MORE SPECIALISATIONS // 127 ////////////////////////// 128 129 // STRING TO STRING 130 template<> 131 class Converter<std::string, std::string> 132 { 133 public: 134 bool operator()(std::string* output, const std::string& input) const 135 { 136 (*output) = std::string(input); 137 return true; 138 } 139 }; 389 } 390 140 391 141 392 //////////////// … … 143 394 //////////////// 144 395 145 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEPRIMITIVE 146 template<typename ToType> 147 class Converter<MultiTypePrimitive, ToType> 148 { 149 public: 150 bool operator()(ToType* output, const MultiTypePrimitive& input) const 151 { 152 if (input.getType() == MT_void) 396 // convert from MultiTypePrimitive 397 template <class ToType> 398 static bool convert(ToType* output, const MultiTypePrimitive& input, _FromType_* type) 399 { 400 if (input.getType() == MT_void) 153 401 return ConvertValue(output, input.getVoid()); 154 402 else if (input.getType() == MT_int) 155 403 return ConvertValue(output, input.getInt()); 156 404 else if (input.getType() == MT_uint) 157 405 return ConvertValue(output, input.getUnsignedInt()); 158 406 else if (input.getType() == MT_char) 159 407 return ConvertValue(output, input.getChar()); 160 408 else if (input.getType() == MT_uchar) 161 409 return ConvertValue(output, input.getUnsignedChar()); 162 410 else if (input.getType() == MT_short) 163 411 return ConvertValue(output, input.getShort()); 164 412 else if (input.getType() == MT_ushort) 165 413 return ConvertValue(output, input.getUnsignedShort()); 166 414 else if (input.getType() == MT_long) 167 415 return ConvertValue(output, input.getLong()); 168 416 else if (input.getType() == MT_ulong) 169 417 return ConvertValue(output, input.getUnsignedLong()); 170 418 else if (input.getType() == MT_float) 171 419 return ConvertValue(output, input.getFloat()); 172 420 else if (input.getType() == MT_double) 173 421 return ConvertValue(output, input.getDouble()); 174 422 else if (input.getType() == MT_longdouble) 175 423 return ConvertValue(output, input.getLongDouble()); 176 424 else if (input.getType() == MT_bool) 177 425 return ConvertValue(output, input.getBool()); 178 426 else 179 427 return false; 180 } 181 }; 182 template<> 183 class Converter<MultiTypePrimitive, std::string> 184 { 185 public: 186 bool operator()(std::string* output, const MultiTypePrimitive& input) const 187 { 188 if (input.getType() == MT_void) 189 return ConvertValue(output, input.getVoid()); 190 else if (input.getType() == MT_int) 191 return ConvertValue(output, input.getInt()); 192 else if (input.getType() == MT_uint) 193 return ConvertValue(output, input.getUnsignedInt()); 194 else if (input.getType() == MT_char) 195 return ConvertValue(output, input.getChar()); 196 else if (input.getType() == MT_uchar) 197 return ConvertValue(output, input.getUnsignedChar()); 198 else if (input.getType() == MT_short) 199 return ConvertValue(output, input.getShort()); 200 else if (input.getType() == MT_ushort) 201 return ConvertValue(output, input.getUnsignedShort()); 202 else if (input.getType() == MT_long) 203 return ConvertValue(output, input.getLong()); 204 else if (input.getType() == MT_ulong) 205 return ConvertValue(output, input.getUnsignedLong()); 206 else if (input.getType() == MT_float) 207 return ConvertValue(output, input.getFloat()); 208 else if (input.getType() == MT_double) 209 return ConvertValue(output, input.getDouble()); 210 else if (input.getType() == MT_longdouble) 211 return ConvertValue(output, input.getLongDouble()); 212 else if (input.getType() == MT_bool) 213 return ConvertValue(output, input.getBool()); 214 else 215 return false; 216 } 217 }; 218 219 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPESTRING 220 template<typename ToType> 221 class Converter<MultiTypeString, ToType> 222 { 223 public: 224 bool operator()(ToType* output, const MultiTypeString& input) const 225 { 226 if (input.getType() == MT_constchar) 428 } 429 430 // convert from MultiTypeString 431 template <class ToType> 432 static bool convert(ToType* output, const MultiTypeString& input, _FromType_* type) 433 { 434 if (input.getType() == MT_constchar) 227 435 return ConvertValue(output, input.getConstChar()); 228 436 else if (input.getType() == MT_string) 229 437 return ConvertValue(output, input.getString()); 230 else if (input.getType() == MT_xmlelement) 231 return ConvertValue(output, input.getXMLElement()); 232 else 438 else 233 439 return ConvertValue(output, (MultiTypePrimitive)input); 234 } 235 }; 236 template<> 237 class Converter<MultiTypeString, std::string> 238 { 239 public: 240 bool operator()(std::string* output, const MultiTypeString& input) const 241 { 242 if (input.getType() == MT_constchar) 243 return ConvertValue(output, input.getConstChar()); 244 else if (input.getType() == MT_string) 245 return ConvertValue(output, input.getString()); 246 else if (input.getType() == MT_xmlelement) 247 return ConvertValue(output, input.getXMLElement()); 248 else 249 return ConvertValue(output, (MultiTypePrimitive)input); 250 } 251 }; 252 253 // PARTIAL SPECIALIZATION TO CONVERT FROM MULTITYPEMATH 254 template<typename ToType> 255 class Converter<MultiTypeMath, ToType> 256 { 257 public: 258 bool operator()(ToType* output, const MultiTypeMath& input) const 259 { 260 if (input.getType() == MT_vector2) 261 return ConvertValue(output, input.getVector2()); 262 else if (input.getType() == MT_vector3) 263 return ConvertValue(output, input.getVector3()); 264 else if (input.getType() == MT_quaternion) 265 return ConvertValue(output, input.getQuaternion()); 266 else if (input.getType() == MT_colourvalue) 267 return ConvertValue(output, input.getColourValue()); 268 else if (input.getType() == MT_radian) 440 } 441 442 // convert from MultiTypeMath 443 template <class ToType> 444 static bool convert(ToType* output, const MultiTypeMath& input, _FromType_* type) 445 { 446 if (input.getType() == MT_vector2) 447 return ConvertValue(output, input.getVector2(), CP_FromType); 448 else if (input.getType() == MT_vector3) 449 return ConvertValue(output, input.getVector3(), CP_FromType); 450 else if (input.getType() == MT_quaternion) 451 return ConvertValue(output, input.getQuaternion(), CP_FromType); 452 else if (input.getType() == MT_colourvalue) 453 return ConvertValue(output, input.getColourValue(), CP_FromType); 454 else if (input.getType() == MT_radian) 269 455 return ConvertValue(output, input.getRadian()); 270 456 else if (input.getType() == MT_degree) 271 457 return ConvertValue(output, input.getDegree()); 272 458 else 273 459 return ConvertValue(output, (MultiTypeString)input); 274 } 275 }; 276 template<> 277 class Converter<MultiTypeMath, std::string> 278 { 279 public: 280 bool operator()(std::string* output, const MultiTypeMath& input) const 281 { 282 if (input.getType() == MT_vector2) 283 return ConvertValue(output, input.getVector2()); 284 else if (input.getType() == MT_vector3) 285 return ConvertValue(output, input.getVector3()); 286 else if (input.getType() == MT_quaternion) 287 return ConvertValue(output, input.getQuaternion()); 288 else if (input.getType() == MT_colourvalue) 289 return ConvertValue(output, input.getColourValue()); 290 else if (input.getType() == MT_radian) 291 return ConvertValue(output, input.getRadian()); 292 else if (input.getType() == MT_degree) 293 return ConvertValue(output, input.getDegree()); 294 else 295 return ConvertValue(output, (MultiTypeString)input); 296 } 297 }; 460 } 298 461 299 462 … … 304 467 // Vector2 to std::string 305 468 template <> 469 static bool convert(std::string* output, const orxonox::Vector2& input, _Explicit_* type) 470 { 471 std::ostringstream ostream; 472 if (ostream << input.x << "," << input.y) 473 { 474 (*output) = ostream.str(); 475 return true; 476 } 477 return false; 478 } 479 480 /* 481 // Vector2 to std::string 482 template <> 306 483 class Converter<orxonox::Vector2, std::string> 307 484 { … … 319 496 } 320 497 }; 321 498 */ 499 // Vector3 to std::string 500 template <> 501 static bool convert(std::string* output, const orxonox::Vector3& input, _Explicit_* type) 502 { 503 std::ostringstream ostream; 504 if (ostream << input.x << "," << input.y << "," << input.z) 505 { 506 (*output) = ostream.str(); 507 return true; 508 } 509 return false; 510 } 511 512 /* 322 513 // Vector3 to std::string 323 514 template <> … … 337 528 } 338 529 }; 339 530 */ 531 // Vector4 to std::string 532 template <> 533 static bool convert(std::string* output, const orxonox::Vector4& input, _Explicit_* type) 534 { 535 std::ostringstream ostream; 536 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) 537 { 538 (*output) = ostream.str(); 539 return true; 540 } 541 return false; 542 } 543 /* 340 544 // Vector4 to std::string 341 545 template <> … … 355 559 } 356 560 }; 357 561 */ 562 // Quaternion to std::string 563 template <> 564 static bool convert(std::string* output, const orxonox::Quaternion& input, _Explicit_* type) 565 { 566 std::ostringstream ostream; 567 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) 568 { 569 (*output) = ostream.str(); 570 return true; 571 } 572 return false; 573 } 574 /* 358 575 // Quaternion to std::string 359 576 template <> … … 373 590 } 374 591 }; 375 592 */ 593 // ColourValue to std::string 594 template <> 595 static bool convert(std::string* output, const orxonox::ColourValue& input, _Explicit_* type) 596 { 597 std::ostringstream ostream; 598 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) 599 { 600 (*output) = ostream.str(); 601 return true; 602 } 603 return false; 604 } 605 /* 376 606 // ColourValue to std::string 377 607 template <> … … 391 621 } 392 622 }; 623 */ 393 624 394 625 … … 399 630 // std::string to Vector2 400 631 template <> 632 static bool convert(orxonox::Vector2* output, const std::string& input, _Explicit_* type) 633 { 634 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 635 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 636 637 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 638 if (tokens.size() >= 2) 639 { 640 if (!ConvertValue(&(output->x), tokens[0])) 641 return false; 642 if (!ConvertValue(&(output->y), tokens[1])) 643 return false; 644 645 return true; 646 } 647 return false; 648 } 649 /* 650 // std::string to Vector2 651 template <> 401 652 class Converter<std::string, orxonox::Vector2> 402 653 { … … 422 673 } 423 674 }; 424 675 */ 676 // std::string to Vector3 677 template <> 678 static bool convert(orxonox::Vector3* output, const std::string& input, _Explicit_* type) 679 { 680 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 681 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 682 683 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 684 if (tokens.size() >= 3) 685 { 686 if (!ConvertValue(&(output->x), tokens[0])) 687 return false; 688 if (!ConvertValue(&(output->y), tokens[1])) 689 return false; 690 if (!ConvertValue(&(output->z), tokens[2])) 691 return false; 692 693 return true; 694 } 695 return false; 696 } 697 /* 425 698 // std::string to Vector3 426 699 template <> … … 450 723 } 451 724 }; 452 725 */ 726 // std::string to Vector4 727 template <> 728 static bool convert(orxonox::Vector4* output, const std::string& input, _Explicit_* type) 729 { 730 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 731 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 732 733 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 734 if (tokens.size() >= 4) 735 { 736 if (!ConvertValue(&(output->x), tokens[0])) 737 return false; 738 if (!ConvertValue(&(output->y), tokens[1])) 739 return false; 740 if (!ConvertValue(&(output->z), tokens[2])) 741 return false; 742 if (!ConvertValue(&(output->w), tokens[3])) 743 return false; 744 745 return true; 746 } 747 return false; 748 } 749 /* 453 750 // std::string to Vector4 454 751 template <> … … 480 777 } 481 778 }; 482 779 */ 780 // std::string to Quaternion 781 template <> 782 static bool convert(orxonox::Quaternion* output, const std::string& input, _Explicit_* type) 783 { 784 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 785 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 786 787 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 788 if (tokens.size() >= 4) 789 { 790 if (!ConvertValue(&(output->w), tokens[0])) 791 return false; 792 if (!ConvertValue(&(output->x), tokens[1])) 793 return false; 794 if (!ConvertValue(&(output->y), tokens[2])) 795 return false; 796 if (!ConvertValue(&(output->z), tokens[3])) 797 return false; 798 799 return true; 800 } 801 return false; 802 } 803 /* 483 804 // std::string to Quaternion 484 805 template <> … … 510 831 } 511 832 }; 512 833 */ 834 // std::string to ColourValue 835 template <> 836 static bool convert(orxonox::ColourValue* output, const std::string& input, _Explicit_* type) 837 { 838 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 839 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 840 841 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 842 if (tokens.size() >= 4) 843 { 844 if (!ConvertValue(&(output->r), tokens[0])) 845 return false; 846 if (!ConvertValue(&(output->g), tokens[1])) 847 return false; 848 if (!ConvertValue(&(output->b), tokens[2])) 849 return false; 850 if (!ConvertValue(&(output->a), tokens[3])) 851 return false; 852 853 return true; 854 } 855 return false; 856 } 857 /* 513 858 // std::string to ColourValue 514 859 template <> … … 540 885 } 541 886 }; 887 */ 888 542 889 543 890 #endif /* _Convert_H__ */ -
code/branches/core2/src/util/MultiTypeMath.cc
r960 r1001 89 89 90 90 MultiTypeMath::operator void*() const 91 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this, 0); }91 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeMath, void*>(*this, 0); } 92 92 MultiTypeMath::operator int() const 93 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this, 0); }93 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeMath, int>(*this, 0); } 94 94 MultiTypeMath::operator unsigned int() const 95 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeMath, unsigned int>(*this, 0); }95 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeMath, unsigned int>(*this, 0); } 96 96 MultiTypeMath::operator char() const 97 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeMath, char>(*this, 0); }97 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeMath, char>(*this, 0); } 98 98 MultiTypeMath::operator unsigned char() const 99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeMath, unsigned char>(*this, 0); }99 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeMath, unsigned char>(*this, 0); } 100 100 MultiTypeMath::operator short() const 101 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeMath, short>(*this, 0); }101 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeMath, short>(*this, 0); } 102 102 MultiTypeMath::operator unsigned short() const 103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeMath, unsigned short>(*this, 0); }103 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeMath, unsigned short>(*this, 0); } 104 104 MultiTypeMath::operator long() const 105 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeMath, long>(*this, 0); }105 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeMath, long>(*this, 0); } 106 106 MultiTypeMath::operator unsigned long() const 107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeMath, unsigned long>(*this, 0); }107 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeMath, unsigned long>(*this, 0); } 108 108 MultiTypeMath::operator float() const 109 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeMath, float>(*this, 0); }109 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeMath, float>(*this, 0); } 110 110 MultiTypeMath::operator double() const 111 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeMath, double>(*this, 0); }111 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeMath, double>(*this, 0); } 112 112 MultiTypeMath::operator long double() const 113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeMath, long double>(*this, 0); }113 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeMath, long double>(*this, 0); } 114 114 MultiTypeMath::operator bool() const 115 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeMath, bool>(*this, 0); }115 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeMath, bool>(*this, 0); } 116 116 MultiTypeMath::operator std::string() const 117 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this); }117 { return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this); } 118 118 MultiTypeMath::operator const char*() const 119 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeMath, std::string>(*this)).c_str(); }119 { return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeMath, std::string>(*this)).c_str(); } 120 120 MultiTypeMath::operator orxonox::Vector2() const 121 { return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); } 122 MultiTypeMath::operator orxonox::Element() const 123 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Element>(*this); } 121 { return (this->type_ == MT_vector2) ? this->vector2_ : getConvertedValue<MultiTypeMath, orxonox::Vector2>(*this); } 124 122 MultiTypeMath::operator orxonox::Vector3() const 125 { return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); }123 { return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); } 126 124 MultiTypeMath::operator orxonox::Quaternion() const 127 { return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Quaternion>(*this); }125 { return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); } 128 126 MultiTypeMath::operator orxonox::ColourValue() const 129 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypeMath, orxonox::ColourValue>(*this); }127 { return (this->type_ == MT_colourvalue) ? this->colourvalue_ : getConvertedValue<MultiTypeMath, orxonox::ColourValue>(*this); } 130 128 MultiTypeMath::operator orxonox::Radian() const 131 { return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Radian>(*this); }129 { return (this->type_ == MT_radian) ? this->radian_ : getConvertedValue<MultiTypeMath, orxonox::Radian>(*this); } 132 130 MultiTypeMath::operator orxonox::Degree() const 133 { return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Degree>(*this); }131 { return (this->type_ == MT_degree) ? this->degree_ : getConvertedValue<MultiTypeMath, orxonox::Degree>(*this); } 134 132 135 133 void MultiTypeMath::setValue(const MultiTypeMath& mtm) … … 167 165 168 166 if (this->type_ == MT_vector2) 169 ConvertValue(&output, this->vector2_ );167 ConvertValue(&output, this->vector2_, CP_FromType); 170 168 else if (this->type_ == MT_vector3) 171 ConvertValue(&output, this->vector3_ );169 ConvertValue(&output, this->vector3_, CP_FromType); 172 170 else if (this->type_ == MT_colourvalue) 173 ConvertValue(&output, this->colourvalue_); 171 { std::cout << "3_1\n"; 172 ConvertValue(&output, this->colourvalue_, CP_FromType);} 174 173 else if (this->type_ == MT_quaternion) 175 ConvertValue(&output, this->quaternion_ );174 ConvertValue(&output, this->quaternion_, CP_FromType); 176 175 else if (this->type_ == MT_radian) 177 176 ConvertValue(&output, this->radian_); … … 187 186 { 188 187 if (this->type_ == MT_vector2) 189 return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0) );188 return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0), CP_FromType); 190 189 else if (this->type_ == MT_vector3) 191 return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0) );190 return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0), CP_FromType); 192 191 else if (this->type_ == MT_colourvalue) 193 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); 192 { std::cout << "4_1\n"; 193 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0), CP_FromType); } 194 194 else if (this->type_ == MT_quaternion) 195 return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0) );195 return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0), CP_FromType); 196 196 else if (this->type_ == MT_radian) 197 197 return ConvertValue(&this->radian_, value, orxonox::Radian(0)); -
code/branches/core2/src/util/MultiTypeMath.h
r947 r1001 54 54 inline MultiTypeMath(const char* value) : MultiTypeString(value) {} 55 55 inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {} 56 inline MultiTypeMath(const orxonox::Element& value) : MultiTypeString(value) {}57 56 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 58 57 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } … … 106 105 virtual operator std::string() const; 107 106 virtual operator const char*() const; 108 virtual operator orxonox::Element() const;109 107 virtual operator orxonox::Vector2() const; 110 108 virtual operator orxonox::Vector3() const; -
code/branches/core2/src/util/MultiTypePrimitive.cc
r960 r1001 135 135 136 136 MultiTypePrimitive::operator void*() const 137 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this, 0); }137 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); } 138 138 MultiTypePrimitive::operator int() const 139 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this, 0); }139 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypePrimitive, int>(*this, 0); } 140 140 MultiTypePrimitive::operator unsigned int() const 141 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this, 0); }141 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypePrimitive, unsigned int>(*this, 0); } 142 142 MultiTypePrimitive::operator char() const 143 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this, 0); }143 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypePrimitive, char>(*this, 0); } 144 144 MultiTypePrimitive::operator unsigned char() const 145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this, 0); }145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypePrimitive, unsigned char>(*this, 0); } 146 146 MultiTypePrimitive::operator short() const 147 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this, 0); }147 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypePrimitive, short>(*this, 0); } 148 148 MultiTypePrimitive::operator unsigned short() const 149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this, 0); }149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypePrimitive, unsigned short>(*this, 0); } 150 150 MultiTypePrimitive::operator long() const 151 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this, 0); }151 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypePrimitive, long>(*this, 0); } 152 152 MultiTypePrimitive::operator unsigned long() const 153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this, 0); }153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypePrimitive, unsigned long>(*this, 0); } 154 154 MultiTypePrimitive::operator float() const 155 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this, 0); }155 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypePrimitive, float>(*this, 0); } 156 156 MultiTypePrimitive::operator double() const 157 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this, 0); }157 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypePrimitive, double>(*this, 0); } 158 158 MultiTypePrimitive::operator long double() const 159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this, 0); }159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypePrimitive, long double>(*this, 0); } 160 160 MultiTypePrimitive::operator bool() const 161 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this, 0); }161 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypePrimitive, bool>(*this, 0); } 162 162 163 163 void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) -
code/branches/core2/src/util/MultiTypeString.cc
r960 r1001 43 43 else if (this->type_ == MT_string) 44 44 return (this->string_ == mts.string_); 45 else if (this->type_ == MT_xmlelement)46 return (&this->xmlelement_ == &mts.xmlelement_);47 45 } 48 46 … … 58 56 else if (this->type_ == MT_string) 59 57 return (this->string_ != mts.string_); 60 else if (this->type_ == MT_xmlelement)61 return (&this->xmlelement_ != &mts.xmlelement_);62 58 } 63 59 … … 66 62 67 63 MultiTypeString::operator void*() const 68 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this, 0); }64 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); } 69 65 MultiTypeString::operator int() const 70 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this, 0); }66 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeString, int>(*this, 0); } 71 67 MultiTypeString::operator unsigned int() const 72 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this, 0); }68 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeString, unsigned int>(*this, 0); } 73 69 MultiTypeString::operator char() const 74 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this, 0); }70 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeString, char>(*this, 0); } 75 71 MultiTypeString::operator unsigned char() const 76 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this, 0); }72 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeString, unsigned char>(*this, 0); } 77 73 MultiTypeString::operator short() const 78 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this, 0); }74 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeString, short>(*this, 0); } 79 75 MultiTypeString::operator unsigned short() const 80 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this, 0); }76 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeString, unsigned short>(*this, 0); } 81 77 MultiTypeString::operator long() const 82 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this, 0); }78 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeString, long>(*this, 0); } 83 79 MultiTypeString::operator unsigned long() const 84 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this, 0); }80 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeString, unsigned long>(*this, 0); } 85 81 MultiTypeString::operator float() const 86 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this, 0); }82 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeString, float>(*this, 0); } 87 83 MultiTypeString::operator double() const 88 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this, 0); }84 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeString, double>(*this, 0); } 89 85 MultiTypeString::operator long double() const 90 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this, 0); }86 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeString, long double>(*this, 0); } 91 87 MultiTypeString::operator bool() const 92 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this, 0); }88 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeString, bool>(*this, 0); } 93 89 MultiTypeString::operator std::string() const 94 { return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }90 { return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this); } 95 91 MultiTypeString::operator const char*() const 96 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); } 97 MultiTypeString::operator orxonox::Element() const 98 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeString, orxonox::Element>(*this); } 92 { return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this)).c_str(); } 99 93 100 94 void MultiTypeString::setValue(const MultiTypeString& mts) … … 110 104 else if (this->type_ == MT_string) 111 105 return "string"; 112 else if (this->type_ == MT_xmlelement)113 return "XML-element";114 106 else 115 107 return MultiTypePrimitive::getTypename(); … … 124 116 else if (this->type_ == MT_string) 125 117 return this->string_; 126 else if (this->type_ == MT_xmlelement)127 ConvertValue(&output, this->xmlelement_);128 118 else 129 119 return MultiTypePrimitive::toString(); … … 138 128 else if (this->type_ == MT_string) 139 129 this->string_ = value; 140 else if (this->type_ == MT_xmlelement)141 return ConvertValue(&this->xmlelement_, value, orxonox::Element());142 130 else 143 131 return MultiTypePrimitive::fromString(value); -
code/branches/core2/src/util/MultiTypeString.h
r947 r1001 33 33 #include <iostream> 34 34 #include "UtilPrereqs.h" 35 #include "XMLIncludes.h"36 #include "tinyxml/ticpp.h"37 35 38 36 #include "MultiTypePrimitive.h" … … 57 55 inline MultiTypeString(const char* value) { this->setValue(value); } 58 56 inline MultiTypeString(const std::string& value) { this->setValue(value); } 59 inline MultiTypeString(const orxonox::Element& value) { this->setValue(value); }60 57 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 61 58 virtual inline ~MultiTypeString() {} … … 64 61 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 65 62 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 66 inline MultiTypeString& operator=(const orxonox::Element& value) { this->setValue(value); return *this; }67 63 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 68 64 … … 70 66 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 71 67 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 72 inline bool operator==(const orxonox::Element& value) const { return (&this->xmlelement_ == &value); }73 68 bool operator==(const MultiTypeString& mts) const; 74 69 … … 76 71 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 77 72 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 78 inline bool operator!=(const orxonox::Element& value) const { return (&this->xmlelement_ != &value); }79 73 bool operator!=(const MultiTypeString& mts) const; 80 74 … … 94 88 virtual operator std::string() const; 95 89 virtual operator const char*() const; 96 virtual operator orxonox::Element() const;97 90 98 91 using MultiTypePrimitive::setValue; 99 92 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 100 93 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 101 inline void setValue(const orxonox::Element& value) { this->type_ = MT_xmlelement; this->xmlelement_ = value; }102 94 void setValue(const MultiTypeString& mts); 103 95 104 96 inline std::string getString() const { return this->string_; } 105 97 inline const char* getConstChar() const { return this->string_.c_str(); } 106 inline orxonox::Element getXMLElement() const { return this->xmlelement_; }107 98 108 99 inline std::string& getString() { return this->string_; } 109 100 inline const char* getConstChar() { return this->string_.c_str(); } 110 inline orxonox::Element& getXMLElement() { return this->xmlelement_; }111 101 112 102 using MultiTypePrimitive::getValue; 113 103 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 114 104 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 115 inline void getValue(orxonox::Element* variable) const { (*variable) = this->xmlelement_; }116 105 117 106 virtual std::string getTypename() const; … … 122 111 protected: 123 112 std::string string_; 124 orxonox::Element xmlelement_;125 113 }; 126 114 -
code/branches/core2/src/util/UtilPrereqs.h
r871 r1001 60 60 //----------------------------------------------------------------------- 61 61 class Convert; 62 template <typename FromType, typename ToType>63 class Converter;62 //template <typename FromType, typename ToType> 63 //class Converter; 64 64 class MultiTypePrimitive; 65 65 class MultiTypeString;
Note: See TracChangeset
for help on using the changeset viewer.