UDAValue: the get<double>() method will return SI values

This commit is contained in:
Joakim Hove 2019-06-07 10:17:29 +02:00
parent f3abbf4981
commit 44e21101bc
2 changed files with 16 additions and 2 deletions

View File

@ -67,8 +67,9 @@ bool UDAValue::is<std::string>() const {
template<>
double UDAValue::get() const {
if (this->numeric_value)
return this->double_value;
this->assert_numeric();
return this->dim.convertRawToSi(this->double_value);
}
throw std::invalid_argument("UDAValue does not hold a numerical value");
}

View File

@ -1056,3 +1056,16 @@ BOOST_AUTO_TEST_CASE(UDA_VALUE) {
BOOST_CHECK_EQUAL( value2.get<std::string>(), std::string("FUBHP"));
BOOST_CHECK_THROW( value2.get<double>(), std::invalid_argument);
}
/*
The unit/dimension handling in the UDAvalue is hacky at best.
*/
BOOST_AUTO_TEST_CASE(UDA_VALUE_DIM) {
UDAValue value0(1);
Dimension dim("DUMMY", 10);
BOOST_CHECK_EQUAL( value0.get<double>(), 1);
value0.set_dim( dim );
BOOST_CHECK_EQUAL( value0.get<double>(), 10);
}