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 Osman
otb
Commits
833636d3
Commit
833636d3
authored
4 years ago
by
Julien Osman
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Change the XMLMetadataSupplier::FetchPartialNameValueMultiple for better handling of memory
parent
fadb863e
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
+13
-1
13 additions, 1 deletion
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
+22
-12
22 additions, 12 deletions
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
with
35 additions
and
13 deletions
Modules/Core/Metadata/include/otbXMLMetadataSupplier.h
+
13
−
1
View file @
833636d3
...
...
@@ -131,7 +131,19 @@ protected:
* @return A StringList containing only the pairs from papszStrList whose key
* contain pszName
*/
char
**
CSLFetchPartialNameValueMultiple
(
char
**
papszStrList
,
const
char
*
pszName
)
const
;
std
::
vector
<
std
::
string
>
FetchPartialNameValueMultiple
(
char
**
papszStrList
,
const
char
*
pszName
)
const
;
/**
* @brief In a StringList of “Name=Value” pairs, look for the values
* associated with a name containing the specified string
*
* @param StringVector A std::vector of std::string that will be searched
* @param Name A std::string that will be looked for in the keys
* @return A std::vector of std::string containing only the pairs from StringVector whose key
* contain Name
*/
std
::
vector
<
std
::
string
>
FetchPartialNameValueMultiple
(
const
std
::
vector
<
std
::
string
>
&
StringVector
,
const
std
::
string
&
Name
)
const
;
private
:
/** List of resource files */
...
...
This diff is collapsed.
Click to expand it.
Modules/Core/Metadata/src/otbXMLMetadataSupplier.cxx
+
22
−
12
View file @
833636d3
...
...
@@ -54,7 +54,7 @@ std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, b
// Search for the first joker
std
::
size_t
found
=
path
.
find
(
"_#"
);
// Looking for the keys corresponding to the part of the path before the first joker
char
**
values
=
this
->
CSL
FetchPartialNameValueMultiple
(
m_MetadataDic
,
path
.
substr
(
0
,
found
).
c_str
());
std
::
vector
<
std
::
string
>
values
=
this
->
FetchPartialNameValueMultiple
(
m_MetadataDic
,
path
.
substr
(
0
,
found
).
c_str
());
// Position of the beginning of the path after the joker
std
::
size_t
start
=
found
+
2
;
...
...
@@ -64,19 +64,15 @@ std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, b
// Look for the next joker
found
=
path
.
find
(
"_#"
,
start
);
// Look for the keys corresponding to the part of the path between the two jokers
char
**
new_values
=
this
->
CSLFetchPartialNameValueMultiple
(
values
,
path
.
substr
(
start
,
found
).
c_str
());
CSLDestroy
(
values
);
values
=
CSLDuplicate
(
new_values
);
CSLDestroy
(
new_values
);
values
=
this
->
FetchPartialNameValueMultiple
(
values
,
path
.
substr
(
start
,
found
));
start
=
found
+
2
;
}
if
((
values
!=
nullptr
)
&&
(
values
[
0
]
!=
nullptr
))
if
((
values
.
size
()
!=
0
)
&&
(
!
values
[
0
]
.
empty
()
))
{
hasValue
=
true
;
std
::
string
ret
=
values
[
0
];
ret
=
ret
.
substr
(
ret
.
find
(
'='
)
+
1
);
CSLDestroy
(
values
);
// Return the value part
return
ret
;
}
...
...
@@ -198,16 +194,30 @@ char** XMLMetadataSupplier::ReadXMLToList(CPLXMLNode* psNode, char** papszList,
return
papszList
;
}
char
**
XMLMetadataSupplier
::
CSLFetchPartialNameValueMultiple
(
char
**
papszStrList
,
const
char
*
pszName
)
const
std
::
vector
<
std
::
string
>
XMLMetadataSupplier
::
FetchPartialNameValueMultiple
(
char
**
papszStrList
,
const
char
*
pszName
)
const
{
std
::
vector
<
std
::
string
>
retStringVector
;
if
(
papszStrList
==
nullptr
||
pszName
==
nullptr
)
return
nullpt
r
;
return
retStringVecto
r
;
char
**
papszValues
=
nullptr
;
for
(
;
*
papszStrList
!=
nullptr
;
++
papszStrList
)
if
(
strstr
(
*
papszStrList
,
pszName
)
)
papszValues
=
CSLAddString
(
papszValues
,
*
papszStrList
);
return
papszValues
;
retStringVector
.
push_back
(
*
papszStrList
);
return
retStringVector
;
}
std
::
vector
<
std
::
string
>
XMLMetadataSupplier
::
FetchPartialNameValueMultiple
(
const
std
::
vector
<
std
::
string
>
&
StringVector
,
const
std
::
string
&
Name
)
const
{
std
::
vector
<
std
::
string
>
retStringVector
;
if
(
StringVector
.
size
()
==
0
||
Name
.
empty
()
)
return
retStringVector
;
for
(
const
auto
&
val
:
StringVector
)
if
(
val
.
find
(
Name
)
!=
std
::
string
::
npos
)
retStringVector
.
push_back
(
val
);
return
retStringVector
;
}
int
XMLMetadataSupplier
::
GetNbBands
()
const
...
...
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