Changeset 1726
- Timestamp:
- Sep 7, 2008, 2:55:22 AM (16 years ago)
- Location:
- code/branches/core3/src/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/util/MultiType.cc
r1722 r1726 30 30 #include "MultiTypeValue.h" 31 31 32 void MultiType:: setType(MT_Type type)32 void MultiType::convert(MT_Type type) 33 33 { 34 34 switch (type) 35 35 { 36 36 case MT_char: 37 this-> setType<char>(); break;37 this->convert<char>(); break; 38 38 case MT_uchar: 39 this-> setType<unsigned char>(); break;39 this->convert<unsigned char>(); break; 40 40 case MT_short: 41 this-> setType<short>(); break;41 this->convert<short>(); break; 42 42 case MT_ushort: 43 this-> setType<unsigned short>(); break;43 this->convert<unsigned short>(); break; 44 44 case MT_int: 45 this-> setType<int>(); break;45 this->convert<int>(); break; 46 46 case MT_uint: 47 this-> setType<unsigned int>(); break;47 this->convert<unsigned int>(); break; 48 48 case MT_long: 49 this-> setType<long>(); break;49 this->convert<long>(); break; 50 50 case MT_ulong: 51 this-> setType<unsigned long>(); break;51 this->convert<unsigned long>(); break; 52 52 case MT_longlong: 53 this-> setType<long long>(); break;53 this->convert<long long>(); break; 54 54 case MT_ulonglong: 55 this-> setType<unsigned long long>(); break;55 this->convert<unsigned long long>(); break; 56 56 case MT_float: 57 this-> setType<float>(); break;57 this->convert<float>(); break; 58 58 case MT_double: 59 this-> setType<double>(); break;59 this->convert<double>(); break; 60 60 case MT_longdouble: 61 this-> setType<long double>(); break;61 this->convert<long double>(); break; 62 62 case MT_bool: 63 this-> setType<bool>(); break;63 this->convert<bool>(); break; 64 64 case MT_void: 65 this-> setType<void*>(); break;65 this->convert<void*>(); break; 66 66 case MT_string: 67 this-> setType<std::string>(); break;67 this->convert<std::string>(); break; 68 68 case MT_vector2: 69 this-> setType<orxonox::Vector2>(); break;69 this->convert<orxonox::Vector2>(); break; 70 70 case MT_vector3: 71 this-> setType<orxonox::Vector3>(); break;71 this->convert<orxonox::Vector3>(); break; 72 72 case MT_vector4: 73 this-> setType<orxonox::Vector4>(); break;73 this->convert<orxonox::Vector4>(); break; 74 74 case MT_colourvalue: 75 this-> setType<orxonox::ColourValue>(); break;75 this->convert<orxonox::ColourValue>(); break; 76 76 case MT_quaternion: 77 this-> setType<orxonox::Quaternion>(); break;77 this->convert<orxonox::Quaternion>(); break; 78 78 case MT_radian: 79 this-> setType<orxonox::Radian>(); break;79 this->convert<orxonox::Radian>(); break; 80 80 case MT_degree: 81 this-> setType<orxonox::Degree>(); break;81 this->convert<orxonox::Degree>(); break; 82 82 default: 83 83 this->reset(); break; -
code/branches/core3/src/util/MultiType.h
r1722 r1726 82 82 virtual MT_ValueBase* clone() const = 0; 83 83 84 virtual void reset() = 0; 85 virtual void assimilate(const MultiType& other) = 0; 84 86 const MT_Type& getType() const { return this->type_; } 85 87 … … 162 164 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } 163 165 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } 166 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } 164 167 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } 165 168 inline MultiType(MT_Type type) : value_(0) { this->setType(type); } … … 167 170 inline ~MultiType() { if (this->value_) { delete this->value_; } } 168 171 169 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); 170 inline MultiType& operator=(const MultiType& other) { this->setValue(other); 171 inline MultiType& operator=(MT_Type type) { this->setType(type); 172 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 173 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 174 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 172 175 173 176 inline void setValue(const char& value); … … 195 198 inline void setValue(const orxonox::Degree& value); 196 199 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); }200 void setValue(const MultiType& other) { if (this->value_) { this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } } } 201 template <typename T, typename V> inline void setValue(const V& value) { this->setType<T>(); this->setValue(value); } 199 202 inline void setValue(const char* value); 200 203 201 template <typename T> inline void convert() { this->setValue<T>((T)(*this)); } 202 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()); } 207 void setType(MT_Type type); 204 inline void copy(const MultiType& other) { if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 205 206 template <typename T> inline void convert() { this->setValue<T>((T)(*this)); } 207 inline void convert(const MultiType& other) { this->convert(other.getType()); } 208 void convert(MT_Type type); 209 210 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } } 211 212 template <typename T> inline void setType() { this->assignValue(T()); } 213 inline void setType(const MultiType& other) { this->setType(other.getType()); } 214 inline void setType(MT_Type type) { this->reset(); this->convert(type); } 208 215 209 216 operator char() const; … … 376 383 inline void MultiType::setValue(const long double& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 377 384 inline void MultiType::setValue(const bool& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 385 inline void MultiType::setValue( void* const& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 378 386 inline void MultiType::setValue(const std::string& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 379 387 inline void MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } -
code/branches/core3/src/util/MultiTypeValue.h
r1722 r1726 40 40 41 41 inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); } 42 inline void reset() { this->value_ = T(); } 43 inline void assimilate(const MultiType& other) { if (other.value_) { this->value_ = other.operator T(); } else { this->value_ = T(); } } 42 44 43 45 inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); }
Note: See TracChangeset
for help on using the changeset viewer.