Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NORMLIM_sigma0
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s1-tiling
NORMLIM_sigma0
Merge requests
!6
Resolve "Migrate code to OTB 8.x"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Migrate code to OTB 8.x"
5-migrate-code-to-otb-8-x
into
master
Overview
0
Commits
10
Pipelines
0
Changes
1
Merged
Luc Hermitte
requested to merge
5-migrate-code-to-otb-8-x
into
master
1 year ago
Overview
0
Commits
10
Pipelines
0
Changes
1
Expand
Closes
#5 (closed)
0
0
Merge request reports
Viewing commit
2b6736d2
Prev
Next
Show latest version
1 file
+
53
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
2b6736d2
ENH: Define `value_or_throw` helper to extract MD
· 2b6736d2
Luc Hermitte
authored
1 year ago
include/otbStringHelpers.h
+
56
−
3
Options
/*
* Copyright(C) 2005-202
1
Centre National d'Etudes Spatiales(CNES)
* Copyright(C) 2005-202
3
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