Skip to content
Snippets Groups Projects
Commit 4ef3fe31 authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Improve VirtualRobot::RuntimeEnvironment::getValue

* the templated version now works withstrings via if constexpr
* add version taking an output parameter
parent bd0ead16
No related branches found
No related tags found
No related merge requests found
......@@ -99,20 +99,32 @@ namespace VirtualRobot
template<class T>
static T getValue(const std::string& key, const T& defaultValue)
{
static_assert(std::is_arithmetic_v<T>);
try
if constexpr(std::is_same_v<T, std::string>)
{
return hasValue(key) ? boost::lexical_cast<T>(getValue(key)) : defaultValue;
return getValue(key, defaultValue);
}
catch(...)
else
{
VR_WARNING << "Failed to lexical cast value '" << getValue(key)
<< "' for key '" << key << "' to "
<< boost::core::demangle(typeid(T).name())
<< "'" << std::endl;
throw;
static_assert(std::is_arithmetic_v<T>);
try
{
return hasValue(key) ? boost::lexical_cast<T>(getValue(key)) : defaultValue;
}
catch(...)
{
VR_WARNING << "Failed to lexical cast value '" << getValue(key)
<< "' for key '" << key << "' to "
<< boost::core::demangle(typeid(T).name())
<< "'" << std::endl;
throw;
}
}
}
template<class T>
static void getValue(T& target, const std::string& key, const auto& defaultValue)
{
target = getValue<T>(key, defaultValue);
}
static bool hasValue(const std::string& key);
/// Indicate whether the given flag was specified.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment