[Orxonox-commit 4555] r9226 - in code/branches/testing: src/libraries/util test/util
landauf at orxonox.net
landauf at orxonox.net
Sun May 20 00:52:16 CEST 2012
Author: landauf
Date: 2012-05-20 00:52:15 +0200 (Sun, 20 May 2012)
New Revision: 9226
Modified:
code/branches/testing/src/libraries/util/MultiType.h
code/branches/testing/src/libraries/util/MultiTypeValue.h
code/branches/testing/test/util/MultiTypeTest.cc
Log:
changed hasDefaultValue() to lastConversionSuccessful() (inverted meaning) and fixed two issues with this function
Modified: code/branches/testing/src/libraries/util/MultiType.h
===================================================================
--- code/branches/testing/src/libraries/util/MultiType.h 2012-05-19 21:24:18 UTC (rev 9225)
+++ code/branches/testing/src/libraries/util/MultiType.h 2012-05-19 22:52:15 UTC (rev 9226)
@@ -173,20 +173,20 @@
class _UtilExport MT_ValueBase
{
public:
- MT_ValueBase(void* data, Type::Enum type) : type_(type), bHasDefaultValue_(false), data_(data) {}
- virtual ~MT_ValueBase() {}
+ inline MT_ValueBase(void* data, Type::Enum type) : type_(type), bLastConversionSuccessful(true), data_(data) {}
+ inline virtual ~MT_ValueBase() {}
virtual MT_ValueBase* clone() const = 0;
virtual void reset() = 0;
/// Returns the type of the current value.
- const Type::Enum& getType() const { return this->type_; }
+ inline const Type::Enum& getType() const { return this->type_; }
/// Returns true if the type of the stored value is T.
template <typename T> inline bool isType() const { return false; }
/// Checks whether the value is a default one.
- bool hasDefaultValue() const { return this->bHasDefaultValue_; }
+ inline bool lastConversionSuccessful() const { return this->bLastConversionSuccessful; }
virtual bool setValue(const char& value) = 0;
virtual bool setValue(const unsigned char& value) = 0;
@@ -252,13 +252,13 @@
virtual void toString(std::ostream& outstream) const = 0;
- virtual void importData( uint8_t*& mem )=0;
- virtual void exportData( uint8_t*& mem ) const=0;
- virtual uint8_t getSize() const=0;
+ virtual void importData(uint8_t*& mem) = 0;
+ virtual void exportData(uint8_t*& mem) const = 0;
+ virtual uint8_t getSize() const = 0;
- Type::Enum type_; ///< The type of the current value
- bool bHasDefaultValue_; ///< True if the last conversion wasn't successful
- void* data_; ///< For direct access to the value if the type is known
+ Type::Enum type_; ///< The type of the current value
+ bool bLastConversionSuccessful; ///< True if the last conversion was successful
+ void* data_; ///< For direct access to the value if the type is known
};
public:
@@ -328,7 +328,8 @@
}
/// Converts the current value to type T.
- template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); }
+ template <typename T> inline bool convert() { return this->force<T>(MultiType(*this)); }
+// template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); }
/// Resets value and type. Type will be void afterwards and null() returns true.
inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; }
@@ -341,8 +342,8 @@
template <typename T> inline bool isType() const { return (this->value_ ? this->value_->isType<T>() : false); }
std::string getTypename() const;
- /// Checks whether the value is a default one (assigned after a failed conversion)
- inline bool hasDefaultValue() const { return this->value_->hasDefaultValue(); }
+ /// Checks whether the last conversion was successful
+ inline bool lastConversionSuccessful() const { return !this->value_ || this->value_->lastConversionSuccessful(); }
/// Checks if the MT contains no value.
inline bool null() const { return !this->value_; }
Modified: code/branches/testing/src/libraries/util/MultiTypeValue.h
===================================================================
--- code/branches/testing/src/libraries/util/MultiTypeValue.h 2012-05-19 21:24:18 UTC (rev 9225)
+++ code/branches/testing/src/libraries/util/MultiTypeValue.h 2012-05-19 22:52:15 UTC (rev 9226)
@@ -60,7 +60,7 @@
inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); }
/// Resets the current value to the default.
- inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; }
+ inline void reset() { this->value_ = zeroise<T>(); bLastConversionSuccessful = true; }
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.
inline bool getValue(unsigned char* value) const { return convertValue<T, unsigned char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match.
@@ -94,38 +94,38 @@
{
if (other.value_)
{
- return !(bHasDefaultValue_ = !other.value_->getValue(&value_));
+ return (this->bLastConversionSuccessful = other.value_->getValue(&value_));
}
else
{
this->value_ = zeroise<T>();
- return !(bHasDefaultValue_ = true);
+ return (bLastConversionSuccessful = false);
}
}
- inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- 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.
- 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.
- inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
+ inline bool setValue(const char& value) { return (bLastConversionSuccessful = convertValue<char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ inline bool setValue(const short& value) { return (bLastConversionSuccessful = convertValue<short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ inline bool setValue(const int& value) { return (bLastConversionSuccessful = convertValue<int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ inline bool setValue(const long& value) { return (bLastConversionSuccessful = convertValue<long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ 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.
+ 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.
+ inline bool setValue(const float& value) { return (bLastConversionSuccessful = convertValue<float , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ inline bool setValue(const double& value) { return (bLastConversionSuccessful = convertValue<double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ inline bool setValue(const bool& value) { return (bLastConversionSuccessful = convertValue<bool , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ inline bool setValue( void* const& value) { return (bLastConversionSuccessful = convertValue<void* , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
/// Puts the current value on the stream
inline void toString(std::ostream& outstream) const { outstream << this->value_; }
Modified: code/branches/testing/test/util/MultiTypeTest.cc
===================================================================
--- code/branches/testing/test/util/MultiTypeTest.cc 2012-05-19 21:24:18 UTC (rev 9225)
+++ code/branches/testing/test/util/MultiTypeTest.cc 2012-05-19 22:52:15 UTC (rev 9226)
@@ -28,7 +28,7 @@
// x get<type>()
// ? getPointer()
- // x hasDefaultValue()
+ // x lastConversionSuccessful()
// x null()
/////////////////////////
@@ -141,13 +141,13 @@
EXPECT_TRUE(mt.isType<Vector3>());
EXPECT_EQ(Vector3(1, 2, 3), mt.get<Vector3>());
- EXPECT_FALSE(mt.hasDefaultValue());
+ EXPECT_TRUE(mt.lastConversionSuccessful());
mt = 77.7f;
EXPECT_TRUE(mt.isType<Vector3>());
EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>());
- EXPECT_TRUE(mt.hasDefaultValue());
+ EXPECT_FALSE(mt.lastConversionSuccessful());
}
//////////////////////
@@ -253,8 +253,6 @@
EXPECT_TRUE(mt.isType<int>());
EXPECT_EQ(0, mt.get<int>());
-
-// EXPECT_TRUE(mt.hasDefaultValue());
}
TEST(MultiType, ConvertFloatToInt)
@@ -286,7 +284,7 @@
EXPECT_EQ(0.0f, mt.get<float>());
EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>());
-// EXPECT_TRUE(mt.hasDefaultValue());
+ EXPECT_FALSE(mt.lastConversionSuccessful());
}
///////////
@@ -647,26 +645,30 @@
EXPECT_TRUE(mt.isType<orxonox::Degree>());
}
- ///////////////////////
- // hasDefaultValue() //
- ///////////////////////
- TEST(MultiType, HasDefaultValue)
+ ////////////////////////////////
+ // lastConversionSuccessful() //
+ ////////////////////////////////
+ TEST(MultiType, LastConversionSuccessful)
{
MultiType mt;
-// EXPECT_FALSE(mt.hasDefaultValue());
+ EXPECT_TRUE(mt.lastConversionSuccessful());
mt = 5.55;
- EXPECT_FALSE(mt.hasDefaultValue());
+ EXPECT_TRUE(mt.lastConversionSuccessful());
mt.convert<int>();
- EXPECT_FALSE(mt.hasDefaultValue());
+ EXPECT_TRUE(mt.lastConversionSuccessful());
- mt.convert<Quaternion>();
+ mt.convert<Vector3>();
-// EXPECT_TRUE(mt.hasDefaultValue());
+ EXPECT_FALSE(mt.lastConversionSuccessful());
+
+ mt.convert<std::string>();
+
+ EXPECT_TRUE(mt.lastConversionSuccessful());
}
////////////
More information about the Orxonox-commit
mailing list