Changeset 9223 for code/branches/testing/src/libraries
- Timestamp:
- May 19, 2012, 11:35:32 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/MultiType.h
r9222 r9223 58 58 If you want to change the type, there are three possibilities: 59 59 - @ref orxonox::MultiType::convert "convert<T>()" sets the type to T and converts the currently assigned value 60 - @ref orxonox::MultiType:: setType "setType<T>()" sets the type to T and resets the value to zero using zeroise<T>()60 - @ref orxonox::MultiType::reset "reset<T>()" sets the type to T and resets the value to zero using zeroise<T>() 61 61 - setValue<T>(value) assigns a new value and changes the type to T. 62 62 … … 339 339 return this->assignValue (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 340 340 } 341 /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). 342 template <typename T, typename V> inline bool setValue(const V& value) { this->reset<T>(); return this->setValue(value); } 341 343 /// Assigns the value of the other MultiType and converts it to the current type. 342 344 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 343 /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted).344 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); }345 346 345 347 346 /// Copies the other MultiType by assigning value and type. … … 353 352 /// Resets value and type. Type will be void afterwards and null() returns true. 354 353 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 355 /// Current content gets overridden with default zero value 354 /// Resets the value and changes the internal type to T. 355 template <typename T> inline void reset() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } 356 /// Current value gets overridden with default zero value 356 357 inline void resetValue() { if (this->value_) this->value_->reset(); } 357 358 /// Resets the value and changes the internal type to T.359 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); }360 358 361 359 /// Returns true if the current type is T. … … 377 375 378 376 /// Checks if the MT contains no value. 379 bool null() const { return (!this->value_); }377 bool null() const { return !this->value_; } 380 378 381 379 operator char() const; … … 497 495 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 498 496 499 template <> inline bool MultiType::isType<void>() const { return this->null(); 497 template <> inline bool MultiType::isType<void>() const { return this->null(); } ///< Returns true if the current type equals the given type. 500 498 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == Type::Char); } ///< Returns true if the current type equals the given type. 501 499 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == Type::UnsignedChar); } ///< Returns true if the current type equals the given type.
Note: See TracChangeset
for help on using the changeset viewer.