Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
David Youssefi
otb
Commits
7ad68ea5
Commit
7ad68ea5
authored
Jul 08, 2020
by
Julien Osman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Add methods to access lists in XMLMetadataSupplier
parent
6ed37fe8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
+22
-0
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
+40
-0
No files found.
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
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
;
...
...
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment