Changeset 9226 for code/branches/testing/src
- Timestamp:
- May 20, 2012, 12:52:15 AM (13 years ago)
- Location:
- code/branches/testing/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/MultiType.h
r9225 r9226 174 174 { 175 175 public: 176 MT_ValueBase(void* data, Type::Enum type) : type_(type), bHasDefaultValue_(false), data_(data) {}177 virtual ~MT_ValueBase() {}176 inline MT_ValueBase(void* data, Type::Enum type) : type_(type), bLastConversionSuccessful(true), data_(data) {} 177 inline virtual ~MT_ValueBase() {} 178 178 179 179 virtual MT_ValueBase* clone() const = 0; … … 182 182 183 183 /// Returns the type of the current value. 184 const Type::Enum& getType() const { return this->type_; }184 inline const Type::Enum& getType() const { return this->type_; } 185 185 /// Returns true if the type of the stored value is T. 186 186 template <typename T> inline bool isType() const { return false; } 187 187 188 188 /// Checks whether the value is a default one. 189 bool hasDefaultValue() const { return this->bHasDefaultValue_; }189 inline bool lastConversionSuccessful() const { return this->bLastConversionSuccessful; } 190 190 191 191 virtual bool setValue(const char& value) = 0; … … 253 253 virtual void toString(std::ostream& outstream) const = 0; 254 254 255 virtual void importData( uint8_t*& mem )=0;256 virtual void exportData( uint8_t*& mem ) const=0;257 virtual uint8_t getSize() const =0;258 259 Type::Enum type_; ///< The type of the current value260 bool b HasDefaultValue_; ///< True if the last conversion wasn'tsuccessful261 void* data_; ///< For direct access to the value if the type is known255 virtual void importData(uint8_t*& mem) = 0; 256 virtual void exportData(uint8_t*& mem) const = 0; 257 virtual uint8_t getSize() const = 0; 258 259 Type::Enum type_; ///< The type of the current value 260 bool bLastConversionSuccessful; ///< True if the last conversion was successful 261 void* data_; ///< For direct access to the value if the type is known 262 262 }; 263 263 … … 329 329 330 330 /// Converts the current value to type T. 331 template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); } 331 template <typename T> inline bool convert() { return this->force<T>(MultiType(*this)); } 332 // template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); } 332 333 333 334 /// Resets value and type. Type will be void afterwards and null() returns true. … … 342 343 std::string getTypename() const; 343 344 344 /// Checks whether the value is a default one (assigned after a failed conversion)345 inline bool hasDefaultValue() const { return this->value_->hasDefaultValue(); }345 /// Checks whether the last conversion was successful 346 inline bool lastConversionSuccessful() const { return !this->value_ || this->value_->lastConversionSuccessful(); } 346 347 347 348 /// Checks if the MT contains no value. -
code/branches/testing/src/libraries/util/MultiTypeValue.h
r9225 r9226 61 61 62 62 /// Resets the current value to the default. 63 inline void reset() { this->value_ = zeroise<T>(); b HasDefaultValue_= true; }63 inline void reset() { this->value_ = zeroise<T>(); bLastConversionSuccessful = true; } 64 64 65 65 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. … … 95 95 if (other.value_) 96 96 { 97 return !(bHasDefaultValue_ = !other.value_->getValue(&value_));97 return (this->bLastConversionSuccessful = other.value_->getValue(&value_)); 98 98 } 99 99 else 100 100 { 101 101 this->value_ = zeroise<T>(); 102 return !(bHasDefaultValue_ = true);102 return (bLastConversionSuccessful = false); 103 103 } 104 104 } 105 105 106 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.107 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.108 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.109 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.110 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.111 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.112 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.113 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.114 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.115 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.116 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.117 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.118 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.119 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.120 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.121 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.122 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.123 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.124 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.125 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.126 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.127 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.128 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.106 inline bool setValue(const char& value) { return (bLastConversionSuccessful = convertValue<char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 107 inline bool setValue(const unsigned char& value) { return (bLastConversionSuccessful = convertValue<unsigned char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 108 inline bool setValue(const short& value) { return (bLastConversionSuccessful = convertValue<short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 109 inline bool setValue(const unsigned short& value) { return (bLastConversionSuccessful = convertValue<unsigned short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 110 inline bool setValue(const int& value) { return (bLastConversionSuccessful = convertValue<int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 111 inline bool setValue(const unsigned int& value) { return (bLastConversionSuccessful = convertValue<unsigned int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 112 inline bool setValue(const long& value) { return (bLastConversionSuccessful = convertValue<long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 113 inline bool setValue(const unsigned long& value) { return (bLastConversionSuccessful = convertValue<unsigned long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 114 inline bool setValue(const long long& value) { return (bLastConversionSuccessful = convertValue<long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 115 inline bool setValue(const unsigned long long& value) { return (bLastConversionSuccessful = convertValue<unsigned long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 116 inline bool setValue(const float& value) { return (bLastConversionSuccessful = convertValue<float , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 117 inline bool setValue(const double& value) { return (bLastConversionSuccessful = convertValue<double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 118 inline bool setValue(const long double& value) { return (bLastConversionSuccessful = convertValue<long double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 119 inline bool setValue(const bool& value) { return (bLastConversionSuccessful = convertValue<bool , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 120 inline bool setValue( void* const& value) { return (bLastConversionSuccessful = convertValue<void* , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 121 inline bool setValue(const std::string& value) { return (bLastConversionSuccessful = convertValue<std::string , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 122 inline bool setValue(const orxonox::Vector2& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector2 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 123 inline bool setValue(const orxonox::Vector3& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector3 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 124 inline bool setValue(const orxonox::Vector4& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector4 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 125 inline bool setValue(const orxonox::ColourValue& value) { return (bLastConversionSuccessful = convertValue<orxonox::ColourValue, T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 126 inline bool setValue(const orxonox::Quaternion& value) { return (bLastConversionSuccessful = convertValue<orxonox::Quaternion , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 127 inline bool setValue(const orxonox::Radian& value) { return (bLastConversionSuccessful = convertValue<orxonox::Radian , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 128 inline bool setValue(const orxonox::Degree& value) { return (bLastConversionSuccessful = convertValue<orxonox::Degree , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 129 129 130 130 /// Puts the current value on the stream
Note: See TracChangeset
for help on using the changeset viewer.