Changeset 9226
- Timestamp:
- May 20, 2012, 12:52:15 AM (13 years ago)
- Location:
- code/branches/testing
- Files:
-
- 3 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 -
code/branches/testing/test/util/MultiTypeTest.cc
r9225 r9226 29 29 // ? getPointer() 30 30 31 // x hasDefaultValue()31 // x lastConversionSuccessful() 32 32 // x null() 33 33 … … 142 142 EXPECT_TRUE(mt.isType<Vector3>()); 143 143 EXPECT_EQ(Vector3(1, 2, 3), mt.get<Vector3>()); 144 EXPECT_ FALSE(mt.hasDefaultValue());144 EXPECT_TRUE(mt.lastConversionSuccessful()); 145 145 146 146 mt = 77.7f; … … 148 148 EXPECT_TRUE(mt.isType<Vector3>()); 149 149 EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>()); 150 EXPECT_ TRUE(mt.hasDefaultValue());150 EXPECT_FALSE(mt.lastConversionSuccessful()); 151 151 } 152 152 … … 254 254 EXPECT_TRUE(mt.isType<int>()); 255 255 EXPECT_EQ(0, mt.get<int>()); 256 257 // EXPECT_TRUE(mt.hasDefaultValue());258 256 } 259 257 … … 287 285 EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>()); 288 286 289 // EXPECT_TRUE(mt.hasDefaultValue());287 EXPECT_FALSE(mt.lastConversionSuccessful()); 290 288 } 291 289 … … 648 646 } 649 647 650 /////////////////////// 651 // hasDefaultValue() //652 /////////////////////// 653 TEST(MultiType, HasDefaultValue)648 //////////////////////////////// 649 // lastConversionSuccessful() // 650 //////////////////////////////// 651 TEST(MultiType, LastConversionSuccessful) 654 652 { 655 653 MultiType mt; 656 654 657 // EXPECT_FALSE(mt.hasDefaultValue());655 EXPECT_TRUE(mt.lastConversionSuccessful()); 658 656 659 657 mt = 5.55; 660 658 661 EXPECT_ FALSE(mt.hasDefaultValue());659 EXPECT_TRUE(mt.lastConversionSuccessful()); 662 660 663 661 mt.convert<int>(); 664 662 665 EXPECT_FALSE(mt.hasDefaultValue()); 666 667 mt.convert<Quaternion>(); 668 669 // EXPECT_TRUE(mt.hasDefaultValue()); 663 EXPECT_TRUE(mt.lastConversionSuccessful()); 664 665 mt.convert<Vector3>(); 666 667 EXPECT_FALSE(mt.lastConversionSuccessful()); 668 669 mt.convert<std::string>(); 670 671 EXPECT_TRUE(mt.lastConversionSuccessful()); 670 672 } 671 673
Note: See TracChangeset
for help on using the changeset viewer.