Commit 48e7d53e authored by Cédric Traizet's avatar Cédric Traizet

ENH: implement an overloaded getAs that return a default value instead of throwing exceptions

parent b786dbc7
Pipeline #6101 passed with stages
in 22 minutes and 50 seconds
......@@ -83,6 +83,25 @@ public:
}
}
template <typename T> T GetAs(T const& defaultValue, std::string const& path, int band=-1) const
{
bool hasValue;
std::string ret = GetMetadataValue(path, hasValue, band);
if (!hasValue)
{
return defaultValue;
}
try
{
return boost::lexical_cast<T>(ret);
}
catch (boost::bad_lexical_cast&)
{
return defaultValue;
}
}
/** Parse a metadata value to a std::vector,
* If size>=0, then the final std::vector size is checked and an exception
* is raised if it doesn't match the given size.*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment