Changeset 1722
- Timestamp:
- Sep 6, 2008, 7:34:49 PM (16 years ago)
- Location:
- code/branches/core3/src/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/util/MultiType.cc
r1720 r1722 87 87 std::string MultiType::getTypename() const 88 88 { 89 switch (this->type_) 89 MT_Type type = (this->value_) ? this->value_->type_ : MT_null; 90 91 switch (type) 90 92 { 91 93 case MT_char: … … 140 142 } 141 143 142 MultiType::operator char() const { return (this-> type_ == MT_char ) ? ((MT_Value<char> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }143 MultiType::operator unsigned char() const { return (this-> type_ == MT_uchar ) ? ((MT_Value<unsigned char> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }144 MultiType::operator short() const { return (this-> type_ == MT_short ) ? ((MT_Value<short> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }145 MultiType::operator unsigned short() const { return (this-> type_ == MT_ushort ) ? ((MT_Value<unsigned short> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }146 MultiType::operator int() const { return (this-> type_ == MT_int ) ? ((MT_Value<int> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }147 MultiType::operator unsigned int() const { return (this-> type_ == MT_uint ) ? ((MT_Value<unsigned int> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }148 MultiType::operator long() const { return (this-> type_ == MT_long ) ? ((MT_Value<long> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }149 MultiType::operator unsigned long() const { return (this-> type_ == MT_ulong ) ? ((MT_Value<unsigned long> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }150 MultiType::operator long long() const { return (this-> type_ == MT_longlong ) ? ((MT_Value<long long> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }151 MultiType::operator unsigned long long() const { return (this-> type_ == MT_ulonglong ) ? ((MT_Value<unsigned long long> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }152 MultiType::operator float() const { return (this-> type_ == MT_float ) ? ((MT_Value<float> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }153 MultiType::operator double() const { return (this-> type_ == MT_double ) ? ((MT_Value<double> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }154 MultiType::operator long double() const { return (this-> type_ == MT_longdouble ) ? ((MT_Value<long double> *)this->value_)->value_ : (this->value_) ? (*this->value_) : 0; }155 MultiType::operator bool() const { return (this-> type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (this->value_) ? (*this->value_) : false; }156 MultiType::operator void*() const { return (this-> type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (this->value_) ? (*this->value_) : (void*)0; }157 MultiType::operator std::string() const { return (this-> type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (this->value_) ? (*this->value_) : std::string(); }158 MultiType::operator orxonox::Vector2() const { return (this-> type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Vector2(); }159 MultiType::operator orxonox::Vector3() const { return (this-> type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Vector3(); }160 MultiType::operator orxonox::Vector4() const { return (this-> type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Vector4(); }161 MultiType::operator orxonox::ColourValue() const { return (this-> type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::ColourValue(); }162 MultiType::operator orxonox::Quaternion() const { return (this-> type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Quaternion(); }163 MultiType::operator orxonox::Radian() const { return (this-> type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Radian(); }164 MultiType::operator orxonox::Degree() const { return (this-> type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (this->value_) ? (*this->value_) : orxonox::Degree(); }144 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_char ) ? ((MT_Value<char> *)this->value_)->value_ : (*this->value_)) : 0; } 145 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_uchar ) ? ((MT_Value<unsigned char> *)this->value_)->value_ : (*this->value_)) : 0; } 146 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_short ) ? ((MT_Value<short> *)this->value_)->value_ : (*this->value_)) : 0; } 147 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_ushort ) ? ((MT_Value<unsigned short> *)this->value_)->value_ : (*this->value_)) : 0; } 148 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_int ) ? ((MT_Value<int> *)this->value_)->value_ : (*this->value_)) : 0; } 149 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_uint ) ? ((MT_Value<unsigned int> *)this->value_)->value_ : (*this->value_)) : 0; } 150 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_long ) ? ((MT_Value<long> *)this->value_)->value_ : (*this->value_)) : 0; } 151 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_ulong ) ? ((MT_Value<unsigned long> *)this->value_)->value_ : (*this->value_)) : 0; } 152 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_longlong ) ? ((MT_Value<long long> *)this->value_)->value_ : (*this->value_)) : 0; } 153 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_ulonglong ) ? ((MT_Value<unsigned long long> *)this->value_)->value_ : (*this->value_)) : 0; } 154 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_float ) ? ((MT_Value<float> *)this->value_)->value_ : (*this->value_)) : 0; } 155 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_double ) ? ((MT_Value<double> *)this->value_)->value_ : (*this->value_)) : 0; } 156 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_longdouble ) ? ((MT_Value<long double> *)this->value_)->value_ : (*this->value_)) : 0; } 157 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : false; } 158 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : (void*)0; } 159 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : std::string(); } 160 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector2(); } 161 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector3(); } 162 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector4(); } 163 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : orxonox::ColourValue(); } 164 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : orxonox::Quaternion(); } 165 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : orxonox::Radian(); } 166 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : orxonox::Degree(); } 165 167 166 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value ); }167 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value ); }168 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value ); }169 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value ); }170 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value ); }171 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value ); }172 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value ); }173 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value ); }174 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value ); }175 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value ); }176 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value ); }177 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value ); }178 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value ); }179 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value ); }180 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value ); }181 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value ); }182 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value ); }183 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value ); }184 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value ); }185 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value ); }186 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value ); }187 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value ); }188 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value ); }168 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_char ); } 169 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_uchar ); } 170 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_short ); } 171 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_ushort ); } 172 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_int ); } 173 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_uint ); } 174 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_long ); } 175 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_ulong ); } 176 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_longlong ); } 177 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_ulonglong ); } 178 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_float ); } 179 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_double ); } 180 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_longdouble ); } 181 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_bool ); } 182 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_void ); } 183 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_string ); } 184 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_vector2 ); } 185 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_vector3 ); } 186 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_vector4 ); } 187 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_colourvalue); } 188 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_quaternion ); } 189 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_radian ); } 190 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_degree ); } -
code/branches/core3/src/util/MultiType.h
r1720 r1722 77 77 struct _UtilExport MT_ValueBase 78 78 { 79 MT_ValueBase(MT_Type type) : type_(type) {} 79 80 virtual ~MT_ValueBase() {} 80 81 81 82 virtual MT_ValueBase* clone() const = 0; 83 84 const MT_Type& getType() const { return this->type_; } 82 85 83 86 virtual void setValue(const char& value) = 0; … … 130 133 131 134 virtual void toString(std::ostream& outstream) const = 0; 135 136 MT_Type type_; 132 137 }; 133 138 134 139 public: 135 inline MultiType() : value_(0), type_(MT_null) {} 136 inline MultiType(const char& value) : value_(0), type_(MT_null) { this->assignValue(value); } 137 inline MultiType(const unsigned char& value) : value_(0), type_(MT_null) { this->assignValue(value); } 138 inline MultiType(const short& value) : value_(0), type_(MT_null) { this->assignValue(value); } 139 inline MultiType(const unsigned short& value) : value_(0), type_(MT_null) { this->assignValue(value); } 140 inline MultiType(const int& value) : value_(0), type_(MT_null) { this->assignValue(value); } 141 inline MultiType(const unsigned int& value) : value_(0), type_(MT_null) { this->assignValue(value); } 142 inline MultiType(const long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 143 inline MultiType(const unsigned long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 144 inline MultiType(const long long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 145 inline MultiType(const unsigned long long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 146 inline MultiType(const float& value) : value_(0), type_(MT_null) { this->assignValue(value); } 147 inline MultiType(const double& value) : value_(0), type_(MT_null) { this->assignValue(value); } 148 inline MultiType(const long double& value) : value_(0), type_(MT_null) { this->assignValue(value); } 149 inline MultiType(const bool& value) : value_(0), type_(MT_null) { this->assignValue(value); } 150 inline MultiType( void* const& value) : value_(0), type_(MT_null) { this->assignValue(value); } 151 inline MultiType(const std::string& value) : value_(0), type_(MT_null) { this->assignValue(value); } 152 inline MultiType(const orxonox::Vector2& value) : value_(0), type_(MT_null) { this->assignValue(value); } 153 inline MultiType(const orxonox::Vector3& value) : value_(0), type_(MT_null) { this->assignValue(value); } 154 inline MultiType(const orxonox::Vector4& value) : value_(0), type_(MT_null) { this->assignValue(value); } 155 inline MultiType(const orxonox::ColourValue& value) : value_(0), type_(MT_null) { this->assignValue(value); } 156 inline MultiType(const orxonox::Quaternion& value) : value_(0), type_(MT_null) { this->assignValue(value); } 157 inline MultiType(const orxonox::Radian& value) : value_(0), type_(MT_null) { this->assignValue(value); } 158 inline MultiType(const orxonox::Degree& value) : value_(0), type_(MT_null) { this->assignValue(value); } 159 inline MultiType(const MultiType& other) : value_(0), type_(MT_null) { this->setValue(other); } 160 inline MultiType(MT_Type type) : value_(0), type_(MT_null) { this->setType(type); } 161 ~MultiType() { if (this->value_) { delete this->value_; } } 162 163 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 164 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 165 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 140 inline MultiType() : value_(0) {} 141 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } 142 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } 143 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } 144 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } 145 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } 146 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } 147 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } 148 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } 149 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } 150 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } 151 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } 152 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } 153 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } 154 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } 155 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } 156 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } 157 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } 158 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } 159 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } 160 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } 161 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } 162 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } 163 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } 164 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } 165 inline MultiType(MT_Type type) : value_(0) { this->setType(type); } 166 167 inline ~MultiType() { if (this->value_) { delete this->value_; } } 168 169 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 170 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 171 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 166 172 167 173 inline void setValue(const char& value); … … 188 194 inline void setValue(const orxonox::Radian& value); 189 195 inline void setValue(const orxonox::Degree& value); 190 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } } 196 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } } 197 inline void setValue(const MultiType& other) { this->value_ = (other.value_) ? other.value_->clone() : 0; } 198 template <typename T, typename V> inline void setValue(const V& value) { this->assignValue((T)value); } 191 199 inline void setValue(const char* value); 192 inline void setValue(const MultiType& other) { this->type_ = other.type_; this->value_ = (other.value_) ? other.value_->clone() : 0; }193 template <typename T, typename V> inline void setValue(const V& value) { this->assignValue((T)value); }194 200 195 201 template <typename T> inline void convert() { this->setValue<T>((T)(*this)); } 196 202 197 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } this->type_ = MT_null;}198 199 template <typename T> inline void setType() { this->assignValue(T()); }200 inline void setType(const MultiType& other) { this->setType(other. type_); }203 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } } 204 205 template <typename T> inline void setType() { this->assignValue(T()); } 206 inline void setType(const MultiType& other) { this->setType(other.getType()); } 201 207 void setType(MT_Type type); 202 208 … … 250 256 inline void getValue(orxonox::Degree* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree(); } } 251 257 252 inline MT_Type getType() const { return this->type_; }253 inline bool isType(MT_Type type) const { return (this-> type_ == type); }258 inline MT_Type getType() const { return (this->value_) ? this->value_->type_ : MT_null; } 259 inline bool isType(MT_Type type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_null); } 254 260 template <typename T> inline bool isType() const { return false; } 255 261 std::string getTypename() const; … … 258 264 259 265 private: 260 inline void assignValue(const char& value) { if (this->value_ && this-> type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value); this->type_ = MT_char;} }261 inline void assignValue(const unsigned char& value) { if (this->value_ && this-> type_ == MT_uchar) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); this->type_ = MT_uchar;} }262 inline void assignValue(const short& value) { if (this->value_ && this-> type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value); this->type_ = MT_short;} }263 inline void assignValue(const unsigned short& value) { if (this->value_ && this-> type_ == MT_ushort) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); this->type_ = MT_ushort;} }264 inline void assignValue(const int& value) { if (this->value_ && this-> type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value); this->type_ = MT_int;} }265 inline void assignValue(const unsigned int& value) { if (this->value_ && this-> type_ == MT_uint) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); this->type_ = MT_uint;} }266 inline void assignValue(const long& value) { if (this->value_ && this-> type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value); this->type_ = MT_long;} }267 inline void assignValue(const unsigned long& value) { if (this->value_ && this-> type_ == MT_ulong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); this->type_ = MT_ulong;} }268 inline void assignValue(const long long& value) { if (this->value_ && this-> type_ == MT_longlong) { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); this->type_ = MT_longlong;} }269 inline void assignValue(const unsigned long long& value) { if (this->value_ && this-> type_ == MT_ulonglong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); this->type_ = MT_ulonglong; } }270 inline void assignValue(const float& value) { if (this->value_ && this-> type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value); this->type_ = MT_float;} }271 inline void assignValue(const double& value) { if (this->value_ && this-> type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value); this->type_ = MT_double;} }272 inline void assignValue(const long double& value) { if (this->value_ && this-> type_ == MT_longdouble) { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); this->type_ = MT_longdouble;} }273 inline void assignValue(const bool& value) { if (this->value_ && this-> type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); this->type_ = MT_bool;} }274 inline void assignValue( void* const& value) { if (this->value_ && this-> type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); this->type_ = MT_void;} }275 inline void assignValue(const std::string& value) { if (this->value_ && this-> type_ == MT_string) { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); this->type_ = MT_string;} }276 inline void assignValue(const orxonox::Vector2& value) { if (this->value_ && this-> type_ == MT_vector2) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); this->type_ = MT_vector2; } }277 inline void assignValue(const orxonox::Vector3& value) { if (this->value_ && this-> type_ == MT_vector3) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); this->type_ = MT_vector3; } }278 inline void assignValue(const orxonox::Vector4& value) { if (this->value_ && this-> type_ == MT_vector4) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); this->type_ = MT_vector4; } }279 inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this-> type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); this->type_ = MT_colourvalue; } }280 inline void assignValue(const orxonox::Quaternion& value) { if (this->value_ && this-> type_ == MT_quaternion) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); this->type_ = MT_quaternion; } }281 inline void assignValue(const orxonox::Radian& value) { if (this->value_ && this-> type_ == MT_radian) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); this->type_ = MT_radian; } }282 inline void assignValue(const orxonox::Degree& value) { if (this->value_ && this-> type_ == MT_degree) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); this->type_ = MT_degree; } }266 inline void assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value); } } 267 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); } } 268 inline void assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value); } } 269 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); } } 270 inline void assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value); } } 271 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); } } 272 inline void assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value); } } 273 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); } } 274 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); } } 275 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); } } 276 inline void assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value); } } 277 inline void assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value); } } 278 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); } } 279 inline void assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); } } 280 inline void assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); } } 281 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); } } 282 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); } } 283 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); } } 284 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); } } 285 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); } } 286 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); } } 287 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); } } 288 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); } } 283 289 284 290 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } … … 286 292 287 293 MT_ValueBase* value_; 288 MT_Type type_;289 294 }; 290 295 291 296 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 292 297 293 template <> inline bool MultiType::isType<char>() const { return (this-> type_ == MT_char); }294 template <> inline bool MultiType::isType<unsigned char>() const { return (this-> type_ == MT_uchar); }295 template <> inline bool MultiType::isType<short>() const { return (this-> type_ == MT_short); }296 template <> inline bool MultiType::isType<unsigned short>() const { return (this-> type_ == MT_ushort); }297 template <> inline bool MultiType::isType<int>() const { return (this-> type_ == MT_int); }298 template <> inline bool MultiType::isType<unsigned int>() const { return (this-> type_ == MT_uint); }299 template <> inline bool MultiType::isType<long>() const { return (this-> type_ == MT_long); }300 template <> inline bool MultiType::isType<unsigned long>() const { return (this-> type_ == MT_ulong); }301 template <> inline bool MultiType::isType<long long>() const { return (this-> type_ == MT_longlong); }302 template <> inline bool MultiType::isType<unsigned long long>() const { return (this-> type_ == MT_ulonglong); }303 template <> inline bool MultiType::isType<float>() const { return (this-> type_ == MT_float); }304 template <> inline bool MultiType::isType<double>() const { return (this-> type_ == MT_double); }305 template <> inline bool MultiType::isType<long double>() const { return (this-> type_ == MT_longdouble); }306 template <> inline bool MultiType::isType<bool>() const { return (this-> type_ == MT_bool); }307 template <> inline bool MultiType::isType<void*>() const { return (this-> type_ == MT_void); }308 template <> inline bool MultiType::isType<std::string>() const { return (this-> type_ == MT_string); }309 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this-> type_ == MT_vector2); }310 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this-> type_ == MT_vector3); }311 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this-> type_ == MT_vector4); }312 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this-> type_ == MT_colourvalue); }313 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this-> type_ == MT_quaternion); }314 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this-> type_ == MT_radian); }315 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this-> type_ == MT_degree); }298 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_char); } 299 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_uchar); } 300 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_short); } 301 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_ushort); } 302 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_int); } 303 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_uint); } 304 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_long); } 305 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_ulong); } 306 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_longlong); } 307 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_ulonglong); } 308 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_float); } 309 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_double); } 310 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_longdouble); } 311 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_bool); } 312 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_void); } 313 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_string); } 314 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_vector2); } 315 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_vector3); } 316 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_vector4); } 317 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_colourvalue); } 318 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_quaternion); } 319 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_radian); } 320 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_degree); } 316 321 317 322 template <> inline void MultiType::convert<std::string>() { this->setValue<std::string> (this->operator std::string()); } … … 379 384 inline void MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 380 385 inline void MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 381 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } } 386 387 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } } 382 388 383 389 -
code/branches/core3/src/util/MultiTypeValue.h
r1720 r1722 37 37 struct MT_Value : public MultiType::MT_ValueBase 38 38 { 39 MT_Value() {} 40 MT_Value(const T& value) : value_(value) {} 39 MT_Value(const T& value, MT_Type type) : MT_ValueBase(type), value_(value) {} 41 40 42 inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_ ); }41 inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); } 43 42 44 43 inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); }
Note: See TracChangeset
for help on using the changeset viewer.