Skip to content
Snippets Groups Projects

Resolve "Migrate code to OTB 8.x"

Merged Luc Hermitte requested to merge 5-migrate-code-to-otb-8-x into master
1 file
+ 53
0
Compare changes
  • Side-by-side
  • Inline
+ 53
0
@@ -109,7 +109,60 @@ T value_or_unless(
}
#endif
#if OTB_VERSION_MAJOR >= 8
/**
* Helper function to fetch data from keyword lists.
* \tparam T Type of the element to find
* \param[in] kwl Keyword list where to search for
* \param[in] key Name of the element to search and decode
* \param[in] context Context to help build error message
*
* \throw itk::ExceptionObject with the `context` as message if there is no
* metadata associated to the `key`
* \throw itk::ExceptionObject with the `context` as message if the metadata
* found at the `key` cannot be converted to a `T`
* \return the metadata found associated to the `key` decoded as a `T` type.
* \todo move this function to `StringUtilities.h`
*/
template <typename T>
inline
T value_or_throw(
otb::ImageMetadata const& kwl,
std::string const& key,
otb::string_view context)
{
if (kwl.Has(key))
{
auto const& value = kwl[key];
return to<T>(value, "converting metadata '"+key+"' "+context);
}
else
{
throw std::runtime_error("Cannot fetch metadata '"+key+"' " +context);
}
}
#else
template <typename T>
inline
T value_or_throw(
otb::ImageKeywordlist const& kwl,
std::string const& key,
otb::string_view context)
{
if (kwl.HasKey(key))
{
auto const& value = kwl.GetMetadataByKey(key);
return to<T>(value, context);
}
else
{
throw std::runtime_error("Cannot fetch metadata '"+ key + "' while " + context);
}
}
#endif
}
// otb namespace
Loading