Changeset 1747 for code/trunk/src/util
- Timestamp:
- Sep 9, 2008, 4:25:52 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 6 deleted
- 5 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core3 (added) merged: 1573-1574,1583-1586,1591-1594,1596-1597,1603,1606-1607,1610-1611,1655,1658,1676-1679,1681-1685,1687,1716-1723,1725-1729,1736
- Property svn:mergeinfo changed
-
code/trunk/src/util/CMakeLists.txt
r1505 r1747 2 2 ArgReader.cc 3 3 Clipboard.cc 4 Error.cc 4 5 ExprParser.cc 5 6 Math.cc 6 MultiType Primitive.cc7 MultiTypeString.cc8 MultiTypeMath.cc7 MultiType.cc 8 OutputBuffer.cc 9 OutputHandler.cc 9 10 String.cc 10 11 SubString.cc -
code/trunk/src/util/Convert.h
r1625 r1747 41 41 42 42 #include "Math.h" 43 #include "Debug.h" 43 44 #include "SubString.h" 44 #include "MultiTypeMath.h"45 45 #include "String.h" 46 46 … … 75 75 enum { specialized = false }; 76 76 static bool convert(ToType* output, const FromType& input) 77 { return false; } 77 { 78 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 79 return false; 80 } 78 81 }; 79 82 … … 95 98 96 99 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type 97 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 98 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 99 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 100 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 101 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 102 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 103 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 104 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 105 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 106 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 107 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 108 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 109 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 110 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 111 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 112 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 100 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 101 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 102 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 103 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 104 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 105 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 106 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 107 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 108 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 109 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 110 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 111 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 112 template <> struct ConverterLevel<long long> { enum { level = __low__ }; }; 113 template <> struct ConverterLevel<unsigned long long> { enum { level = __low__ }; }; 114 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 115 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 116 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 117 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 113 118 114 119 … … 140 145 static bool convert(ToType* output, const FromType& input) 141 146 { 147 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 142 148 return false; 143 149 } … … 330 336 331 337 332 //////////////// 333 // MULTITYPES // 334 //////////////// 335 336 // convert from MultiTypePrimitive 337 template <class ToType> 338 struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_> 339 { 340 enum { specialized = true }; 341 static bool convert(ToType* output, const MultiTypePrimitive& input) 342 { 343 if (input.getType() == MT_void) 344 return ConvertValue(output, input.getVoid()); 345 else if (input.getType() == MT_int) 346 return ConvertValue(output, input.getInt()); 347 else if (input.getType() == MT_uint) 348 return ConvertValue(output, input.getUnsignedInt()); 349 else if (input.getType() == MT_char) 350 return ConvertValue(output, input.getChar()); 351 else if (input.getType() == MT_uchar) 352 return ConvertValue(output, input.getUnsignedChar()); 353 else if (input.getType() == MT_short) 354 return ConvertValue(output, input.getShort()); 355 else if (input.getType() == MT_ushort) 356 return ConvertValue(output, input.getUnsignedShort()); 357 else if (input.getType() == MT_long) 358 return ConvertValue(output, input.getLong()); 359 else if (input.getType() == MT_ulong) 360 return ConvertValue(output, input.getUnsignedLong()); 361 else if (input.getType() == MT_float) 362 return ConvertValue(output, input.getFloat()); 363 else if (input.getType() == MT_double) 364 return ConvertValue(output, input.getDouble()); 365 else if (input.getType() == MT_longdouble) 366 return ConvertValue(output, input.getLongDouble()); 367 else if (input.getType() == MT_bool) 368 return ConvertValue(output, input.getBool()); 369 else 370 return false; 371 } 372 }; 373 374 // convert from MultiTypeString 375 template <class ToType> 376 struct ConverterSpecialized<MultiTypeString, ToType, _FromType_> 377 { 378 enum { specialized = true }; 379 static bool convert(ToType* output, const MultiTypeString& input) 380 { 381 if (input.getType() == MT_constchar) 382 return ConvertValue(output, input.getConstChar()); 383 else if (input.getType() == MT_string) 384 return ConvertValue(output, input.getString()); 385 else 386 return ConvertValue(output, (MultiTypePrimitive)input); 387 } 388 }; 389 390 // convert from MultiTypeMath 391 template <class ToType> 392 struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_> 393 { 394 enum { specialized = true }; 395 static bool convert(ToType* output, const MultiTypeMath& input) 396 { 397 if (input.getType() == MT_vector2) 398 return ConvertValue(output, input.getVector2()); 399 else if (input.getType() == MT_vector3) 400 return ConvertValue(output, input.getVector3()); 401 else if (input.getType() == MT_vector4) 402 return ConvertValue(output, input.getVector4()); 403 else if (input.getType() == MT_quaternion) 404 return ConvertValue(output, input.getQuaternion()); 405 else if (input.getType() == MT_colourvalue) 406 return ConvertValue(output, input.getColourValue()); 407 else if (input.getType() == MT_radian) 408 return ConvertValue(output, input.getRadian()); 409 else if (input.getType() == MT_degree) 410 return ConvertValue(output, input.getDegree()); 411 else 412 return ConvertValue(output, (MultiTypeString)input); 338 ////////// 339 // MATH // 340 ////////// 341 // convert everything to Degree 342 template <class FromType> 343 struct ConverterSpecialized<FromType, Ogre::Degree, _ToType_> 344 { 345 enum { specialized = true }; 346 static bool convert(Ogre::Degree* output, const FromType& input) 347 { 348 float angle = 0; 349 bool success = ConvertValue<FromType, float>(&angle, input); 350 (*output) = angle; 351 return success; 352 } 353 }; 354 355 // convert everything to Radian 356 template <class FromType> 357 struct ConverterSpecialized<FromType, Ogre::Radian, _ToType_> 358 { 359 enum { specialized = true }; 360 static bool convert(Ogre::Radian* output, const FromType& input) 361 { 362 float angle = 0; 363 bool success = ConvertValue<FromType, float>(&angle, input); 364 (*output) = angle; 365 return success; 413 366 } 414 367 }; -
code/trunk/src/util/MultiType.h
r1505 r1747 25 25 * ... 26 26 * 27 * Inspiration: MultiType by Benjamin Grauer28 27 */ 29 28 … … 33 32 #include "UtilPrereqs.h" 34 33 35 enum _UtilExport MultiType 34 #include <boost/static_assert.hpp> 35 36 #include "Math.h" 37 38 enum MT_Type 36 39 { 37 40 MT_null, 38 MT_void,39 MT_int,40 MT_uint,41 41 MT_char, 42 42 MT_uchar, 43 43 MT_short, 44 44 MT_ushort, 45 MT_int, 46 MT_uint, 45 47 MT_long, 46 48 MT_ulong, 49 MT_longlong, 50 MT_ulonglong, 47 51 MT_float, 48 52 MT_double, 49 53 MT_longdouble, 50 54 MT_bool, 51 MT_ constchar,55 MT_void, 52 56 MT_string, 53 MT_xmlelement,54 57 MT_vector2, 55 58 MT_vector3, … … 57 60 MT_colourvalue, 58 61 MT_quaternion, 59 MT_ degree,60 MT_ radian62 MT_radian, 63 MT_degree 61 64 }; 62 65 63 union _UtilExport MultiTypeValue66 class _UtilExport MultiType 64 67 { 65 void* void_; 66 int int_; 67 unsigned int uint_; 68 char char_; 69 unsigned char uchar_; 70 short short_; 71 unsigned short ushort_; 72 long long_; 73 unsigned long ulong_; 74 float float_; 75 double double_; 76 long double longdouble_; 77 bool bool_; 68 _UtilExport friend std::ostream& operator<<(std::ostream& outstream, const MultiType& mt); 69 template <typename T> friend struct MT_Value; 70 71 struct _UtilExport MT_ValueBase 72 { 73 MT_ValueBase(MT_Type type) : type_(type) {} 74 virtual ~MT_ValueBase() {} 75 76 virtual MT_ValueBase* clone() const = 0; 77 78 virtual void reset() = 0; 79 virtual void assimilate(const MultiType& other) = 0; 80 const MT_Type& getType() const { return this->type_; } 81 82 virtual void setValue(const char& value) = 0; 83 virtual void setValue(const unsigned char& value) = 0; 84 virtual void setValue(const short& value) = 0; 85 virtual void setValue(const unsigned short& value) = 0; 86 virtual void setValue(const int& value) = 0; 87 virtual void setValue(const unsigned int& value) = 0; 88 virtual void setValue(const long& value) = 0; 89 virtual void setValue(const unsigned long& value) = 0; 90 virtual void setValue(const long long& value) = 0; 91 virtual void setValue(const unsigned long long& value) = 0; 92 virtual void setValue(const float& value) = 0; 93 virtual void setValue(const double& value) = 0; 94 virtual void setValue(const long double& value) = 0; 95 virtual void setValue(const bool& value) = 0; 96 virtual void setValue( void* const& value) = 0; 97 virtual void setValue(const std::string& value) = 0; 98 virtual void setValue(const orxonox::Vector2& value) = 0; 99 virtual void setValue(const orxonox::Vector3& value) = 0; 100 virtual void setValue(const orxonox::Vector4& value) = 0; 101 virtual void setValue(const orxonox::ColourValue& value) = 0; 102 virtual void setValue(const orxonox::Quaternion& value) = 0; 103 virtual void setValue(const orxonox::Radian& value) = 0; 104 virtual void setValue(const orxonox::Degree& value) = 0; 105 106 virtual operator char() const = 0; 107 virtual operator unsigned char() const = 0; 108 virtual operator short() const = 0; 109 virtual operator unsigned short() const = 0; 110 virtual operator int() const = 0; 111 virtual operator unsigned int() const = 0; 112 virtual operator long() const = 0; 113 virtual operator unsigned long() const = 0; 114 virtual operator long long() const = 0; 115 virtual operator unsigned long long() const = 0; 116 virtual operator float() const = 0; 117 virtual operator double() const = 0; 118 virtual operator long double() const = 0; 119 virtual operator bool() const = 0; 120 virtual operator void*() const = 0; 121 virtual operator std::string() const = 0; 122 virtual operator orxonox::Vector2() const = 0; 123 virtual operator orxonox::Vector3() const = 0; 124 virtual operator orxonox::Vector4() const = 0; 125 virtual operator orxonox::ColourValue() const = 0; 126 virtual operator orxonox::Quaternion() const = 0; 127 virtual operator orxonox::Radian() const = 0; 128 virtual operator orxonox::Degree() const = 0; 129 130 virtual void toString(std::ostream& outstream) const = 0; 131 132 MT_Type type_; 133 }; 134 135 public: 136 inline MultiType() : value_(0) {} 137 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } 138 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } 139 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } 140 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } 141 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } 142 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } 143 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } 144 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } 145 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } 146 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } 147 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } 148 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } 149 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } 150 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } 151 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } 152 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } 153 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } 154 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } 155 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } 156 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } 157 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } 158 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } 159 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } 160 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } 161 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } 162 inline MultiType(MT_Type type) : value_(0) { this->setType(type); } 163 164 inline ~MultiType() { if (this->value_) { delete this->value_; } } 165 166 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 167 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 168 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 169 170 inline void setValue(const char& value); 171 inline void setValue(const unsigned char& value); 172 inline void setValue(const short& value); 173 inline void setValue(const unsigned short& value); 174 inline void setValue(const int& value); 175 inline void setValue(const unsigned int& value); 176 inline void setValue(const long& value); 177 inline void setValue(const unsigned long& value); 178 inline void setValue(const long long& value); 179 inline void setValue(const unsigned long long& value); 180 inline void setValue(const float& value); 181 inline void setValue(const double& value); 182 inline void setValue(const long double& value); 183 inline void setValue(const bool& value); 184 inline void setValue( void* const& value); 185 inline void setValue(const std::string& value); 186 inline void setValue(const orxonox::Vector2& value); 187 inline void setValue(const orxonox::Vector3& value); 188 inline void setValue(const orxonox::Vector4& value); 189 inline void setValue(const orxonox::ColourValue& value); 190 inline void setValue(const orxonox::Quaternion& value); 191 inline void setValue(const orxonox::Radian& value); 192 inline void setValue(const orxonox::Degree& value); 193 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } } 194 void setValue(const MultiType& other) { if (this->value_) { this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } } } 195 template <typename T, typename V> inline void setValue(const V& value) { this->setType<T>(); this->setValue(value); } 196 inline void setValue(const char* value); 197 198 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 199 200 template <typename T> inline void convert() { this->setValue<T>((T)(*this)); } 201 inline void convert(const MultiType& other) { this->convert(other.getType()); } 202 void convert(MT_Type type); 203 204 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } } 205 206 template <typename T> inline void setType() { this->assignValue(T()); } 207 inline void setType(const MultiType& other) { this->setType(other.getType()); } 208 inline void setType(MT_Type type) { this->reset(); this->convert(type); } 209 210 inline MT_Type getType() const { return (this->value_) ? this->value_->type_ : MT_null; } 211 inline bool isType(MT_Type type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_null); } 212 template <typename T> inline bool isType() const { return false; } 213 std::string getTypename() const; 214 215 operator char() const; 216 operator unsigned char() const; 217 operator short() const; 218 operator unsigned short() const; 219 operator int() const; 220 operator unsigned int() const; 221 operator long() const; 222 operator unsigned long() const; 223 operator long long() const; 224 operator unsigned long long() const; 225 operator float() const; 226 operator double() const; 227 operator long double() const; 228 operator bool() const; 229 operator void*() const; 230 operator std::string() const; 231 operator orxonox::Vector2() const; 232 operator orxonox::Vector3() const; 233 operator orxonox::Vector4() const; 234 operator orxonox::ColourValue() const; 235 operator orxonox::Quaternion() const; 236 operator orxonox::Radian() const; 237 operator orxonox::Degree() const; 238 template <class T> operator T*() const { return ((T*)this->operator void*()); } 239 240 inline void getValue(char* value) const { if (this->value_) { (*value) = (*this->value_); } } 241 inline void getValue(unsigned char* value) const { if (this->value_) { (*value) = (*this->value_); } } 242 inline void getValue(short* value) const { if (this->value_) { (*value) = (*this->value_); } } 243 inline void getValue(unsigned short* value) const { if (this->value_) { (*value) = (*this->value_); } } 244 inline void getValue(int* value) const { if (this->value_) { (*value) = (*this->value_); } } 245 inline void getValue(unsigned int* value) const { if (this->value_) { (*value) = (*this->value_); } } 246 inline void getValue(long* value) const { if (this->value_) { (*value) = (*this->value_); } } 247 inline void getValue(unsigned long* value) const { if (this->value_) { (*value) = (*this->value_); } } 248 inline void getValue(long long* value) const { if (this->value_) { (*value) = (*this->value_); } } 249 inline void getValue(unsigned long long* value) const { if (this->value_) { (*value) = (*this->value_); } } 250 inline void getValue(float* value) const { if (this->value_) { (*value) = (*this->value_); } } 251 inline void getValue(double* value) const { if (this->value_) { (*value) = (*this->value_); } } 252 inline void getValue(long double* value) const { if (this->value_) { (*value) = (*this->value_); } } 253 inline void getValue(bool* value) const { if (this->value_) { (*value) = (*this->value_); } } 254 inline void getValue(void* value) const { if (this->value_) { value = (*this->value_); } } 255 inline void getValue(std::string* value) const { if (this->value_) { (*value) = this->value_->operator std::string(); } } 256 inline void getValue(orxonox::Vector2* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector2(); } } 257 inline void getValue(orxonox::Vector3* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector3(); } } 258 inline void getValue(orxonox::Vector4* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector4(); } } 259 inline void getValue(orxonox::ColourValue* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::ColourValue(); } } 260 inline void getValue(orxonox::Quaternion* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Quaternion(); } } 261 inline void getValue(orxonox::Radian* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Radian(); } } 262 inline void getValue(orxonox::Degree* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree(); } } 263 264 inline char getChar() const { return this->operator char(); } 265 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } 266 inline short getShort() const { return this->operator short(); } 267 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } 268 inline int getInt() const { return this->operator int(); } 269 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } 270 inline long getLong() const { return this->operator long(); } 271 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } 272 inline long long getLongLong() const { return this->operator long long(); } 273 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } 274 inline float getFloat() const { return this->operator float(); } 275 inline double getDouble() const { return this->operator double(); } 276 inline long double getLongDouble() const { return this->operator long double(); } 277 inline bool getBool() const { return this->operator bool(); } 278 inline void* getVoid() const { return this->operator void*(); } 279 inline std::string getString() const { return this->operator std::string(); } 280 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } 281 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } 282 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } 283 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } 284 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } 285 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } 286 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } 287 template <typename T> inline T* getPointer() const { return ((T*)this->getVoid()); } 288 289 private: 290 inline void assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value); } } 291 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); } } 292 inline void assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value); } } 293 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); } } 294 inline void assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value); } } 295 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); } } 296 inline void assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value); } } 297 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); } } 298 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); } } 299 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); } } 300 inline void assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value); } } 301 inline void assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value); } } 302 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); } } 303 inline void assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); } } 304 inline void assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); } } 305 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); } } 306 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); } } 307 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); } } 308 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); } } 309 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); } } 310 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); } } 311 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); } } 312 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); } } 313 314 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 315 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); } 316 317 MT_ValueBase* value_; 78 318 }; 79 319 320 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 321 322 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_char); } 323 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_uchar); } 324 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_short); } 325 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_ushort); } 326 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_int); } 327 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_uint); } 328 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_long); } 329 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_ulong); } 330 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_longlong); } 331 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_ulonglong); } 332 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_float); } 333 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_double); } 334 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_longdouble); } 335 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_bool); } 336 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_void); } 337 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_string); } 338 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_vector2); } 339 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_vector3); } 340 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_vector4); } 341 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_colourvalue); } 342 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_quaternion); } 343 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_radian); } 344 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_degree); } 345 346 template <> inline void MultiType::convert<std::string>() { this->setValue<std::string> (this->operator std::string()); } 347 template <> inline void MultiType::convert<orxonox::Vector2>() { this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } 348 template <> inline void MultiType::convert<orxonox::Vector3>() { this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } 349 template <> inline void MultiType::convert<orxonox::Vector4>() { this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } 350 template <> inline void MultiType::convert<orxonox::ColourValue>() { this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } 351 template <> inline void MultiType::convert<orxonox::Quaternion>() { this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } 352 template <> inline void MultiType::convert<orxonox::Radian>() { this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } 353 template <> inline void MultiType::convert<orxonox::Degree>() { this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } 354 355 template <> inline void MultiType::convert<const std::string&>() { this->convert<std::string>(); } 356 template <> inline void MultiType::convert<const orxonox::Vector2&>() { this->convert<orxonox::Vector2>(); } 357 template <> inline void MultiType::convert<const orxonox::Vector3&>() { this->convert<orxonox::Vector3>(); } 358 template <> inline void MultiType::convert<const orxonox::Vector4&>() { this->convert<orxonox::Vector4>(); } 359 template <> inline void MultiType::convert<const orxonox::ColourValue&>() { this->convert<orxonox::ColourValue>(); } 360 template <> inline void MultiType::convert<const orxonox::Quaternion&>() { this->convert<orxonox::Quaternion>(); } 361 template <> inline void MultiType::convert<const orxonox::Radian&>() { this->convert<orxonox::Radian>(); } 362 template <> inline void MultiType::convert<const orxonox::Degree&>() { this->convert<orxonox::Degree>(); } 363 364 template <> void MultiType::createNewValueContainer(const char& value); 365 template <> void MultiType::createNewValueContainer(const unsigned char& value); 366 template <> void MultiType::createNewValueContainer(const short& value); 367 template <> void MultiType::createNewValueContainer(const unsigned short& value); 368 template <> void MultiType::createNewValueContainer(const int& value); 369 template <> void MultiType::createNewValueContainer(const unsigned int& value); 370 template <> void MultiType::createNewValueContainer(const long& value); 371 template <> void MultiType::createNewValueContainer(const unsigned long& value); 372 template <> void MultiType::createNewValueContainer(const long long& value); 373 template <> void MultiType::createNewValueContainer(const unsigned long long& value); 374 template <> void MultiType::createNewValueContainer(const float& value); 375 template <> void MultiType::createNewValueContainer(const double& value); 376 template <> void MultiType::createNewValueContainer(const bool& value); 377 template <> void MultiType::createNewValueContainer(const long double& value); 378 template <> void MultiType::createNewValueContainer( void* const& value); 379 template <> void MultiType::createNewValueContainer(const std::string& value); 380 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value); 381 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value); 382 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value); 383 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value); 384 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value); 385 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value); 386 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value); 387 388 inline void MultiType::setValue(const char& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 389 inline void MultiType::setValue(const unsigned char& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 390 inline void MultiType::setValue(const short& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 391 inline void MultiType::setValue(const unsigned short& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 392 inline void MultiType::setValue(const int& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 393 inline void MultiType::setValue(const unsigned int& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 394 inline void MultiType::setValue(const long& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 395 inline void MultiType::setValue(const unsigned long& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 396 inline void MultiType::setValue(const long long& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 397 inline void MultiType::setValue(const unsigned long long& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 398 inline void MultiType::setValue(const float& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 399 inline void MultiType::setValue(const double& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 400 inline void MultiType::setValue(const long double& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 401 inline void MultiType::setValue(const bool& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 402 inline void MultiType::setValue( void* const& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 403 inline void MultiType::setValue(const std::string& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 404 inline void MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 405 inline void MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 406 inline void MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 407 inline void MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 408 inline void MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 409 inline void MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 410 inline void MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 411 412 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } } 413 80 414 #endif /* _MultiType_H__ */ -
code/trunk/src/util/UtilPrereqs.h
r1735 r1747 62 62 class ArgReader; 63 63 class Convert; 64 class MultiTypePrimitive; 65 class MultiTypeString; 66 class MultiTypeMath; 67 template <class T> 68 class String2Number; 64 class ExprParser; 65 class MultiType; 69 66 class SubString; 67 namespace orxonox 68 { 69 class OutputBuffer; 70 class OutputBufferListener; 71 class Error; 72 class OutputHandler; 73 } 74 70 75 #endif /* _UtilPrereqs_H__ */
Note: See TracChangeset
for help on using the changeset viewer.