UDAValue: add reset() methods
This commit is contained in:
parent
44e21101bc
commit
edbc9d2af7
@ -41,6 +41,8 @@ public:
|
||||
template<typename T>
|
||||
bool is() const;
|
||||
|
||||
void reset(double value);
|
||||
void reset(const std::string& value);
|
||||
|
||||
void assert_numeric() const;
|
||||
void assert_numeric(const std::string& error_msg) const;
|
||||
|
@ -71,7 +71,14 @@ double UDAValue::get() const {
|
||||
return this->dim.convertRawToSi(this->double_value);
|
||||
}
|
||||
|
||||
throw std::invalid_argument("UDAValue does not hold a numerical value");
|
||||
void UDAValue::reset(double value) {
|
||||
this->double_value = value;
|
||||
this->numeric_value = true;
|
||||
}
|
||||
|
||||
void UDAValue::reset(const std::string& value) {
|
||||
this->string_value = value;
|
||||
this->numeric_value = false;
|
||||
}
|
||||
|
||||
template<>
|
||||
@ -96,6 +103,9 @@ bool UDAValue::operator==(const UDAValue& other) const {
|
||||
if (this->numeric_value != other.numeric_value)
|
||||
return false;
|
||||
|
||||
if (this->dim != other.dim)
|
||||
return false;
|
||||
|
||||
if (this->numeric_value)
|
||||
return (this->double_value == other.double_value);
|
||||
|
||||
@ -114,4 +124,7 @@ std::ostream& operator<<( std::ostream& stream, const UDAValue& uda_value ) {
|
||||
stream << "'" << uda_value.get<std::string>() << "'";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1041,6 +1041,12 @@ BOOST_AUTO_TEST_CASE(UDA_VALUE) {
|
||||
BOOST_CHECK(!value0.is<std::string>());
|
||||
BOOST_CHECK_EQUAL( value0.get<double>(), 0);
|
||||
BOOST_CHECK_THROW( value0.get<std::string>(), std::invalid_argument);
|
||||
value0.reset( 10 );
|
||||
BOOST_CHECK_EQUAL( value0.get<double>(), 10);
|
||||
BOOST_CHECK_THROW( value0.get<std::string>(), std::invalid_argument);
|
||||
value0.reset( "STRING" );
|
||||
BOOST_CHECK_EQUAL( value0.get<std::string>(), std::string("STRING"));
|
||||
BOOST_CHECK_THROW( value0.get<double>(), std::invalid_argument);
|
||||
|
||||
|
||||
UDAValue value1(10);
|
||||
|
Loading…
Reference in New Issue
Block a user