Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParameterHandler::print_parameters(): Demangle JSON #13815

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/news/changes/incompatibilities/20220525SchreterMunch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changed: For ParameterHandler::OutputStyle::JSON or
ParameterHandler::OutputStyle::ShortJSON, the function
ParameterHandler::print_parameters() demangles now the
parameters before printing the output. Users do not
need to demangle the output themselves anymore.
<br>
(Magdalena Schreter, Peter Munch, 2022/05/25)
34 changes: 33 additions & 1 deletion source/base/parameter_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,36 @@ namespace
}
}

/**
* Demangle all parameters recursively and attach them to @p tree_out.
* @p parameter_node indicates, whether a given node @p tree_in
* is a parameter node (as opposed to being a subsection or alias
* node).
*/
void
recursively_demangle(const boost::property_tree::ptree &tree_in,
boost::property_tree::ptree & tree_out,
const bool parameter_node = false)
{
for (const auto &p : tree_in)
{
if (parameter_node)
{
tree_out.put_child(p.first, p.second);
}
else
{
boost::property_tree::ptree temp;

if (const auto val = p.second.get_value_optional<std::string>())
temp.put_value<std::string>(*val);

recursively_demangle(p.second, temp, is_parameter_node(p.second));
tree_out.put_child(demangle(p.first), temp);
}
}
}

/**
* Assert validity of of given output @p style.
*/
Expand Down Expand Up @@ -1308,7 +1338,9 @@ ParameterHandler::print_parameters(std::ostream & out,

if ((style & JSON) != 0)
{
write_json(out, current_entries);
boost::property_tree::ptree current_entries_damangled;
recursively_demangle(current_entries, current_entries_damangled);
write_json(out, current_entries_damangled);
return out;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/parameter_handler/parameter_acceptor_09.output
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEAL::Generate and read input.json
{
"Test":
{
"A_20point":
"A point":
{
"value": "0, 0, 0",
"default_value": "0, 0, 0",
Expand Down
6 changes: 3 additions & 3 deletions tests/parameter_handler/parameter_handler_27.output
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DEAL::========================================
{
"Testing":
{
"A_20bool":
"A bool":
{
"value": "true",
"default_value": "true",
Expand All @@ -29,7 +29,7 @@ DEAL::========================================
"pattern_description": "[Bool]",
"actions": "1"
},
"A_20double":
"A double":
{
"value": "1",
"default_value": "1",
Expand All @@ -38,7 +38,7 @@ DEAL::========================================
"pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
"actions": "0"
},
"A_20string":
"A string":
{
"value": "Ciao",
"default_value": "Ciao",
Expand Down
6 changes: 3 additions & 3 deletions tests/parameter_handler/parameter_handler_28.output
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ DEAL::========================================
DEAL::ShortJSON format:
DEAL::========================================
{
"A_20double": "1",
"Section_20two":
"A double": "1",
"Section two":
{
"Another_20double": "2"
"Another double": "2"
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/parameter_handler/parameter_handler_read_json.output
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]",
"actions": "1"
},
"Testing_25testing":
"Testing%testing":
{
"double_2bdouble":
"double+double":
{
"value": "7.1415926",
"default_value": "6.14159",
Expand All @@ -29,7 +29,7 @@
"pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
"actions": "6"
},
"int_2aint":
"int*int":
{
"value": "2",
"default_value": "2",
Expand All @@ -38,7 +38,7 @@
"pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]",
"actions": "5"
},
"string_26list":
"string&list":
{
"value": "< & > ; \/",
"default_value": "< & > ; \/",
Expand All @@ -50,7 +50,7 @@
},
"ss1":
{
"double_201":
"double 1":
{
"value": "2.234",
"default_value": "1.234",
Expand All @@ -61,7 +61,7 @@
},
"ss2":
{
"double_202":
"double 2":
{
"value": "5.321",
"default_value": "4.321",
Expand Down
24 changes: 12 additions & 12 deletions tests/parameter_handler/parameter_handler_write_json.output
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
"pattern": "1",
"pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
},
"Testing_25testing":
"Testing%testing":
{
"double_2bdouble":
"double+double":
{
"value": "6.1415926",
"default_value": "6.1415926",
"documentation": "docs 3",
"pattern": "6",
"pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
},
"int_2aint":
"int*int":
{
"value": "2",
"default_value": "2",
"documentation": "",
"pattern": "5",
"pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
},
"string_26list":
"string&list":
{
"value": "< & > ; \/",
"default_value": "< & > ; \/",
Expand All @@ -45,7 +45,7 @@
},
"ss1":
{
"double_201":
"double 1":
{
"value": "1.234",
"default_value": "1.234",
Expand All @@ -55,7 +55,7 @@
},
"ss2":
{
"double_202":
"double 2":
{
"value": "4.321",
"default_value": "4.321",
Expand All @@ -70,18 +70,18 @@
{
"int1": "1",
"int2": "2",
"Testing_25testing":
"Testing%testing":
{
"double_2bdouble": "6.1415926",
"int_2aint": "2",
"string_26list": "< & > ; \/"
"double+double": "6.1415926",
"int*int": "2",
"string&list": "< & > ; \/"
},
"ss1":
{
"double_201": "1.234",
"double 1": "1.234",
"ss2":
{
"double_202": "4.321"
"double 2": "4.321"
}
}
}
Expand Down