Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Utilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UNICADO
Utilities
Commits
ba56bc9c
Commit
ba56bc9c
authored
3 months ago
by
Oliver Charles Schubert
Browse files
Options
Downloads
Patches
Plain Diff
Adds extractNodesFromPtree() to search a ptree for specific nodes.
parent
77169dd4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DesignEvaluator/src/main.cpp
+29
-14
29 additions, 14 deletions
DesignEvaluator/src/main.cpp
with
29 additions
and
14 deletions
DesignEvaluator/src/main.cpp
+
29
−
14
View file @
ba56bc9c
...
...
@@ -3,9 +3,9 @@
#include
<boost/property_tree/xml_parser.hpp>
#include
<boost/property_tree/ptree.hpp>
void
printNodeNames
(
const
boost
::
property_tree
::
ptree
&
tree
,
const
std
::
string
&
indent
=
""
)
{
void
printNodeNames
(
const
boost
::
property_tree
::
ptree
&
myP
tree
,
const
std
::
string
&
indent
=
""
)
{
// Iterate through each child node of the given tree
for
(
const
auto
&
node
:
tree
)
{
for
(
const
auto
&
node
:
myP
tree
)
{
// Print the node's name
std
::
cout
<<
indent
<<
node
.
first
;
...
...
@@ -23,14 +23,28 @@ void printNodeNames(const boost::property_tree::ptree& tree, const std::string&
}
}
int
containsSymbol
(
const
std
::
string
&
my
S
tring
,
const
std
::
string
&
my
S
ymbol
)
{
if
(
my
S
tring
.
find
(
my
S
ymbol
)
!=
std
::
string
::
npos
)
{
int
containsSymbol
(
const
std
::
string
&
my
_s
tring
,
const
std
::
string
&
my
_s
ymbol
)
{
if
(
my
_s
tring
.
find
(
my
_s
ymbol
)
!=
std
::
string
::
npos
)
{
return
1
;
}
else
{
return
0
;
}
}
boost
::
property_tree
::
ptree
extractNodesFromPtree
(
const
boost
::
property_tree
::
ptree
&
ptree
,
const
std
::
string
&
target_node
)
{
boost
::
property_tree
::
ptree
reduced_ptree
{};
for
(
const
auto
&
parent_node
:
ptree
)
{
if
(
parent_node
.
first
==
target_node
)
{
reduced_ptree
.
add_child
(
parent_node
.
first
,
parent_node
.
second
);
}
boost
::
property_tree
::
ptree
myPtree
{};
myPtree
=
extractNodesFromPtree
(
parent_node
.
second
,
target_node
);
}
return
reduced_ptree
;
}
enum
State
{
DefiningFilePaths
,
LoadingXMLsIntoTrees
,
...
...
@@ -119,16 +133,17 @@ int main () {
std
::
cout
<<
"Current State: "
<<
state
<<
std
::
endl
;
// Iterate through the children of <ConfigFile.ProgramSettings.Parameters>
for
(
const
boost
::
property_tree
::
ptree
::
value_type
&
parent_nodes
:
config_tree
.
get_child
(
"ConfigFile.ProgramSettings.Parameters"
))
{
boost
::
property_tree
::
ptree
temporary_tree
{};
// Iterate through the children of parent_node
for
(
const
auto
&
child_nodes
:
parent_nodes
.
second
)
{
if
(
child_nodes
.
first
==
"SubPath"
)
{
temporary_tree
.
add_child
(
child_nodes
.
first
,
child_nodes
.
second
);
}
}
reduced_config_tree
.
add_child
(
parent_nodes
.
first
,
temporary_tree
);
}
// for (const boost::property_tree::ptree::value_type& parent_nodes : config_tree.get_child("ConfigFile.ProgramSettings.Parameters")) {
// boost::property_tree::ptree temporary_tree{};
// // Iterate through the children of parent_node
// for (const auto &child_nodes : parent_nodes.second) {
// if (child_nodes.first == "SubPath") {
// temporary_tree.add_child(child_nodes.first, child_nodes.second);
// }
// }
// reduced_config_tree.add_child(parent_nodes.first, temporary_tree);
// }
reduced_config_tree
=
extractNodesFromPtree
(
config_tree
,
"SubPath"
);
// printNodeNames(reduced_config_tree);
state
=
State
::
SubstractingNodeValues
;
break
;
...
...
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