Changeset 3280 for code/trunk/src/util
- Timestamp:
- Jul 12, 2009, 11:58:01 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 10 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core4 (added) merged: 3235-3237,3245-3250,3253-3254,3260-3261,3265,3270
- Property svn:mergeinfo changed
-
code/trunk/src/util/CMakeLists.txt
r3196 r3280 29 29 SignalHandler.cc 30 30 Sleep.cc 31 String .cc31 StringUtils.cc 32 32 SubString.cc 33 33 ) -
code/trunk/src/util/Convert.h
r3234 r3280 43 43 44 44 #include "Debug.h" 45 #include "String .h"45 #include "StringUtils.h" 46 46 #include "TemplateUtils.h" 47 47 … … 316 316 } 317 317 318 // convert to string Shortcut319 template <class FromType>320 FORCEINLINE std::string convertToString(FromType value)321 {322 return getConvertedValue<FromType, std::string>(value);323 }324 325 // convert from string Shortcut326 template <class ToType>327 FORCEINLINE ToType convertFromString(std::string str)328 {329 return getConvertedValue<std::string, ToType>(str);330 }331 332 318 //////////////////////////////// 333 319 // Special string conversions // -
code/trunk/src/util/Exception.cc
r3196 r3280 64 64 std::ostringstream fullDesc; 65 65 66 fullDesc << this->getTypeName() << " _EXCEPTION";66 fullDesc << this->getTypeName() << "Exception"; 67 67 68 68 if (this->filename_ != "") … … 87 87 return fullDescription_; 88 88 } 89 90 //! Returns the error description 91 const char* Exception::what() const throw() 92 { 93 return getDescription().c_str(); 94 } 89 95 } -
code/trunk/src/util/Exception.h
r3196 r3280 68 68 //! Needed for compatibility with std::exception 69 69 virtual ~Exception() throw() { } 70 const char* what() const throw(); 70 71 71 72 //! Returns a full description with type, line, file and function … … 81 82 //! Returns the filename in which the exception occurred. 82 83 virtual const std::string& getFilename() const { return this->filename_; } 83 84 //! Returns a full description of the error.85 const char* what() const throw() { return getFullDescription().c_str(); }86 84 87 85 protected: … … 152 150 Exception description as string 153 151 */ 154 #define ThrowException(type, description , ...) \152 #define ThrowException(type, description) \ 155 153 throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__)) 156 154 -
code/trunk/src/util/Math.h
r3214 r3280 78 78 { 79 79 return (x >= 0) ? 1 : -1; 80 }81 82 /**83 @brief Returns the smaller of two values.84 */85 template <typename T>86 inline T min(T a, T b)87 {88 return (a <= b) ? a : b;89 }90 91 /**92 @brief Returns the greater of two values.93 */94 template <typename T>95 inline T max(T a, T b)96 {97 return (a >= b) ? a : b;98 80 } 99 81 -
code/trunk/src/util/MultiType.cc
r3196 r3280 41 41 @param type The type 42 42 */ 43 bool MultiType::convert(MT_Type type)43 bool MultiType::convert(MT_Type::Value type) 44 44 { 45 45 switch (type) 46 46 { 47 case MT_ null:47 case MT_Type::Null: 48 48 this->reset(); return true; 49 case MT_ char:49 case MT_Type::Char: 50 50 return this->convert<char>(); break; 51 case MT_ uchar:51 case MT_Type::UnsignedChar: 52 52 return this->convert<unsigned char>(); break; 53 case MT_ short:53 case MT_Type::Short: 54 54 return this->convert<short>(); break; 55 case MT_ ushort:55 case MT_Type::UnsignedShort: 56 56 return this->convert<unsigned short>(); break; 57 case MT_ int:57 case MT_Type::Int: 58 58 return this->convert<int>(); break; 59 case MT_ uint:59 case MT_Type::UnsignedInt: 60 60 return this->convert<unsigned int>(); break; 61 case MT_ long:61 case MT_Type::Long: 62 62 return this->convert<long>(); break; 63 case MT_ ulong:63 case MT_Type::UnsignedLong: 64 64 return this->convert<unsigned long>(); break; 65 case MT_ longlong:65 case MT_Type::LongLong: 66 66 return this->convert<long long>(); break; 67 case MT_ ulonglong:67 case MT_Type::UnsignedLongLong: 68 68 return this->convert<unsigned long long>(); break; 69 case MT_ float:69 case MT_Type::Float: 70 70 return this->convert<float>(); break; 71 case MT_ double:71 case MT_Type::Double: 72 72 return this->convert<double>(); break; 73 case MT_ longdouble:73 case MT_Type::LongDouble: 74 74 return this->convert<long double>(); break; 75 case MT_ bool:75 case MT_Type::Bool: 76 76 return this->convert<bool>(); break; 77 case MT_ void:77 case MT_Type::VoidPointer: 78 78 return this->convert<void*>(); break; 79 case MT_ string:79 case MT_Type::String: 80 80 return this->convert<std::string>(); break; 81 case MT_ vector2:81 case MT_Type::Vector2: 82 82 return this->convert<orxonox::Vector2>(); break; 83 case MT_ vector3:83 case MT_Type::Vector3: 84 84 return this->convert<orxonox::Vector3>(); break; 85 case MT_ vector4:85 case MT_Type::Vector4: 86 86 return this->convert<orxonox::Vector4>(); break; 87 case MT_ colourvalue:87 case MT_Type::ColourValue: 88 88 return this->convert<orxonox::ColourValue>(); break; 89 case MT_ quaternion:89 case MT_Type::Quaternion: 90 90 return this->convert<orxonox::Quaternion>(); break; 91 case MT_ radian:91 case MT_Type::Radian: 92 92 return this->convert<orxonox::Radian>(); break; 93 case MT_ degree:93 case MT_Type::Degree: 94 94 return this->convert<orxonox::Degree>(); break; 95 95 default: … … 104 104 std::string MultiType::getTypename() const 105 105 { 106 MT_Type type = (this->value_) ? this->value_->type_ : MT_null;106 MT_Type::Value type = (this->value_) ? this->value_->type_ : MT_Type::Null; 107 107 108 108 switch (type) 109 109 { 110 case MT_ char:110 case MT_Type::Char: 111 111 return "char"; break; 112 case MT_ uchar:112 case MT_Type::UnsignedChar: 113 113 return "unsigned char"; break; 114 case MT_ short:114 case MT_Type::Short: 115 115 return "short"; break; 116 case MT_ ushort:116 case MT_Type::UnsignedShort: 117 117 return "unsigned short"; break; 118 case MT_ int:118 case MT_Type::Int: 119 119 return "int"; break; 120 case MT_ uint:120 case MT_Type::UnsignedInt: 121 121 return "unsigned int"; break; 122 case MT_ long:122 case MT_Type::Long: 123 123 return "long"; break; 124 case MT_ ulong:124 case MT_Type::UnsignedLong: 125 125 return "unsigned long"; break; 126 case MT_ longlong:126 case MT_Type::LongLong: 127 127 return "long long"; break; 128 case MT_ ulonglong:128 case MT_Type::UnsignedLongLong: 129 129 return "unsigned long long"; break; 130 case MT_ float:130 case MT_Type::Float: 131 131 return "float"; break; 132 case MT_ double:132 case MT_Type::Double: 133 133 return "double"; break; 134 case MT_ longdouble:134 case MT_Type::LongDouble: 135 135 return "long double"; break; 136 case MT_ bool:136 case MT_Type::Bool: 137 137 return "bool"; break; 138 case MT_ void:138 case MT_Type::VoidPointer: 139 139 return "void*"; break; 140 case MT_ string:140 case MT_Type::String: 141 141 return "std::string"; break; 142 case MT_ vector2:142 case MT_Type::Vector2: 143 143 return "orxonox::Vector2"; break; 144 case MT_ vector3:144 case MT_Type::Vector3: 145 145 return "orxonox::Vector3"; break; 146 case MT_ vector4:146 case MT_Type::Vector4: 147 147 return "orxonox::Vector4"; break; 148 case MT_ colourvalue:148 case MT_Type::ColourValue: 149 149 return "orxonox::ColourValue"; break; 150 case MT_ quaternion:150 case MT_Type::Quaternion: 151 151 return "orxonox::Quaternion"; break; 152 case MT_ radian:152 case MT_Type::Radian: 153 153 return "orxonox::Radian"; break; 154 case MT_ degree:154 case MT_Type::Degree: 155 155 return "orxonox::Degree"; break; 156 156 default: … … 159 159 } 160 160 161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_ char) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_ uchar) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_ short) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_ ushort) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_ int) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_ uint) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_ long) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_ ulong) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_ longlong) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_ ulonglong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_ float) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_ double) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_ longdouble) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_ bool) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_ void) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_ string) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } /** @brief Returns the current value, converted to the requested type. */177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_ vector2) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } /** @brief Returns the current value, converted to the requested type. */178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_ vector3) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } /** @brief Returns the current value, converted to the requested type. */179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_ vector4) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } /** @brief Returns the current value, converted to the requested type. */180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_ colourvalue) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } /** @brief Returns the current value, converted to the requested type. */181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_ quaternion) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } /** @brief Returns the current value, converted to the requested type. */182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_ radian) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } /** @brief Returns the current value, converted to the requested type. */183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_ degree) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } /** @brief Returns the current value, converted to the requested type. */184 185 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. */186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_ uchar); } /** @brief Creates a new value container for the given type. */187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_ short); } /** @brief Creates a new value container for the given type. */188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_ ushort); } /** @brief Creates a new value container for the given type. */189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_ int); } /** @brief Creates a new value container for the given type. */190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_ uint); } /** @brief Creates a new value container for the given type. */191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_ long); } /** @brief Creates a new value container for the given type. */192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_ ulong); } /** @brief Creates a new value container for the given type. */193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_ longlong); } /** @brief Creates a new value container for the given type. */194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_ ulonglong); } /** @brief Creates a new value container for the given type. */195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_ float); } /** @brief Creates a new value container for the given type. */196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_ double); } /** @brief Creates a new value container for the given type. */197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_ longdouble); } /** @brief Creates a new value container for the given type. */198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_ bool); } /** @brief Creates a new value container for the given type. */199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_ void); } /** @brief Creates a new value container for the given type. */200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_ string); } /** @brief Creates a new value container for the given type. */201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_ vector2); } /** @brief Creates a new value container for the given type. */202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_ vector3); } /** @brief Creates a new value container for the given type. */203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_ vector4); } /** @brief Creates a new value container for the given type. */204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_ colourvalue); } /** @brief Creates a new value container for the given type. */205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_ quaternion); } /** @brief Creates a new value container for the given type. */206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_ radian); } /** @brief Creates a new value container for the given type. */207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_ degree); } /** @brief Creates a new value container for the given type. */161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } /** @brief Returns the current value, converted to the requested type. */ 177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } /** @brief Returns the current value, converted to the requested type. */ 178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } /** @brief Returns the current value, converted to the requested type. */ 179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } /** @brief Returns the current value, converted to the requested type. */ 180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } /** @brief Returns the current value, converted to the requested type. */ 181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } /** @brief Returns the current value, converted to the requested type. */ 182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } /** @brief Returns the current value, converted to the requested type. */ 183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } /** @brief Returns the current value, converted to the requested type. */ 184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } /** @brief Creates a new value container for the given type. */ 186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } /** @brief Creates a new value container for the given type. */ 187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } /** @brief Creates a new value container for the given type. */ 188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } /** @brief Creates a new value container for the given type. */ 189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } /** @brief Creates a new value container for the given type. */ 190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } /** @brief Creates a new value container for the given type. */ 191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } /** @brief Creates a new value container for the given type. */ 192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } /** @brief Creates a new value container for the given type. */ 193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } /** @brief Creates a new value container for the given type. */ 194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } /** @brief Creates a new value container for the given type. */ 195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } /** @brief Creates a new value container for the given type. */ 196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } /** @brief Creates a new value container for the given type. */ 197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } /** @brief Creates a new value container for the given type. */ 198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } /** @brief Creates a new value container for the given type. */ 199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } /** @brief Creates a new value container for the given type. */ 200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } /** @brief Creates a new value container for the given type. */ 201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } /** @brief Creates a new value container for the given type. */ 202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } /** @brief Creates a new value container for the given type. */ 203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } /** @brief Creates a new value container for the given type. */ 204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } /** @brief Creates a new value container for the given type. */ 205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } /** @brief Creates a new value container for the given type. */ 206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } /** @brief Creates a new value container for the given type. */ 207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } /** @brief Creates a new value container for the given type. */ 208 208 } -
code/trunk/src/util/MultiType.h
r3241 r3280 84 84 @brief Enum of all possible types of a MultiType. 85 85 */ 86 enumMT_Type86 namespace MT_Type 87 87 { 88 MT_null=0, 89 MT_char=1, 90 MT_uchar=2, 91 MT_short=3, 92 MT_ushort=4, 93 MT_int=5, 94 MT_uint=6, 95 MT_long=7, 96 MT_ulong=8, 97 MT_longlong=9, 98 MT_ulonglong=10, 99 MT_float=11, 100 MT_double=12, 101 MT_longdouble=13, 102 MT_bool=14, 103 MT_void=15, 104 MT_string=16, 105 MT_vector2=17, 106 MT_vector3=18, 107 MT_vector4=19, 108 MT_colourvalue=20, 109 MT_quaternion=21, 110 MT_radian=22, 111 MT_degree=23 112 }; 88 enum Value 89 { 90 Null, 91 Char, 92 UnsignedChar, 93 Short, 94 UnsignedShort, 95 Int, 96 UnsignedInt, 97 Long, 98 UnsignedLong, 99 LongLong, 100 UnsignedLongLong, 101 Float, 102 Double, 103 LongDouble, 104 Bool, 105 VoidPointer, 106 String, 107 Vector2, 108 Vector3, 109 Vector4, 110 ColourValue, 111 Quaternion, 112 Radian, 113 Degree 114 }; 115 } 113 116 114 117 /** … … 142 145 { 143 146 public: 144 MT_ValueBase(MT_Type type) : type_(type), bHasDefaultValue_(false) {}147 MT_ValueBase(MT_Type::Value type) : type_(type), bHasDefaultValue_(false) {} 145 148 virtual ~MT_ValueBase() {} 146 149 … … 151 154 152 155 /** @brief Returns the type of the current value. */ 153 const MT_Type & getType() const { return this->type_; }156 const MT_Type::Value& getType() const { return this->type_; } 154 157 155 158 /** @brief Checks whether the value is a default one. */ … … 234 237 virtual uint8_t getSize() const=0; 235 238 236 MT_Type type_;//!< The type of the current value239 MT_Type::Value type_; //!< The type of the current value 237 240 bool bHasDefaultValue_; //!< True if the last conversion wasn't successful 238 241 }; … … 265 268 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } /** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */ 266 269 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } /** @brief Copyconstructor: Assigns value and type of the other MultiType. */ 267 inline MultiType(MT_Type type): value_(0) { this->setType(type); } /** @brief Constructor: Sets the type, the next assignment will determine the value. */270 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } /** @brief Constructor: Sets the type, the next assignment will determine the value. */ 268 271 269 272 /** @brief Destructor: Deletes the MT_Value. */ … … 273 276 template <typename V> inline const MultiType& operator=(V* value) { this->setValue(value); return (*this); } /** @brief Assigns a pointer. */ 274 277 inline const MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } /** @brief Assigns the value of the other MultiType and converts it to the current type of the MultiType. */ 275 inline const MultiType& operator=(MT_Type type){ this->setType(type); return (*this); } /** @brief Resets the value and changes the type. */278 inline const MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } /** @brief Resets the value and changes the type. */ 276 279 277 280 inline bool setValue(const char& value); … … 312 315 template <typename T> inline bool convert() { return this->setValue<T>((T)(*this)); } /** @brief Converts the current value to type T. */ 313 316 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 314 bool convert(MT_Type type);315 316 /** @brief Current content gets deleted. New type is MT_ null */317 bool convert(MT_Type::Value type); 318 319 /** @brief Current content gets deleted. New type is MT_Type::Null */ 317 320 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 318 321 /** @brief Current content gets overridden with default zero value */ … … 321 324 template <typename T> inline void setType() { this->assignValue(typename TypeStripper<T>::RawType()); } /** @brief Resets the value and changes the internal type to T. */ 322 325 inline void setType(const MultiType& other) { this->setType(other.getType()); } /** @brief Resets the value and changes the internal type to the type of the other MultiType. */ 323 inline void setType(MT_Type type){ this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */326 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */ 324 327 325 328 /** @brief Returns the current type. */ 326 inline MT_Type getType() const { return (this->value_) ? this->value_->type_ : MT_null; }329 inline MT_Type::Value getType() const { return (this->value_) ? this->value_->type_ : MT_Type::Null; } 327 330 /** @brief Returns true if the current type equals the given type. */ 328 inline bool isType(MT_Type type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_null); }331 inline bool isType(MT_Type::Value type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_Type::Null); } 329 332 /** @brief Returns true if the current type is T. */ 330 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below331 std::string getTypename() const;333 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 334 std::string getTypename() const; 332 335 333 336 /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */ 334 inline void exportData(uint8_t*& mem) const { assert(sizeof(MT_Type )<=8); *(uint8_t*)(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); }337 inline void exportData(uint8_t*& mem) const { assert(sizeof(MT_Type::Value)<=8); *(uint8_t*)(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); } 335 338 /** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */ 336 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type )<=8); this->setType(static_cast<MT_Type>(*(uint8_t*)mem)); mem+=sizeof(uint8_t); this->value_->importData(mem); }339 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type::Value)<=8); this->setType(static_cast<MT_Type::Value>(*(uint8_t*)mem)); mem+=sizeof(uint8_t); this->value_->importData(mem); } 337 340 /** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */ 338 341 inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; } … … 420 423 421 424 private: 422 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. */423 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. */424 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. */425 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. */426 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. */427 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. */428 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. */429 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. */430 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. */431 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. */432 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. */433 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. */434 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. */435 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. */436 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. */437 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. */438 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. */439 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. */440 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. */441 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. */442 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. */443 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. */444 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. */425 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 426 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { 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. */ 427 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 428 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { 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. */ 429 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 430 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { 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. */ 431 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 432 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { 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. */ 433 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 434 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { 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. */ 435 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 436 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 437 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 438 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 439 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { 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. */ 440 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 441 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 442 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 443 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 444 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 445 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 446 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 447 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::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. */ 445 448 446 449 /** @brief Changes the value container. */ … … 455 458 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 456 459 457 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_ char);} /** @brief Returns true if the current type equals the given type. */458 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_ uchar);} /** @brief Returns true if the current type equals the given type. */459 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_ short);} /** @brief Returns true if the current type equals the given type. */460 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_ ushort);} /** @brief Returns true if the current type equals the given type. */461 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_ int);} /** @brief Returns true if the current type equals the given type. */462 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_ uint);} /** @brief Returns true if the current type equals the given type. */463 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_ long);} /** @brief Returns true if the current type equals the given type. */464 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_ ulong);} /** @brief Returns true if the current type equals the given type. */465 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_ longlong);} /** @brief Returns true if the current type equals the given type. */466 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_ ulonglong);} /** @brief Returns true if the current type equals the given type. */467 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_ float);} /** @brief Returns true if the current type equals the given type. */468 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_ double);} /** @brief Returns true if the current type equals the given type. */469 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_ longdouble);} /** @brief Returns true if the current type equals the given type. */470 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_ bool);} /** @brief Returns true if the current type equals the given type. */471 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_ void);} /** @brief Returns true if the current type equals the given type. */472 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_ string);} /** @brief Returns true if the current type equals the given type. */473 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_ vector2);} /** @brief Returns true if the current type equals the given type. */474 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_ vector3);} /** @brief Returns true if the current type equals the given type. */475 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_ vector4);} /** @brief Returns true if the current type equals the given type. */476 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_ colourvalue);} /** @brief Returns true if the current type equals the given type. */477 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_ quaternion);} /** @brief Returns true if the current type equals the given type. */478 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_ radian);} /** @brief Returns true if the current type equals the given type. */479 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_ degree);} /** @brief Returns true if the current type equals the given type. */460 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } /** @brief Returns true if the current type equals the given type. */ 461 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } /** @brief Returns true if the current type equals the given type. */ 462 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } /** @brief Returns true if the current type equals the given type. */ 463 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } /** @brief Returns true if the current type equals the given type. */ 464 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } /** @brief Returns true if the current type equals the given type. */ 465 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } /** @brief Returns true if the current type equals the given type. */ 466 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } /** @brief Returns true if the current type equals the given type. */ 467 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } /** @brief Returns true if the current type equals the given type. */ 468 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } /** @brief Returns true if the current type equals the given type. */ 469 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } /** @brief Returns true if the current type equals the given type. */ 470 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } /** @brief Returns true if the current type equals the given type. */ 471 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } /** @brief Returns true if the current type equals the given type. */ 472 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } /** @brief Returns true if the current type equals the given type. */ 473 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } /** @brief Returns true if the current type equals the given type. */ 474 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } /** @brief Returns true if the current type equals the given type. */ 475 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } /** @brief Returns true if the current type equals the given type. */ 476 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } /** @brief Returns true if the current type equals the given type. */ 477 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } /** @brief Returns true if the current type equals the given type. */ 478 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } /** @brief Returns true if the current type equals the given type. */ 479 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } /** @brief Returns true if the current type equals the given type. */ 480 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } /** @brief Returns true if the current type equals the given type. */ 481 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } /** @brief Returns true if the current type equals the given type. */ 482 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } /** @brief Returns true if the current type equals the given type. */ 480 483 481 484 // Specialization to avoid ambiguities with the conversion operator -
code/trunk/src/util/MultiTypeValue.h
r3196 r3280 54 54 public: 55 55 /** @brief Constructor: Assigns the value and the type identifier. */ 56 MT_Value(const T& value, MT_Type type) : MT_ValueBase(type), value_(value) {}56 MT_Value(const T& value, MT_Type::Value type) : MT_ValueBase(type), value_(value) {} 57 57 58 58 /** @brief Creates a copy of itself. */ … … 139 139 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 140 140 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 141 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. */142 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. */143 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. */144 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. */145 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. */146 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. */147 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. */148 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. */141 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } /** @brief Returns the current value, converted to the requested type. */ 142 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } /** @brief Returns the current value, converted to the requested type. */ 143 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } /** @brief Returns the current value, converted to the requested type. */ 144 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } /** @brief Returns the current value, converted to the requested type. */ 145 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } /** @brief Returns the current value, converted to the requested type. */ 146 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } /** @brief Returns the current value, converted to the requested type. */ 147 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } /** @brief Returns the current value, converted to the requested type. */ 148 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } /** @brief Returns the current value, converted to the requested type. */ 149 149 150 150 /** @brief Puts the current value on the stream */ -
code/trunk/src/util/StringUtils.cc
r3251 r3280 44 44 std::string getUniqueNumberString() 45 45 { 46 return convertToString(getUniqueNumber());46 return multi_cast<std::string>(getUniqueNumber()); 47 47 } 48 48 -
code/trunk/src/util/UtilPrereqs.h
r3196 r3280 60 60 // Forward declarations 61 61 //----------------------------------------------------------------------- 62 63 namespace orxonox 64 { 65 class Exception; 66 class ExprParser; 67 class IntVector2; 68 class IntVector3; 69 class MultiType; 70 class OutputBuffer; 71 class OutputBufferListener; 72 class OutputHandler; 73 class SignalHandler; 74 class SubString; 75 } 76 62 77 namespace Ogre 63 78 { … … 72 87 class ColourValue; 73 88 } 74 75 89 namespace orxonox 76 90 { … … 84 98 using Ogre::Quaternion; 85 99 using Ogre::ColourValue; 100 } 86 101 87 class Exception; 88 class ExprParser; 89 class IntVector2; 90 class IntVector3; 91 class MultiType; 92 class OutputBuffer; 93 class OutputBufferListener; 94 class OutputHandler; 95 class SignalHandler; 96 class SubString; 102 namespace Loki 103 { 104 class ScopeGuardImplBase; 105 typedef const ScopeGuardImplBase& ScopeGuard; 97 106 } 98 107
Note: See TracChangeset
for help on using the changeset viewer.