Changeset 2087 for code/trunk/src/util
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 15 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/util
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/ceguilua/src/util merged eligible /code/branches/script_trigger/src/util merged eligible /code/branches/core3/src/util 1572-1739,1742-2014 /code/branches/gcc43/src/util 1580 /code/branches/gui/src/util 1635-1723 /code/branches/input/src/util 1629-1636
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/util/CMakeLists.txt
r1844 r2087 8 8 OutputBuffer.cc 9 9 OutputHandler.cc 10 SignalHandler.cc 10 11 String.cc 11 12 SubString.cc -
code/trunk/src/util/Convert.h
r1889 r2087 21 21 * 22 22 * Author: 23 * Reto Grieder 23 24 * Fabian 'x3n' Landau 24 25 * Benjamin Grauer … … 28 29 29 30 /*! 30 @file Convert.h31 @file 31 32 @brief Definition and Implementation of the Convert class. 32 33 */ 33 34 34 #ifndef _Convert _H__35 #define _Convert _H__35 #ifndef _Converter_H__ 36 #define _Converter_H__ 36 37 37 38 #include "UtilPrereqs.h" … … 39 40 #include <string> 40 41 #include <sstream> 42 #include <istream> 43 #include <ostream> 41 44 #include <typeinfo> 42 45 43 #include "Math.h"44 46 #include "Debug.h" 45 #include "SubString.h"46 47 #include "String.h" 47 48 48 // disable annoying warning about forcing value to boolean 49 // GCC generates warnings when implicitely casting from float to int for instance. 50 // This is however exactly what convertValue does, so we need to suppress these warnings. 51 // They only occur when using the ImplicitConversion template. 52 #if ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC 53 # pragma GCC system_header 54 #endif 55 56 57 /////////////////////////////////////////////// 58 // Static detection for conversion functions // 59 /////////////////////////////////////////////// 60 61 /* The idea to use the sizeof() operator on return functions to determine function existance 62 is described in 'Modern C++ design' by Alexandrescu (2001). */ 63 64 // disable warnings about possible loss of data 49 65 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 50 # pragma warning(push)51 # pragma warning(disable:4100 4800)66 # pragma warning(push) 67 # pragma warning(disable:4244) 52 68 #endif 53 69 54 55 ////////// 56 // MAIN // 57 ////////// 58 59 // Enum to declare the wanted conversion preference in case of equal type-levels 60 enum ConversionPreference 61 { 62 CP_PreferToType, 63 CP_PreferFromType, 64 }; 65 66 // Helper classes to determine the preferred partial template specialization 67 class _ToType_ {}; 68 class _FromType_ {}; 69 class _Explicit_ {}; 70 71 72 // The default convert functions 73 template <class FromType, class ToType, class Type> 74 struct ConverterSpecialized 75 { 76 enum { specialized = false }; 70 template <class FromType, class ToType> 71 class ImplicitConversion 72 { 73 private: 74 ImplicitConversion(); ImplicitConversion(const ImplicitConversion&); ~ImplicitConversion(); 75 // Gets chosen only if there is an implicit conversion from FromType to ToType. 76 static char test(ToType); 77 // Accepts any argument. Why do we not use a template? The reason is that with templates, 78 // the function above is only taken iff it is an exact type match. But since we want to 79 // check for implicit conversion, we have to use the ellipsis. 80 static long long test(...); 81 static FromType object; // helper object to handle private c'tor and d'tor 82 public: 83 // test(object) only has 'long long' return type iff the compiler doesn't choose test(...) 84 enum { exists = (sizeof(test(object)) == sizeof(char)) }; 85 }; 86 87 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 88 # pragma warning(pop) 89 #endif 90 91 92 //////////////////////////////////// 93 //// ACTUAL CONVERSION SEQUENCE //// 94 //////////////////////////////////// 95 /* 96 There is a distinct priority when choosing the right conversion function: 97 Overwrite: 98 1. (Partial) template specialisation of ConverterExplicit::convert() 99 Fallbacks: 100 2. Any possible implicit conversion. This includes 'FooBar' --> 'int' if FooBar defines operator float(). 101 3. Global or member operators for stringstream when converting from or to std::string (or FROM const char*) 102 4. (Partial) template specialisation of ConverterFallback::convert() 103 5. Function that simply displays "Could not convert value" with type information obtained from typeid(). 104 105 Notes: 106 There has to be an exact type match when using template specialisations. 107 Template specialisations can be defined after including this file. Any implicit cast function or iostream 108 operator has to be declared BEFORE this file gets parsed. 109 110 Defining your own functions: 111 There are obviously 4 ways to specifiy a user defined conversion. What should I use? 112 113 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from 114 'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities. 115 116 However if you want to overwrite an implicit conversion or an iostream operator, you really need to 117 make use of ConverterExplicit. 118 */ 119 120 namespace 121 { 122 //! Little template that maps integers to entire types (Alexandrescu 2001) 123 template <int I> 124 struct Int2Type { }; 125 } 126 127 128 /////////////////// 129 // No Conversion // 130 /////////////////// 131 132 // Default template. No conversion available at all. 133 template <class FromType, class ToType> 134 struct ConverterFallback 135 { 77 136 static bool convert(ToType* output, const FromType& input) 78 137 { 79 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 138 COUT(2) << "Could not convert value of type " << typeid(FromType).name() 139 << " to type " << typeid(ToType).name() << std::endl; 80 140 return false; 81 141 } 82 142 }; 83 143 84 85 // The default convert function if both types are the same 86 template <class BothTypes> 87 struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_> 88 { 89 enum { specialized = true }; 90 static bool convert(BothTypes* output, const BothTypes& input) 91 { (*output) = input; return true; } 92 }; 93 94 95 // The possible levels 96 #define __low__ 0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type) 97 #define __mid__ 1 // Everything that has overloaded << and >> operators to operate on a std::stream 98 #define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions 99 100 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type 101 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 102 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 103 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 104 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 105 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 106 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 107 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 108 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 109 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 110 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 111 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 112 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 113 template <> struct ConverterLevel<long long> { enum { level = __low__ }; }; 114 template <> struct ConverterLevel<unsigned long long> { enum { level = __low__ }; }; 115 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 116 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 117 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 118 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 119 120 121 // Calculates the preference based on the levels of FromType and ToType 122 template <int from, int to> 123 struct ConverterPreference 124 { 125 enum 126 { 127 // The maximum of both levels: element of {0, 1, 2} 128 // max 0: Both types are primitives or have a similar behaviour 129 // max 1: At least one type is not a primitive, but both can be put on a std::stream 130 // max 2: There is at least one generic type that needs specialized conversions 131 max = (from > to) ? from : to, 132 133 // The difference between both levels limited to +-1: element of {-1, 0, 1} 134 // diff -1: The FromType has higher level than the ToType 135 // diff 0: Both types have the same level 136 // diff 1: The ToType has higher level than the FromType 137 diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) 138 }; 139 }; 140 141 142 // The default conversion: This usually does nothing 143 template <int max, class FromType, class ToType> 144 struct ConverterDefault 144 // If all else fails, try a dynamic_cast for pointer types. 145 template <class FromType, class ToType> 146 struct ConverterFallback<FromType*, ToType*> 147 { 148 static bool convert(ToType** output, FromType* const input) 149 { 150 ToType* temp = dynamic_cast<ToType*>(input); 151 if (temp) 152 { 153 *output = temp; 154 return true; 155 } 156 else 157 return false; 158 } 159 }; 160 161 162 /////////////////////// 163 // ConverterFallback // 164 /////////////////////// 165 166 // Default template for stringstream 167 template <class FromType, class ToType> 168 struct ConverterStringStream 145 169 { 146 170 static bool convert(ToType* output, const FromType& input) 147 171 { 148 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 149 return false; 150 } 151 }; 152 // 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> 153 template <class FromType, class ToType> 154 struct ConverterDefault<0, FromType, ToType> 155 { 156 static bool convert(ToType* output, const FromType& input) 157 { 158 (*output) = (ToType)input; 159 return true; 160 } 161 }; 162 163 164 // Converter: Converts input of FromType into output of ToType 165 template <int diff, int max, class FromType, class ToType, ConversionPreference pref> 166 struct Converter 167 { 168 static bool convert(ToType* output, const FromType& input) 169 { 170 return false; 171 } 172 }; 173 // Converter: level{FromType} > level{ToType} 174 template <int max, class FromType, class ToType, ConversionPreference pref> 175 struct Converter<-1, max, FromType, ToType, pref> 176 { static bool convert(ToType* output, const FromType& input) 177 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 178 // Converter: level{FromType} < level{ToType} 179 template <int max, class FromType, class ToType, ConversionPreference pref> 180 struct Converter<1, max, FromType, ToType, pref> 181 { static bool convert(ToType* output, const FromType& input) 182 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 183 // Converter: level{FromType} = level{ToType} 184 // CP_PreferToType 185 template <int max, class FromType, class ToType> 186 struct Converter<0, max, FromType, ToType, CP_PreferToType> 187 { static bool convert(ToType* output, const FromType& input) 188 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 189 // CP_PreferFromType 190 template <int max, class FromType, class ToType> 191 struct Converter<0, max, FromType, ToType, CP_PreferFromType> 192 { static bool convert(ToType* output, const FromType& input) 193 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 194 195 196 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference 197 template <class FromType, class ToType> 198 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 199 { 200 return (preference == CP_PreferToType) ? 201 Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 202 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 203 FromType, 204 ToType, 205 CP_PreferToType>::convert(output, input) 206 : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 207 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 208 FromType, 209 ToType, 210 CP_PreferFromType>::convert(output, input); 211 } 212 213 214 ////////////////////// 215 // HELPER FUNCTIONS // 216 ////////////////////// 217 218 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful 219 template<class FromType, class ToType> 220 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 221 { 222 return convertValue(output, input, preference); 223 } 224 template<class FromType, class ToType> 225 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 226 { 227 if (convertValue(output, input, preference)) 228 return true; 229 230 (*output) = fallback; 231 return false; 232 } 233 234 // Helper function: Calls convertValue with and without default value and returns the converted value 235 template<class FromType, class ToType> 236 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType) 237 { 238 ToType output = ToType(); 239 ConvertValue(&output, input, preference); 240 return output; 241 } 242 template<class FromType, class ToType> 243 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 244 { 245 ToType output = fallback; 246 ConvertValue(&output, input, fallback, preference); 247 return output; 248 } 249 250 251 ///////////////////// 252 // SPECIALIZATIONS // 253 ///////////////////// 172 return ConverterFallback<FromType, ToType>::convert(output, input); 173 } 174 }; 175 254 176 255 177 ///////////// 256 // SAMPLES//178 // OStream // 257 179 ///////////// 258 /* 259 // convert everything to xyz 180 181 namespace fallbackTemplates 182 { 183 template <class FromType> 184 inline bool operator <<(std::ostream& outstream, const FromType& input) 185 { 186 std::string temp; 187 if (ConverterFallback<FromType, std::string>::convert(&temp, input)) 188 { 189 std::operator <<(outstream, temp); 190 return true; 191 } 192 else 193 return false; 194 } 195 } 196 197 // template that evaluates whether we can convert to std::string via ostringstream 260 198 template <class FromType> 261 struct ConverterSpecialized<FromType, xyz, _ToType_> 262 { 263 enum { specialized = true }; 264 static bool convert(xyz* output, const FromType& input) 265 { return ...; } 266 }; 267 268 // convert xyz to everything 269 template <class ToType> 270 struct ConverterSpecialized<xyz, ToType, _FromType_> 271 { 272 enum { specialized = true }; 273 static bool convert(ToType* output, const xyz& input) 274 { return ...; } 275 }; 276 277 // convert abc to xyz 278 template <> 279 struct ConverterSpecialized<abc, xyz, _Explicit_> 280 { 281 enum { specialized = true }; 282 static bool convert(xyz* output, const abc& input) 283 { return ...; } 284 }; 285 */ 286 287 //////////// 288 // STRING // 289 //////////// 290 291 // convert to string 292 template <class FromType> 293 struct ConverterSpecialized<FromType, std::string, _ToType_> 294 { 295 enum { specialized = true }; 199 struct ConverterStringStream<FromType, std::string> 200 { 296 201 static bool convert(std::string* output, const FromType& input) 297 202 { 203 using namespace fallbackTemplates; 204 // this operator call only chooses fallbackTemplates::operator<< if there's no other fitting function 298 205 std::ostringstream oss; 299 206 if (oss << input) … … 307 214 }; 308 215 216 217 ///////////// 218 // IStream // 219 ///////////// 220 221 namespace fallbackTemplates 222 { 223 template <class ToType> 224 inline bool operator >>(std::istream& instream, ToType& output) 225 { 226 return ConverterFallback<std::string, ToType> 227 ::convert(&output, static_cast<std::istringstream&>(instream).str()); 228 } 229 } 230 231 // template that evaluates whether we can convert from std::string via ostringstream 232 template <class ToType> 233 struct ConverterStringStream<std::string, ToType> 234 { 235 static bool convert(ToType* output, const std::string& input) 236 { 237 using namespace fallbackTemplates; 238 std::istringstream iss(input); 239 // this operator call only chooses fallbackTemplates::operator>> if there's no other fitting function 240 if (iss >> (*output)) 241 { 242 return true; 243 } 244 else 245 return false; 246 } 247 }; 248 249 250 /////////////////// 251 // Implicit Cast // 252 /////////////////// 253 254 // implicit cast not possible, try stringstream conversion next 255 template <class FromType, class ToType> 256 inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<false>) 257 { 258 return ConverterStringStream<FromType, ToType>::convert(output, input); 259 } 260 261 // We can cast implicitely 262 template <class FromType, class ToType> 263 inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<true>) 264 { 265 (*output) = static_cast<ToType>(input); 266 return true; 267 } 268 269 270 //////////////////////////////// 271 // ConverterExplicit Fallback // 272 //////////////////////////////// 273 274 // Default template if no specialisation is available 275 template <class FromType, class ToType> 276 struct ConverterExplicit 277 { 278 static bool convert(ToType* output, const FromType& input) 279 { 280 // Try implict cast and probe first. If a simple cast is not possible, it will not compile 281 // We therefore have to out source it into another template function 282 const bool probe = ImplicitConversion<FromType, ToType>::exists; 283 return convertImplicitely(output, input, ::Int2Type<probe>()); 284 } 285 }; 286 287 288 ////////////////////// 289 // Public Functions // 290 ////////////////////// 291 292 /** 293 @brief 294 Converts any value to any other as long as there exists a conversion. 295 Otherwise, the conversion will generate a runtime warning and return false. 296 For information about the different conversion methods (user defined too), see the section 297 'Actual conversion sequence' in this file above. 298 */ 299 template <class FromType, class ToType> 300 inline bool convertValue(ToType* output, const FromType& input) 301 { 302 return ConverterExplicit<FromType, ToType>::convert(output, input); 303 } 304 305 // For compatibility reasons. The same, but with capital ConvertValue 306 template<class FromType, class ToType> 307 inline bool ConvertValue(ToType* output, const FromType& input) 308 { 309 return convertValue(output, input); 310 } 311 312 // Calls convertValue and returns true if the conversion was successful. 313 // Otherwise the fallback is used. 314 /** 315 @brief 316 Converts any value to any other as long as there exists a conversion. 317 Otherwise, the conversion will generate a runtime warning and return false. 318 For information about the different conversion methods (user defined too), see the section 319 'Actual conversion sequence' in this file above. 320 If the conversion doesn't succeed, 'fallback' is written to '*output'. 321 @param fallback 322 A default value that gets written to '*output' if there is no conversion. 323 */ 324 template<class FromType, class ToType> 325 inline bool convertValue(ToType* output, const FromType& input, const ToType& fallback) 326 { 327 if (convertValue(output, input)) 328 return true; 329 else 330 { 331 (*output) = fallback; 332 return false; 333 } 334 } 335 336 // for compatibility reason. (capital 'c' in ConvertValue) 337 template<class FromType, class ToType> 338 inline bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback) 339 { 340 return convertValue(output, input, fallback); 341 } 342 343 // Directly returns the converted value, even if the conversion was not successful. 344 template<class FromType, class ToType> 345 inline ToType getConvertedValue(const FromType& input) 346 { 347 ToType output; 348 convertValue(&output, input); 349 return output; 350 } 351 352 // Directly returns the converted value, but uses the fallback on failure. 353 template<class FromType, class ToType> 354 inline ToType getConvertedValue(const FromType& input, const ToType& fallback) 355 { 356 ToType output; 357 convertValue(&output, input, fallback); 358 return output; 359 } 360 361 // Like getConvertedValue, but the template argument order is in reverse. 362 // That means you can call it exactly like static_cast<ToType>(fromTypeValue). 363 template<class ToType, class FromType> 364 inline ToType omni_cast(const FromType& input) 365 { 366 ToType output; 367 convertValue(&output, input); 368 return output; 369 } 370 309 371 // convert to string Shortcut 310 372 template <class FromType> 311 std::string convertToString(FromType value)373 inline std::string convertToString(FromType value) 312 374 { 313 375 return getConvertedValue<FromType, std::string>(value); 314 376 } 315 377 316 // convert from string 378 // convert from string Shortcut 317 379 template <class ToType> 318 struct ConverterSpecialized<std::string, ToType, _FromType_> 319 { 320 enum { specialized = true }; 321 static bool convert(ToType* output, const std::string& input) 322 { 380 inline ToType convertFromString(std::string str) 381 { 382 return getConvertedValue<std::string, ToType>(str); 383 } 384 385 //////////////////////////////// 386 // Special string conversions // 387 //////////////////////////////// 388 389 // Delegate conversion from const char* to std::string 390 template <class ToType> 391 struct ConverterExplicit<const char*, ToType> 392 { 393 static bool convert(ToType* output, const char* input) 394 { 395 return convertValue<std::string, ToType>(output, input); 396 } 397 }; 398 399 // These conversions would exhibit ambiguous << or >> operators when using stringstream 400 template <> 401 struct ConverterExplicit<char, std::string> 402 { 403 static bool convert(std::string* output, const char input) 404 { 405 *output = std::string(1, input); 406 return true; 407 } 408 }; 409 template <> 410 struct ConverterExplicit<unsigned char, std::string> 411 { 412 static bool convert(std::string* output, const unsigned char input) 413 { 414 *output = std::string(1, input); 415 return true; 416 } 417 }; 418 template <> 419 struct ConverterExplicit<std::string, char> 420 { 421 static bool convert(char* output, const std::string input) 422 { 423 if (input != "") 424 *output = input[0]; 425 else 426 *output = '\0'; 427 return true; 428 } 429 }; 430 template <> 431 struct ConverterExplicit<std::string, unsigned char> 432 { 433 static bool convert(unsigned char* output, const std::string input) 434 { 435 if (input != "") 436 *output = input[0]; 437 else 438 *output = '\0'; 439 return true; 440 } 441 }; 442 443 444 // bool to std::string 445 template <> 446 struct ConverterExplicit<bool, std::string> 447 { 448 static bool convert(std::string* output, const bool& input) 449 { 450 if (input) 451 *output = "true"; 452 else 453 *output = "false"; 454 return false; 455 } 456 }; 457 458 // std::string to bool 459 template <> 460 struct ConverterExplicit<std::string, bool> 461 { 462 static bool convert(bool* output, const std::string& input) 463 { 464 std::string stripped = getLowercase(removeTrailingWhitespaces(input)); 465 if (stripped == "true" || stripped == "on" || stripped == "yes") 466 { 467 *output = true; 468 return true; 469 } 470 else if (stripped == "false" || stripped == "off" || stripped == "no") 471 { 472 *output = false; 473 return true; 474 } 475 323 476 std::istringstream iss(input); 324 477 if (iss >> (*output)) … … 329 482 }; 330 483 331 // convert from string Shortcut332 template <class ToType>333 ToType convertFromString(std::string str)334 {335 return getConvertedValue<std::string, ToType>(str);336 }337 338 339 //////////340 // MATH //341 //////////342 // convert everything to Degree343 template <class FromType>344 struct ConverterSpecialized<FromType, Ogre::Degree, _ToType_>345 {346 enum { specialized = true };347 static bool convert(Ogre::Degree* output, const FromType& input)348 {349 float angle = 0;350 bool success = ConvertValue<FromType, float>(&angle, input);351 (*output) = angle;352 return success;353 }354 };355 356 // convert everything to Radian357 template <class FromType>358 struct ConverterSpecialized<FromType, Ogre::Radian, _ToType_>359 {360 enum { specialized = true };361 static bool convert(Ogre::Radian* output, const FromType& input)362 {363 float angle = 0;364 bool success = ConvertValue<FromType, float>(&angle, input);365 (*output) = angle;366 return success;367 }368 };369 370 371 ////////////////////372 // MATH TO STRING //373 ////////////////////374 375 // bool to std::string376 template <>377 struct ConverterSpecialized<bool, std::string, _Explicit_>378 {379 enum { specialized = true };380 static bool convert(std::string* output, const bool& input)381 {382 if (input)383 *output = "true";384 else385 *output = "false";386 return false;387 }388 };389 390 // Vector2 to std::string391 template <>392 struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>393 {394 enum { specialized = true };395 static bool convert(std::string* output, const orxonox::Vector2& input)396 {397 std::ostringstream ostream;398 if (ostream << input.x << "," << input.y)399 {400 (*output) = ostream.str();401 return true;402 }403 return false;404 }405 };406 407 // Vector3 to std::string408 template <>409 struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>410 {411 enum { specialized = true };412 static bool convert(std::string* output, const orxonox::Vector3& input)413 {414 std::ostringstream ostream;415 if (ostream << input.x << "," << input.y << "," << input.z)416 {417 (*output) = ostream.str();418 return true;419 }420 return false;421 }422 };423 424 // Vector4 to std::string425 template <>426 struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>427 {428 enum { specialized = true };429 static bool convert(std::string* output, const orxonox::Vector4& input)430 {431 std::ostringstream ostream;432 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)433 {434 (*output) = ostream.str();435 return true;436 }437 return false;438 }439 };440 441 // Quaternion to std::string442 template <>443 struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>444 {445 enum { specialized = true };446 static bool convert(std::string* output, const orxonox::Quaternion& input)447 {448 std::ostringstream ostream;449 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)450 {451 (*output) = ostream.str();452 return true;453 }454 return false;455 }456 };457 458 // ColourValue to std::string459 template <>460 struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>461 {462 enum { specialized = true };463 static bool convert(std::string* output, const orxonox::ColourValue& input)464 {465 std::ostringstream ostream;466 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)467 {468 (*output) = ostream.str();469 return true;470 }471 return false;472 }473 };474 475 476 ////////////////////477 // STRING TO MATH //478 ////////////////////479 480 // std::string to bool481 template <>482 struct ConverterSpecialized<std::string, bool, _Explicit_>483 {484 enum { specialized = true };485 static bool convert(bool* output, const std::string& input)486 {487 std::string stripped = getLowercase(removeTrailingWhitespaces(input));488 if (stripped == "true" || stripped == "on" || stripped == "yes")489 {490 *output = true;491 return true;492 }493 else if (stripped == "false" || stripped == "off" || stripped == "no")494 {495 *output = false;496 return true;497 }498 499 std::istringstream iss(input);500 if (iss >> (*output))501 return true;502 else503 return false;504 }505 };506 507 // std::string to Vector2508 template <>509 struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>510 {511 enum { specialized = true };512 static bool convert(orxonox::Vector2* output, const std::string& input)513 {514 size_t opening_parenthesis, closing_parenthesis = input.find(')');515 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }516 517 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');518 if (tokens.size() >= 2)519 {520 if (!ConvertValue(&(output->x), tokens[0]))521 return false;522 if (!ConvertValue(&(output->y), tokens[1]))523 return false;524 525 return true;526 }527 return false;528 }529 };530 531 // std::string to Vector3532 template <>533 struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>534 {535 enum { specialized = true };536 static bool convert(orxonox::Vector3* output, const std::string& input)537 {538 size_t opening_parenthesis, closing_parenthesis = input.find(')');539 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }540 541 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');542 if (tokens.size() >= 3)543 {544 if (!ConvertValue(&(output->x), tokens[0]))545 return false;546 if (!ConvertValue(&(output->y), tokens[1]))547 return false;548 if (!ConvertValue(&(output->z), tokens[2]))549 return false;550 551 return true;552 }553 return false;554 }555 };556 557 // std::string to Vector4558 template <>559 struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>560 {561 enum { specialized = true };562 static bool convert(orxonox::Vector4* output, const std::string& input)563 {564 size_t opening_parenthesis, closing_parenthesis = input.find(')');565 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }566 567 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');568 if (tokens.size() >= 4)569 {570 if (!ConvertValue(&(output->x), tokens[0]))571 return false;572 if (!ConvertValue(&(output->y), tokens[1]))573 return false;574 if (!ConvertValue(&(output->z), tokens[2]))575 return false;576 if (!ConvertValue(&(output->w), tokens[3]))577 return false;578 579 return true;580 }581 return false;582 }583 };584 585 // std::string to Quaternion586 template <>587 struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>588 {589 enum { specialized = true };590 static bool convert(orxonox::Quaternion* output, const std::string& input)591 {592 size_t opening_parenthesis, closing_parenthesis = input.find(')');593 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }594 595 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');596 if (tokens.size() >= 4)597 {598 if (!ConvertValue(&(output->w), tokens[0]))599 return false;600 if (!ConvertValue(&(output->x), tokens[1]))601 return false;602 if (!ConvertValue(&(output->y), tokens[2]))603 return false;604 if (!ConvertValue(&(output->z), tokens[3]))605 return false;606 607 return true;608 }609 return false;610 }611 };612 613 // std::string to ColourValue614 template <>615 struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>616 {617 enum { specialized = true };618 static bool convert(orxonox::ColourValue* output, const std::string& input)619 {620 size_t opening_parenthesis, closing_parenthesis = input.find(')');621 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }622 623 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');624 if (tokens.size() >= 3)625 {626 if (!ConvertValue(&(output->r), tokens[0]))627 return false;628 if (!ConvertValue(&(output->g), tokens[1]))629 return false;630 if (!ConvertValue(&(output->b), tokens[2]))631 return false;632 if (tokens.size() >= 4)633 {634 if (!ConvertValue(&(output->a), tokens[3]))635 return false;636 }637 else638 output->a = 1.0;639 640 return true;641 }642 return false;643 }644 };645 646 647 ///////////////////////////648 // Static type detection //649 ///////////////////////////650 651 /**652 Template class that determines whether type T converts implicitly to type U.653 @note654 This allows to detect type conversion at compile time.655 From 'Modern C++ Design' (Alexandrescu 2001).656 */657 template <class T, class U>658 class StaticConversion659 {660 class Small { char dummy[1]; };661 class Big { char dummy[1024]; };662 static Small Test(U);663 static Big Test(...);664 static T MakeT();665 public:666 enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };667 };668 669 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC670 #pragma warning(pop)671 #endif672 673 484 #endif /* _Convert_H__ */ -
code/trunk/src/util/Debug.h
r1791 r2087 77 77 } 78 78 79 namespace orxonox 80 { 81 using std::endl; 82 } 79 83 80 84 // DEFINE ERROR MODES -
code/trunk/src/util/Exception.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/util/Exception.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/util/Math.cc
r1791 r2087 28 28 29 29 /** 30 @file Math.cc30 @file 31 31 @brief Implementation of several math-functions. 32 32 */ 33 33 34 #include "Math.h" 35 34 36 #include <OgrePlane.h> 35 36 #include "Math.h" 37 #include "Convert.h" 37 #include "MathConvert.h" 38 #include "SubString.h" 38 39 39 40 /** … … 201 202 } 202 203 203 std::string getUniqueNumberStr() 204 { 205 return convertToString(getUniqueNumber()); 206 } 204 205 ////////////////////////// 206 // Conversion functions // 207 ////////////////////////// 208 209 // std::string to Vector2 210 bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input) 211 { 212 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 213 if ((opening_parenthesis = input.find('(')) == std::string::npos) 214 opening_parenthesis = 0; 215 else 216 opening_parenthesis++; 217 218 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 219 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 220 if (tokens.size() >= 2) 221 { 222 if (!ConvertValue(&(output->x), tokens[0])) 223 return false; 224 if (!ConvertValue(&(output->y), tokens[1])) 225 return false; 226 227 return true; 228 } 229 return false; 230 } 231 232 // std::string to Vector3 233 bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input) 234 { 235 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 236 if ((opening_parenthesis = input.find('(')) == std::string::npos) 237 opening_parenthesis = 0; 238 else 239 opening_parenthesis++; 240 241 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 242 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 243 if (tokens.size() >= 3) 244 { 245 if (!ConvertValue(&(output->x), tokens[0])) 246 return false; 247 if (!ConvertValue(&(output->y), tokens[1])) 248 return false; 249 if (!ConvertValue(&(output->z), tokens[2])) 250 return false; 251 252 return true; 253 } 254 return false; 255 } 256 257 // std::string to Vector4 258 bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input) 259 { 260 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 261 if ((opening_parenthesis = input.find('(')) == std::string::npos) 262 opening_parenthesis = 0; 263 else 264 opening_parenthesis++; 265 266 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 267 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 268 if (tokens.size() >= 4) 269 { 270 if (!ConvertValue(&(output->x), tokens[0])) 271 return false; 272 if (!ConvertValue(&(output->y), tokens[1])) 273 return false; 274 if (!ConvertValue(&(output->z), tokens[2])) 275 return false; 276 if (!ConvertValue(&(output->w), tokens[3])) 277 return false; 278 279 return true; 280 } 281 return false; 282 } 283 284 // std::string to Quaternion 285 bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input) 286 { 287 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 288 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 289 290 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 291 if (tokens.size() >= 4) 292 { 293 if (!ConvertValue(&(output->w), tokens[0])) 294 return false; 295 if (!ConvertValue(&(output->x), tokens[1])) 296 return false; 297 if (!ConvertValue(&(output->y), tokens[2])) 298 return false; 299 if (!ConvertValue(&(output->z), tokens[3])) 300 return false; 301 302 return true; 303 } 304 return false; 305 } 306 307 // std::string to ColourValue 308 bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input) 309 { 310 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 311 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 312 313 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 314 if (tokens.size() >= 3) 315 { 316 if (!ConvertValue(&(output->r), tokens[0])) 317 return false; 318 if (!ConvertValue(&(output->g), tokens[1])) 319 return false; 320 if (!ConvertValue(&(output->b), tokens[2])) 321 return false; 322 if (tokens.size() >= 4) 323 { 324 if (!ConvertValue(&(output->a), tokens[3])) 325 return false; 326 } 327 else 328 output->a = 1.0; 329 330 return true; 331 } 332 return false; 333 } -
code/trunk/src/util/Math.h
r1840 r2087 39 39 #include <ostream> 40 40 #include <string> 41 #include <boost/static_assert.hpp> 41 42 42 43 #include <OgreMath.h> … … 189 190 } 190 191 192 template <typename T> 193 inline T zeroise() 194 { 195 BOOST_STATIC_ASSERT(sizeof(T) == 0); 196 return T(); 197 } 198 199 template <> inline char zeroise<char>() { return 0; } 200 template <> inline unsigned char zeroise<unsigned char>() { return 0; } 201 template <> inline short zeroise<short>() { return 0; } 202 template <> inline unsigned short zeroise<unsigned short>() { return 0; } 203 template <> inline int zeroise<int>() { return 0; } 204 template <> inline unsigned int zeroise<unsigned int>() { return 0; } 205 template <> inline long zeroise<long>() { return 0; } 206 template <> inline unsigned long zeroise<unsigned long>() { return 0; } 207 template <> inline long long zeroise<long long>() { return 0; } 208 template <> inline unsigned long long zeroise<unsigned long long>() { return 0; } 209 template <> inline float zeroise<float>() { return 0; } 210 template <> inline double zeroise<double>() { return 0; } 211 template <> inline long double zeroise<long double>() { return 0; } 212 template <> inline bool zeroise<bool>() { return 0; } 213 template <> inline void* zeroise<void*>() { return 0; } 214 template <> inline std::string zeroise<std::string>() { return ""; } 215 template <> inline orxonox::Radian zeroise<orxonox::Radian>() { return orxonox::Radian(0.0f); } 216 template <> inline orxonox::Degree zeroise<orxonox::Degree>() { return orxonox::Degree(0.0f); } 217 template <> inline orxonox::Vector2 zeroise<orxonox::Vector2>() { return orxonox::Vector2 (0, 0) ; } 218 template <> inline orxonox::Vector3 zeroise<orxonox::Vector3>() { return orxonox::Vector3 (0, 0, 0) ; } 219 template <> inline orxonox::Vector4 zeroise<orxonox::Vector4>() { return orxonox::Vector4 (0, 0, 0, 0); } 220 template <> inline orxonox::ColourValue zeroise<orxonox::ColourValue>() { return orxonox::ColourValue(0, 0, 0, 0); } 221 template <> inline orxonox::Quaternion zeroise<orxonox::Quaternion>() { return orxonox::Quaternion (0, 0, 0, 0); } 222 191 223 /** 192 224 @brief Interpolates between two values for a time between 0 and 1. … … 243 275 244 276 _UtilExport unsigned long getUniqueNumber(); 245 _UtilExport std::string getUniqueNumberStr();246 277 247 278 class _UtilExport IntVector2 -
code/trunk/src/util/MultiType.cc
r1791 r2087 39 39 @param type The type 40 40 */ 41 voidMultiType::convert(MT_Type type)41 bool MultiType::convert(MT_Type type) 42 42 { 43 43 switch (type) 44 44 { 45 45 case MT_char: 46 this->convert<char>(); break;46 return this->convert<char>(); break; 47 47 case MT_uchar: 48 this->convert<unsigned char>(); break;48 return this->convert<unsigned char>(); break; 49 49 case MT_short: 50 this->convert<short>(); break;50 return this->convert<short>(); break; 51 51 case MT_ushort: 52 this->convert<unsigned short>(); break;52 return this->convert<unsigned short>(); break; 53 53 case MT_int: 54 this->convert<int>(); break;54 return this->convert<int>(); break; 55 55 case MT_uint: 56 this->convert<unsigned int>(); break;56 return this->convert<unsigned int>(); break; 57 57 case MT_long: 58 this->convert<long>(); break;58 return this->convert<long>(); break; 59 59 case MT_ulong: 60 this->convert<unsigned long>(); break;60 return this->convert<unsigned long>(); break; 61 61 case MT_longlong: 62 this->convert<long long>(); break;62 return this->convert<long long>(); break; 63 63 case MT_ulonglong: 64 this->convert<unsigned long long>(); break;64 return this->convert<unsigned long long>(); break; 65 65 case MT_float: 66 this->convert<float>(); break;66 return this->convert<float>(); break; 67 67 case MT_double: 68 this->convert<double>(); break;68 return this->convert<double>(); break; 69 69 case MT_longdouble: 70 this->convert<long double>(); break;70 return this->convert<long double>(); break; 71 71 case MT_bool: 72 this->convert<bool>(); break;72 return this->convert<bool>(); break; 73 73 case MT_void: 74 this->convert<void*>(); break;74 return this->convert<void*>(); break; 75 75 case MT_string: 76 this->convert<std::string>(); break;76 return this->convert<std::string>(); break; 77 77 case MT_vector2: 78 this->convert<orxonox::Vector2>(); break;78 return this->convert<orxonox::Vector2>(); break; 79 79 case MT_vector3: 80 this->convert<orxonox::Vector3>(); break;80 return this->convert<orxonox::Vector3>(); break; 81 81 case MT_vector4: 82 this->convert<orxonox::Vector4>(); break;82 return this->convert<orxonox::Vector4>(); break; 83 83 case MT_colourvalue: 84 this->convert<orxonox::ColourValue>(); break;84 return this->convert<orxonox::ColourValue>(); break; 85 85 case MT_quaternion: 86 this->convert<orxonox::Quaternion>(); break;86 return this->convert<orxonox::Quaternion>(); break; 87 87 case MT_radian: 88 this->convert<orxonox::Radian>(); break;88 return this->convert<orxonox::Radian>(); break; 89 89 case MT_degree: 90 this->convert<orxonox::Degree>(); break;90 return this->convert<orxonox::Degree>(); break; 91 91 default: 92 this->reset(); break;92 this->reset(); return false; break; 93 93 }; 94 94 } … … 168 168 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_double ) ? ((MT_Value<double> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 169 169 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_longdouble ) ? ((MT_Value<long double> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 170 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : false;} /** @brief Returns the current value, converted to the requested type. */171 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : (void*)0;} /** @brief Returns the current value, converted to the requested type. */172 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : std::string(); } /** @brief Returns the current value, converted to the requested type. */173 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector2(); } /** @brief Returns the current value, converted to the requested type. */174 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector3(); } /** @brief Returns the current value, converted to the requested type. */175 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector4(); } /** @brief Returns the current value, converted to the requested type. */176 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : orxonox::ColourValue(); } /** @brief Returns the current value, converted to the requested type. */177 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : orxonox::Quaternion(); } /** @brief Returns the current value, converted to the requested type. */178 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : orxonox::Radian(); } /** @brief Returns the current value, converted to the requested type. */179 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : orxonox::Degree(); } /** @brief Returns the current value, converted to the requested type. */170 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 171 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 172 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : zeroise<std::string>(); } /** @brief Returns the current value, converted to the requested type. */ 173 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector2>(); } /** @brief Returns the current value, converted to the requested type. */ 174 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector3>(); } /** @brief Returns the current value, converted to the requested type. */ 175 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector4>(); } /** @brief Returns the current value, converted to the requested type. */ 176 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::ColourValue>(); } /** @brief Returns the current value, converted to the requested type. */ 177 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Quaternion>(); } /** @brief Returns the current value, converted to the requested type. */ 178 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Radian>(); } /** @brief Returns the current value, converted to the requested type. */ 179 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Degree>(); } /** @brief Returns the current value, converted to the requested type. */ 180 180 181 181 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_char ); } /** @brief Creates a new value container for the given type. */ -
code/trunk/src/util/MultiType.h
r1854 r2087 58 58 a.convert<bool>(); // converts 3.14 to bool, which is true 59 59 a = false; // assigns false, this is equivalent to a.setValue(false) 60 61 @note 62 Whenever a value gets converted, there is a boolean return value telling you whether it was 63 successful or not. If it wasn't a zero value is assigned with the help of zeroise<T>(). 60 64 */ 61 65 … … 128 132 struct _UtilExport MT_ValueBase 129 133 { 130 MT_ValueBase(MT_Type type) : type_(type) {}134 MT_ValueBase(MT_Type type) : type_(type), bHasDefaultValue_(false) {} 131 135 virtual ~MT_ValueBase() {} 132 136 … … 134 138 135 139 virtual void reset() = 0; 136 virtual voidassimilate(const MultiType& other) = 0;140 virtual bool assimilate(const MultiType& other) = 0; 137 141 138 142 /** @brief Returns the type of the current value. */ 139 143 const MT_Type& getType() const { return this->type_; } 140 144 141 virtual void setValue(const char& value) = 0; 142 virtual void setValue(const unsigned char& value) = 0; 143 virtual void setValue(const short& value) = 0; 144 virtual void setValue(const unsigned short& value) = 0; 145 virtual void setValue(const int& value) = 0; 146 virtual void setValue(const unsigned int& value) = 0; 147 virtual void setValue(const long& value) = 0; 148 virtual void setValue(const unsigned long& value) = 0; 149 virtual void setValue(const long long& value) = 0; 150 virtual void setValue(const unsigned long long& value) = 0; 151 virtual void setValue(const float& value) = 0; 152 virtual void setValue(const double& value) = 0; 153 virtual void setValue(const long double& value) = 0; 154 virtual void setValue(const bool& value) = 0; 155 virtual void setValue( void* const& value) = 0; 156 virtual void setValue(const std::string& value) = 0; 157 virtual void setValue(const orxonox::Vector2& value) = 0; 158 virtual void setValue(const orxonox::Vector3& value) = 0; 159 virtual void setValue(const orxonox::Vector4& value) = 0; 160 virtual void setValue(const orxonox::ColourValue& value) = 0; 161 virtual void setValue(const orxonox::Quaternion& value) = 0; 162 virtual void setValue(const orxonox::Radian& value) = 0; 163 virtual void setValue(const orxonox::Degree& value) = 0; 145 /** @brief Checks whether the value is a default one. */ 146 bool hasDefaultValue() const { return this->bHasDefaultValue_; } 147 148 virtual bool setValue(const char& value) = 0; 149 virtual bool setValue(const unsigned char& value) = 0; 150 virtual bool setValue(const short& value) = 0; 151 virtual bool setValue(const unsigned short& value) = 0; 152 virtual bool setValue(const int& value) = 0; 153 virtual bool setValue(const unsigned int& value) = 0; 154 virtual bool setValue(const long& value) = 0; 155 virtual bool setValue(const unsigned long& value) = 0; 156 virtual bool setValue(const long long& value) = 0; 157 virtual bool setValue(const unsigned long long& value) = 0; 158 virtual bool setValue(const float& value) = 0; 159 virtual bool setValue(const double& value) = 0; 160 virtual bool setValue(const long double& value) = 0; 161 virtual bool setValue(const bool& value) = 0; 162 virtual bool setValue( void* const& value) = 0; 163 virtual bool setValue(const std::string& value) = 0; 164 virtual bool setValue(const orxonox::Vector2& value) = 0; 165 virtual bool setValue(const orxonox::Vector3& value) = 0; 166 virtual bool setValue(const orxonox::Vector4& value) = 0; 167 virtual bool setValue(const orxonox::ColourValue& value) = 0; 168 virtual bool setValue(const orxonox::Quaternion& value) = 0; 169 virtual bool setValue(const orxonox::Radian& value) = 0; 170 virtual bool setValue(const orxonox::Degree& value) = 0; 171 172 virtual bool getValue(char* value) const = 0; 173 virtual bool getValue(unsigned char* value) const = 0; 174 virtual bool getValue(short* value) const = 0; 175 virtual bool getValue(unsigned short* value) const = 0; 176 virtual bool getValue(int* value) const = 0; 177 virtual bool getValue(unsigned int* value) const = 0; 178 virtual bool getValue(long* value) const = 0; 179 virtual bool getValue(unsigned long* value) const = 0; 180 virtual bool getValue(long long* value) const = 0; 181 virtual bool getValue(unsigned long long* value) const = 0; 182 virtual bool getValue(float* value) const = 0; 183 virtual bool getValue(double* value) const = 0; 184 virtual bool getValue(long double* value) const = 0; 185 virtual bool getValue(bool* value) const = 0; 186 virtual bool getValue(void** value) const = 0; 187 virtual bool getValue(std::string* value) const = 0; 188 virtual bool getValue(orxonox::Vector2* value) const = 0; 189 virtual bool getValue(orxonox::Vector3* value) const = 0; 190 virtual bool getValue(orxonox::Vector4* value) const = 0; 191 virtual bool getValue(orxonox::ColourValue* value) const = 0; 192 virtual bool getValue(orxonox::Quaternion* value) const = 0; 193 virtual bool getValue(orxonox::Radian* value) const = 0; 194 virtual bool getValue(orxonox::Degree* value) const = 0; 164 195 165 196 virtual operator char() const = 0; … … 189 220 virtual void toString(std::ostream& outstream) const = 0; 190 221 191 MT_Type type_; //!< The type of the current value 222 MT_Type type_; //!< The type of the current value 223 bool bHasDefaultValue_; //!< True if the last conversion wasn't successful 192 224 }; 193 225 … … 229 261 inline const MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } /** @brief Resets the value and changes the type. */ 230 262 231 inline voidsetValue(const char& value);232 inline voidsetValue(const unsigned char& value);233 inline voidsetValue(const short& value);234 inline voidsetValue(const unsigned short& value);235 inline voidsetValue(const int& value);236 inline voidsetValue(const unsigned int& value);237 inline voidsetValue(const long& value);238 inline voidsetValue(const unsigned long& value);239 inline voidsetValue(const long long& value);240 inline voidsetValue(const unsigned long long& value);241 inline voidsetValue(const float& value);242 inline voidsetValue(const double& value);243 inline voidsetValue(const long double& value);244 inline voidsetValue(const bool& value);245 inline voidsetValue( void* const& value);246 inline voidsetValue(const std::string& value);247 inline voidsetValue(const orxonox::Vector2& value);248 inline voidsetValue(const orxonox::Vector3& value);249 inline voidsetValue(const orxonox::Vector4& value);250 inline voidsetValue(const orxonox::ColourValue& value);251 inline voidsetValue(const orxonox::Quaternion& value);252 inline voidsetValue(const orxonox::Radian& value);253 inline voidsetValue(const orxonox::Degree& value);254 inline voidsetValue(const char* value);263 inline bool setValue(const char& value); 264 inline bool setValue(const unsigned char& value); 265 inline bool setValue(const short& value); 266 inline bool setValue(const unsigned short& value); 267 inline bool setValue(const int& value); 268 inline bool setValue(const unsigned int& value); 269 inline bool setValue(const long& value); 270 inline bool setValue(const unsigned long& value); 271 inline bool setValue(const long long& value); 272 inline bool setValue(const unsigned long long& value); 273 inline bool setValue(const float& value); 274 inline bool setValue(const double& value); 275 inline bool setValue(const long double& value); 276 inline bool setValue(const bool& value); 277 inline bool setValue( void* const& value); 278 inline bool setValue(const std::string& value); 279 inline bool setValue(const orxonox::Vector2& value); 280 inline bool setValue(const orxonox::Vector3& value); 281 inline bool setValue(const orxonox::Vector4& value); 282 inline bool setValue(const orxonox::ColourValue& value); 283 inline bool setValue(const orxonox::Quaternion& value); 284 inline bool setValue(const orxonox::Radian& value); 285 inline bool setValue(const orxonox::Degree& value); 286 inline bool setValue(const char* value); 255 287 /** @brief Assigns a pointer. */ 256 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else {this->assignValue((void*)value); } }288 template <typename V> inline bool setValue(V* value) { if (this->value_) { return this->value_->setValue((void*)value); } else { return this->assignValue((void*)value); } } 257 289 /** @brief Assigns the value of the other MultiType and converts it to the current type. */ 258 void setValue(const MultiType& other) { if (this->value_) { this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); }} }290 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 259 291 /** @brief Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). */ 260 template <typename T, typename V> inline void setValue(const V& value) { this->setType<T>();this->setValue(value); }292 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); } 261 293 262 294 … … 264 296 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 265 297 266 template <typename T> inline void convert() {this->setValue<T>((T)(*this)); } /** @brief Converts the current value to type T. */267 inline void convert(const MultiType& other) {this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */268 voidconvert(MT_Type type);269 270 /** @brief Resets the value to the defaultvalue of the current type.*/271 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; }}298 template <typename T> inline bool convert() { return this->setValue<T>((T)(*this)); } /** @brief Converts the current value to type T. */ 299 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 300 bool convert(MT_Type type); 301 302 /** @brief Current content gets deleted. New type is MT_null */ 303 inline void reset() { if (this->value_) this->value_->reset(); } 272 304 273 305 template <typename T> inline void setType() { this->assignValue(T()); } /** @brief Resets the value and changes the internal type to T. */ … … 282 314 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 283 315 std::string getTypename() const; 316 317 /** @brief Checks whether the value is a default one. */ 318 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 284 319 285 320 operator char() const; … … 309 344 template <class T> operator T*() const { return ((T*)this->operator void*()); } 310 345 311 inline void getValue(char* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */312 inline void getValue(unsigned char* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */313 inline void getValue(short* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */314 inline void getValue(unsigned short* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */315 inline void getValue(int* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */316 inline void getValue(unsigned int* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */317 inline void getValue(long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */318 inline void getValue(unsigned long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */319 inline void getValue(long long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */320 inline void getValue(unsigned long long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */321 inline void getValue(float* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */322 inline void getValue(double* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */323 inline void getValue(long double* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */324 inline void getValue(bool* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */325 inline void getValue(void* value) const { if (this->value_) { value = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */326 inline void getValue(std::string* value) const { if (this->value_) { (*value) = this->value_->operator std::string(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */327 inline void getValue(orxonox::Vector2* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector2(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */328 inline void getValue(orxonox::Vector3* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector3(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */329 inline void getValue(orxonox::Vector4* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector4(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */330 inline void getValue(orxonox::ColourValue* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::ColourValue(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */331 inline void getValue(orxonox::Quaternion* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Quaternion(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */332 inline void getValue(orxonox::Radian* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Radian(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */333 inline void getValue(orxonox::Degree* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */346 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 347 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 348 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 349 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 350 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 351 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 352 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 353 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 354 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 355 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 356 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 357 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 358 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 359 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 360 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 361 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 362 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 363 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 364 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 365 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 366 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 367 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 368 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 334 369 335 370 inline char getChar() const { return this->operator char(); } /** @brief Returns the current value, converted to the requested type. */ … … 359 394 360 395 private: 361 inline void assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */362 inline void assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_uchar) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */363 inline void assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */364 inline void assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_ushort) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */365 inline void assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */366 inline void assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_uint) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */367 inline void assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */368 inline void assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_ulong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */369 inline void assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_longlong) { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */370 inline void assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_ulonglong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */371 inline void assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */372 inline void assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */373 inline void assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_longdouble) { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */374 inline void assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */375 inline void assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */376 inline void assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_string) { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */377 inline void assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_vector2) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */378 inline void assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_vector3) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */379 inline void assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_vector4) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */380 inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); } } /** @brief Assigns a new value by changing type and creating a new container. */381 inline void assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_quaternion) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */382 inline void assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_radian) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */383 inline void assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_degree) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */396 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 397 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_uchar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 398 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 399 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_ushort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 400 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 401 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_uint) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 402 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 403 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_ulong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 404 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_longlong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 405 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_ulonglong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 406 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 407 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 408 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_longdouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 409 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 410 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 411 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_string) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 412 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 413 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 414 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 415 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 416 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 417 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 418 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 384 419 385 420 /** @brief Changes the value container. */ 386 421 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 387 422 /** @brief Creates a new value container (works only with specialized types). */ 388 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }423 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } 389 424 390 425 MT_ValueBase* value_; //!< A pointer to the value container … … 419 454 420 455 // Specialization to avoid ambiguities with the conversion operator 421 template <> inline void MultiType::convert<std::string>() {this->setValue<std::string> (this->operator std::string()); } /** @brief Converts the current value to the given type. */422 template <> inline void MultiType::convert<orxonox::Vector2>() {this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } /** @brief Converts the current value to the given type. */423 template <> inline void MultiType::convert<orxonox::Vector3>() {this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } /** @brief Converts the current value to the given type. */424 template <> inline void MultiType::convert<orxonox::Vector4>() {this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } /** @brief Converts the current value to the given type. */425 template <> inline void MultiType::convert<orxonox::ColourValue>() {this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */426 template <> inline void MultiType::convert<orxonox::Quaternion>() {this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } /** @brief Converts the current value to the given type. */427 template <> inline void MultiType::convert<orxonox::Radian>() {this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } /** @brief Converts the current value to the given type. */428 template <> inline void MultiType::convert<orxonox::Degree>() {this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } /** @brief Converts the current value to the given type. */456 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } /** @brief Converts the current value to the given type. */ 457 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } /** @brief Converts the current value to the given type. */ 458 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } /** @brief Converts the current value to the given type. */ 459 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } /** @brief Converts the current value to the given type. */ 460 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */ 461 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } /** @brief Converts the current value to the given type. */ 462 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } /** @brief Converts the current value to the given type. */ 463 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } /** @brief Converts the current value to the given type. */ 429 464 430 465 // Specialization to avoid ambiguities with the conversion operator 431 template <> inline void MultiType::convert<const std::string&>() {this->convert<std::string>(); } /** @brief Converts the current value to the given type. */432 template <> inline void MultiType::convert<const orxonox::Vector2&>() {this->convert<orxonox::Vector2>(); } /** @brief Converts the current value to the given type. */433 template <> inline void MultiType::convert<const orxonox::Vector3&>() {this->convert<orxonox::Vector3>(); } /** @brief Converts the current value to the given type. */434 template <> inline void MultiType::convert<const orxonox::Vector4&>() {this->convert<orxonox::Vector4>(); } /** @brief Converts the current value to the given type. */435 template <> inline void MultiType::convert<const orxonox::ColourValue&>() {this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */436 template <> inline void MultiType::convert<const orxonox::Quaternion&>() {this->convert<orxonox::Quaternion>(); } /** @brief Converts the current value to the given type. */437 template <> inline void MultiType::convert<const orxonox::Radian&>() {this->convert<orxonox::Radian>(); } /** @brief Converts the current value to the given type. */438 template <> inline void MultiType::convert<const orxonox::Degree&>() {this->convert<orxonox::Degree>(); } /** @brief Converts the current value to the given type. */466 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } /** @brief Converts the current value to the given type. */ 467 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } /** @brief Converts the current value to the given type. */ 468 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } /** @brief Converts the current value to the given type. */ 469 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } /** @brief Converts the current value to the given type. */ 470 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */ 471 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } /** @brief Converts the current value to the given type. */ 472 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } /** @brief Converts the current value to the given type. */ 473 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } /** @brief Converts the current value to the given type. */ 439 474 440 475 template <> void MultiType::createNewValueContainer(const char& value); … … 462 497 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value); 463 498 464 inline void MultiType::setValue(const char& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */465 inline void MultiType::setValue(const unsigned char& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */466 inline void MultiType::setValue(const short& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */467 inline void MultiType::setValue(const unsigned short& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */468 inline void MultiType::setValue(const int& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */469 inline void MultiType::setValue(const unsigned int& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */470 inline void MultiType::setValue(const long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */471 inline void MultiType::setValue(const unsigned long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */472 inline void MultiType::setValue(const long long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */473 inline void MultiType::setValue(const unsigned long long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */474 inline void MultiType::setValue(const float& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */475 inline void MultiType::setValue(const double& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */476 inline void MultiType::setValue(const long double& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */477 inline void MultiType::setValue(const bool& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */478 inline void MultiType::setValue( void* const& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */479 inline void MultiType::setValue(const std::string& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */480 inline void MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */481 inline void MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */482 inline void MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */483 inline void MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */484 inline void MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */485 inline void MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */486 inline void MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */487 488 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else {this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */499 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 500 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 501 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 502 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 503 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 504 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 505 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 506 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 507 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 508 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 509 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 510 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 511 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 512 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 513 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 514 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 515 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 516 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 517 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 518 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 519 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 520 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 521 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 522 523 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */ 489 524 490 525 #endif /* _MultiType_H__ */ -
code/trunk/src/util/MultiTypeValue.h
r1854 r2087 38 38 39 39 #include "UtilPrereqs.h" 40 #include " Convert.h"40 #include "MathConvert.h" 41 41 #include "MultiType.h" 42 42 … … 54 54 55 55 /** @brief Resets the current value to the default. */ 56 inline void reset() { this->value_ = T(); }56 inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; } 57 57 58 58 /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */ 59 inline void assimilate(const MultiType& other) { if (other.value_) { T temp; other.getValue(&temp); this->value_ = temp; } else { this->value_ = T(); } } 59 inline bool assimilate(const MultiType& other) 60 { 61 if (other.value_) 62 { 63 return !(bHasDefaultValue_ = !other.value_->getValue(&value_)); 64 } 65 else 66 { 67 this->value_ = zeroise<T>(); 68 return !(bHasDefaultValue_ = true); 69 } 70 } 60 71 61 inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); } /** @brief Assigns the value by converting it to T. */ 62 inline void setValue(const unsigned char& value) { this->value_ = getConvertedValue<unsigned char, T>(value); } /** @brief Assigns the value by converting it to T. */ 63 inline void setValue(const short& value) { this->value_ = getConvertedValue<short, T>(value); } /** @brief Assigns the value by converting it to T. */ 64 inline void setValue(const unsigned short& value) { this->value_ = getConvertedValue<unsigned short, T>(value); } /** @brief Assigns the value by converting it to T. */ 65 inline void setValue(const int& value) { this->value_ = getConvertedValue<int, T>(value); } /** @brief Assigns the value by converting it to T. */ 66 inline void setValue(const unsigned int& value) { this->value_ = getConvertedValue<unsigned int, T>(value); } /** @brief Assigns the value by converting it to T. */ 67 inline void setValue(const long& value) { this->value_ = getConvertedValue<long, T>(value); } /** @brief Assigns the value by converting it to T. */ 68 inline void setValue(const unsigned long& value) { this->value_ = getConvertedValue<unsigned long, T>(value); } /** @brief Assigns the value by converting it to T. */ 69 inline void setValue(const long long& value) { this->value_ = getConvertedValue<long long, T>(value); } /** @brief Assigns the value by converting it to T. */ 70 inline void setValue(const unsigned long long& value) { this->value_ = getConvertedValue<unsigned long long, T>(value); } /** @brief Assigns the value by converting it to T. */ 71 inline void setValue(const float& value) { this->value_ = getConvertedValue<float, T>(value); } /** @brief Assigns the value by converting it to T. */ 72 inline void setValue(const double& value) { this->value_ = getConvertedValue<double, T>(value); } /** @brief Assigns the value by converting it to T. */ 73 inline void setValue(const long double& value) { this->value_ = getConvertedValue<long double, T>(value); } /** @brief Assigns the value by converting it to T. */ 74 inline void setValue(const bool& value) { this->value_ = getConvertedValue<bool, T>(value); } /** @brief Assigns the value by converting it to T. */ 75 inline void setValue( void* const& value) { this->value_ = getConvertedValue<void*, T>(value); } /** @brief Assigns the value by converting it to T. */ 76 inline void setValue(const std::string& value) { this->value_ = getConvertedValue<std::string, T>(value); } /** @brief Assigns the value by converting it to T. */ 77 inline void setValue(const orxonox::Vector2& value) { this->value_ = getConvertedValue<orxonox::Vector2, T>(value); } /** @brief Assigns the value by converting it to T. */ 78 inline void setValue(const orxonox::Vector3& value) { this->value_ = getConvertedValue<orxonox::Vector3, T>(value); } /** @brief Assigns the value by converting it to T. */ 79 inline void setValue(const orxonox::Vector4& value) { this->value_ = getConvertedValue<orxonox::Vector4, T>(value); } /** @brief Assigns the value by converting it to T. */ 80 inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); } /** @brief Assigns the value by converting it to T. */ 81 inline void setValue(const orxonox::Quaternion& value) { this->value_ = getConvertedValue<orxonox::Quaternion, T>(value); } /** @brief Assigns the value by converting it to T. */ 82 inline void setValue(const orxonox::Radian& value) { this->value_ = getConvertedValue<orxonox::Radian, T>(value); } /** @brief Assigns the value by converting it to T. */ 83 inline void setValue(const orxonox::Degree& value) { this->value_ = getConvertedValue<orxonox::Degree, T>(value); } /** @brief Assigns the value by converting it to T. */ 72 inline bool getValue(char* value) const { return ConvertValue<T, char >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 73 inline bool getValue(unsigned char* value) const { return ConvertValue<T, unsigned char >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 74 inline bool getValue(short* value) const { return ConvertValue<T, short >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 75 inline bool getValue(unsigned short* value) const { return ConvertValue<T, unsigned short >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 76 inline bool getValue(int* value) const { return ConvertValue<T, int >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 77 inline bool getValue(unsigned int* value) const { return ConvertValue<T, unsigned int >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 78 inline bool getValue(long* value) const { return ConvertValue<T, long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 79 inline bool getValue(unsigned long* value) const { return ConvertValue<T, unsigned long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 80 inline bool getValue(long long* value) const { return ConvertValue<T, long long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 81 inline bool getValue(unsigned long long* value) const { return ConvertValue<T, unsigned long long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 82 inline bool getValue(float* value) const { return ConvertValue<T, float >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 83 inline bool getValue(double* value) const { return ConvertValue<T, double >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 84 inline bool getValue(long double* value) const { return ConvertValue<T, long double >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 85 inline bool getValue(bool* value) const { return ConvertValue<T, bool >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 86 inline bool getValue(void** value) const { return ConvertValue<T, void* >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 87 inline bool getValue(std::string* value) const { return ConvertValue<T, std::string >(value, value_, zeroise<std::string> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 88 inline bool getValue(orxonox::Vector2* value) const { return ConvertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 89 inline bool getValue(orxonox::Vector3* value) const { return ConvertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 90 inline bool getValue(orxonox::Vector4* value) const { return ConvertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 91 inline bool getValue(orxonox::ColourValue* value) const { return ConvertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 92 inline bool getValue(orxonox::Quaternion* value) const { return ConvertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 93 inline bool getValue(orxonox::Radian* value) const { return ConvertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 94 inline bool getValue(orxonox::Degree* value) const { return ConvertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 95 96 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !ConvertValue<char , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 97 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned char , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 98 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !ConvertValue<short , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 99 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned short , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 100 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !ConvertValue<int , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 101 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned int , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 102 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !ConvertValue<long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 103 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 104 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !ConvertValue<long long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 105 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 106 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !ConvertValue<float , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 107 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !ConvertValue<double , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 108 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !ConvertValue<long double , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 109 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !ConvertValue<bool , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 110 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !ConvertValue<void* , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 111 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !ConvertValue<std::string , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 112 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 113 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 114 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 115 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 116 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 117 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 118 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 84 119 85 120 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ … … 96 131 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 97 132 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 98 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, false); }/** @brief Returns the current value, converted to the requested type. */133 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 99 134 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 100 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */101 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */102 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */103 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */104 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_ ); }/** @brief Returns the current value, converted to the requested type. */105 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */106 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */107 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */135 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, zeroise<std::string >()); } /** @brief Returns the current value, converted to the requested type. */ 136 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, zeroise<orxonox::Vector2 >()); } /** @brief Returns the current value, converted to the requested type. */ 137 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, zeroise<orxonox::Vector3 >()); } /** @brief Returns the current value, converted to the requested type. */ 138 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, zeroise<orxonox::Vector4 >()); } /** @brief Returns the current value, converted to the requested type. */ 139 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, zeroise<orxonox::ColourValue>()); } /** @brief Returns the current value, converted to the requested type. */ 140 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, zeroise<orxonox::Quaternion >()); } /** @brief Returns the current value, converted to the requested type. */ 141 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, zeroise<orxonox::Radian >()); } /** @brief Returns the current value, converted to the requested type. */ 142 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, zeroise<orxonox::Degree >()); } /** @brief Returns the current value, converted to the requested type. */ 108 143 109 144 /** @brief Puts the current value on the stream */ -
code/trunk/src/util/OutputHandler.cc
r1791 r2087 33 33 34 34 #include "OutputHandler.h" 35 #include <time.h> 35 36 36 37 namespace orxonox … … 46 47 this->logfilename_ = logfilename; 47 48 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 48 this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; // Todo: Get date and time 49 50 time_t rawtime; 51 struct tm* timeinfo; 52 time(&rawtime); 53 timeinfo = localtime(&rawtime); 54 55 this->logfile_ << "Started log at " << asctime(timeinfo) << std::endl; 49 56 this->logfile_.flush(); 50 57 } -
code/trunk/src/util/String.cc
r1894 r2087 37 37 #include <iostream> 38 38 39 /** 40 @brief Blank string as variable so you can use const std::string& even if you have to return "". 41 */ 42 std::string blankString = ""; 39 #include "Convert.h" 40 #include "Math.h" 41 42 std::string BLANKSTRING(""); 43 44 std::string getUniqueNumberString() 45 { 46 return convertToString(getUniqueNumber()); 47 } 43 48 44 49 /** -
code/trunk/src/util/String.h
r1889 r2087 40 40 #include <sstream> 41 41 42 extern _UtilExport std::string blankString; 42 extern _UtilExport std::string BLANKSTRING; 43 _UtilExport std::string getUniqueNumberString(); 43 44 44 45 _UtilExport void strip(std::string* str);
Note: See TracChangeset
for help on using the changeset viewer.