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
+ 10
15
Compare changes
  • Side-by-side
  • Inline
+ 56
3
/*
* Copyright(C) 2005-2021 Centre National d'Etudes Spatiales(CNES)
* Copyright(C) 2005-2023 Centre National d'Etudes Spatiales(CNES)
*
* This file is part of Orfeo Toolbox
*
@@ -20,7 +20,7 @@
#ifndef otbStringHelpers_h
#define otbStringHelpers_h
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#if OTB_VERSION_MAJOR >= 8
#include "otbImageMetadata.h"
#else
#include "otbImageKeywordlist.h"
@@ -69,7 +69,7 @@ inline std::string sto<std::string>(std::string const& s)
* \return the metadata found associated to the `key` decoded as a `T` type.
* \todo move this function to `StringUtilities.h`
*/
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#if OTB_VERSION_MAJOR >= 8
template <typename T>
inline
T value_or_unless(
@@ -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