std::string Value::as_string() const { //if the data is stored as a string if(m_storedAs == valueType_string) { try { return any_cast<std::string>(m_value); } catch(std::bad_cast&) { throw Error_BadDataType(); } } //build the string depending on how the value is stored switch(m_storedAs) { case valueType_uint8: return Utils::toStr(static_cast<uint16>(as_uint8())); case valueType_uint16: return Utils::toStr(as_uint16()); case valueType_uint32: return Utils::toStr(as_uint32()); case valueType_int16: return Utils::toStr(as_int16()); case valueType_int32: return Utils::toStr(as_int32()); case valueType_float: return Utils::toStr(as_float()); case valueType_double: return Utils::toStr(as_double()); case valueType_bool: return Utils::toStr(as_bool()); default: throw Error_BadDataType(); } }
bool Value::isSameValue(const Value& other) const { switch(m_storedAs) { case valueType_float: return as_float() == other.as_float(); case valueType_double: return as_double() == other.as_double(); case valueType_uint16: return as_uint16() == other.as_uint16(); case valueType_uint32: return as_uint32() == other.as_uint32(); case valueType_int16: return as_int16() == other.as_int16(); case valueType_int32: return as_int32() == other.as_int32(); case valueType_uint8: return as_uint8() == other.as_uint8(); case valueType_bool: return as_bool() == other.as_bool(); case valueType_string: return as_string() == other.as_string(); default: return false; } }
TEST_F(CtypeOpsFromStringTest, uint16_max) { EXPECT_EQ(0, parse("uint16", "65535")); EXPECT_EQ(65535, as_uint16()); }
TEST_F(CtypeOpsFromStringTest, uint16_min) { EXPECT_EQ(0, parse("uint16", "0")); EXPECT_EQ(0, as_uint16()); }