Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
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
Julien Cabieces
otb
Commits
7ad68ea5
Commit
7ad68ea5
authored
4 years ago
by
Julien Osman
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Add methods to access lists in XMLMetadataSupplier
parent
6ed37fe8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
+22
-0
22 additions, 0 deletions
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
+40
-0
40 additions, 0 deletions
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
with
62 additions
and
0 deletions
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
+
22
−
0
View file @
7ad68ea5
...
...
@@ -49,6 +49,26 @@ public:
* If band >= 0, the metadata value is looked in the specified band*/
const
std
::
string
GetMetadataValue
(
const
std
::
string
path
,
bool
&
hasValue
,
int
band
=
1
)
const
override
;
const
std
::
string
GetFirstMetadataValue
(
const
std
::
string
paths
,
bool
&
hasValue
)
const
;
template
<
typename
T
>
T
GetFirstAs
(
std
::
string
path
)
const
{
bool
hasValue
;
std
::
string
ret
=
GetFirstMetadataValue
(
path
,
hasValue
);
if
(
!
hasValue
)
{
otbGenericExceptionMacro
(
MissingMetadataException
,
<<
"Missing metadata '"
<<
path
<<
"'"
)
}
try
{
return
boost
::
lexical_cast
<
T
>
(
ret
);
}
catch
(
boost
::
bad_lexical_cast
&
)
{
otbGenericExceptionMacro
(
MissingMetadataException
,
<<
"Bad metadata value for '"
<<
path
<<
"', got: "
<<
ret
)
}
}
std
::
string
GetResourceFile
(
std
::
string
=
""
)
const
override
;
int
GetNbBands
()
const
override
;
...
...
@@ -70,6 +90,8 @@ protected:
virtual
char
**
ReadXMLToList
(
CPLXMLNode
*
psNode
,
char
**
papszList
,
const
char
*
pszName
=
""
);
char
**
CSLFetchPartialNameValueMultiple
(
CSLConstList
papszStrList
,
const
char
*
pszName
)
const
;
private
:
/** List of resource files */
std
::
string
m_FileName
;
...
...
This diff is collapsed.
Click to expand it.
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
+
40
−
0
View file @
7ad68ea5
...
...
@@ -54,6 +54,34 @@ const std::string XMLMetadataSupplier::GetMetadataValue(const std::string path,
return
std
::
string
(
ret
);
}
const
std
::
string
XMLMetadataSupplier
::
GetFirstMetadataValue
(
const
std
::
string
path
,
bool
&
hasValue
)
const
{
std
::
size_t
found
=
path
.
find
(
"_#"
);
char
**
values
=
this
->
CSLFetchPartialNameValueMultiple
(
m_MetadataDic
,
path
.
substr
(
0
,
found
).
c_str
());
std
::
size_t
start
=
found
+
2
;
if
(
found
!=
std
::
string
::
npos
)
found
=
path
.
find
(
"_#"
,
found
);
while
(
found
!=
std
::
string
::
npos
)
{
values
=
this
->
CSLFetchPartialNameValueMultiple
(
m_MetadataDic
,
path
.
substr
(
start
,
found
).
c_str
());
start
=
found
;
found
=
path
.
find
(
"_#"
,
found
+
2
);
}
if
(
values
[
0
]
!=
nullptr
)
{
hasValue
=
true
;
std
::
string
ret
=
std
::
string
(
values
[
0
]);
return
ret
.
substr
(
ret
.
find
(
'='
)
+
1
);
}
else
{
hasValue
=
false
;
return
""
;
}
}
std
::
string
XMLMetadataSupplier
::
GetResourceFile
(
std
::
string
)
const
{
return
m_FileName
;
...
...
@@ -165,6 +193,18 @@ char** XMLMetadataSupplier::ReadXMLToList(CPLXMLNode* psNode, char** papszList,
return
papszList
;
}
char
**
XMLMetadataSupplier
::
CSLFetchPartialNameValueMultiple
(
CSLConstList
papszStrList
,
const
char
*
pszName
)
const
{
if
(
papszStrList
==
nullptr
||
pszName
==
nullptr
)
return
nullptr
;
char
**
papszValues
=
nullptr
;
for
(
;
*
papszStrList
!=
nullptr
;
++
papszStrList
)
if
(
strstr
(
*
papszStrList
,
pszName
)
)
papszValues
=
CSLAddString
(
papszValues
,
*
papszStrList
);
return
papszValues
;
}
int
XMLMetadataSupplier
::
GetNbBands
()
const
{
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment