--- /dev/null
+Changed:`ParameterHandler::parse_input_from_json()` reads now a json-file
+without mangled parameter names.
+<br>
+(Magdalena Schreter, Peter Munch, 2024/01/26)
}
/**
- * Demangle all parameters recursively and attach them to @p tree_out.
+ * Mangle (@p do_mangle = true) or demangle (@p do_mangle = false) all
+ * parameters recursively and attach them to @p tree_out.
* @p is_parameter_or_alias_node indicates, whether a given node
* @p tree_in is a parameter node or an alias node (as opposed to being
* a subsection).
*/
void
- recursively_demangle(const boost::property_tree::ptree &tree_in,
- boost::property_tree::ptree &tree_out,
- const bool is_parameter_or_alias_node = false)
+ recursively_mangle_or_demangle(const boost::property_tree::ptree &tree_in,
+ boost::property_tree::ptree &tree_out,
+ const bool do_mangle,
+ const bool is_parameter_or_alias_node = false)
{
for (const auto &p : tree_in)
{
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) ||
- is_alias_node(p.second));
- tree_out.put_child(demangle(p.first), temp);
+ recursively_mangle_or_demangle(p.second,
+ temp,
+ do_mangle,
+ is_parameter_node(p.second) ||
+ is_alias_node(p.second));
+ tree_out.put_child(do_mangle ? mangle(p.first) : demangle(p.first),
+ temp);
}
}
}
}
// The xml function is reused to read in the xml into the parameter file.
- // This means that only mangled files can be read.
+ // This function can only read mangled files. Therefore, we create a mangeled
+ // tree first.
+ boost::property_tree::ptree node_tree_mangled;
+ recursively_mangle_or_demangle(node_tree,
+ node_tree_mangled,
+ true /*do_mangle*/);
read_xml_recursively(
- node_tree, "", path_separator, patterns, skip_undefined, *this);
+ node_tree_mangled, "", path_separator, patterns, skip_undefined, *this);
}
if ((style & JSON) != 0)
{
- boost::property_tree::ptree current_entries_damangled;
- recursively_demangle(current_entries, current_entries_damangled);
- write_json(out, current_entries_damangled);
+ boost::property_tree::ptree current_entries_demangled;
+ recursively_mangle_or_demangle(current_entries,
+ current_entries_demangled,
+ false /*do_mangle*/);
+ write_json(out, current_entries_demangled);
return out;
}
-// check ParameterHandler::parse_input_from_xml
+// check ParameterHandler::parse_input_from_json
#include <deal.II/base/parameter_handler.h>
initlog();
// default values
- int int1 = 1;
- int int2 = 2;
- double double1 = 1.234;
- double double2 = 4.321;
- std::string str = "< & > ; /";
- int intint = 2;
- double doubledouble = 6.1415926;
+ int int1 = 1;
+ int int2 = 2;
+ double double1 = 1.234;
+ double double2 = 4.321;
+ std::string str = "< & > ; /";
+ int intint = 2;
+ double doubledouble = 6.1415926;
+ double double_double = 0;
ParameterHandler prm;
prm.add_parameter("int1", int1, "doc 1");
prm.add_parameter("string&list", str, "docs 1");
prm.add_parameter("int*int", intint);
prm.add_parameter("double+double", doubledouble, "docs 3");
+ prm.add_parameter("double_double", double_double, "docs 4");
}
prm.leave_subsection();
// read from json
- std::ifstream in(SOURCE_DIR "/prm/parameter_handler_read_json.prm");
+ std::ifstream in(SOURCE_DIR "/prm/parameter_handler_read_json_01.json");
prm.parse_input_from_json(in);
Assert(int1 == 2, ExcNotImplemented());
Assert(str == "< & > ; /", ExcNotImplemented());
Assert(intint == 2, ExcNotImplemented());
Assert(doubledouble == 7.1415926, ExcNotImplemented());
+ Assert(double_double == 1.234, ExcNotImplemented());
// write it out again
prm.print_parameters(deallog.get_file_stream(), ParameterHandler::JSON);
"pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
"actions": "6"
},
+ "double_double":
+ {
+ "value": "1.234",
+ "default_value": "0",
+ "documentation": "docs 4",
+ "pattern": "7",
+ "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
+ "actions": "7"
+ },
"int*int":
{
"value": "2",
prm.leave_subsection();
// read from json
- std::ifstream in(SOURCE_DIR "/prm/parameter_handler_read_json_02.prm");
+ std::ifstream in(SOURCE_DIR "/prm/parameter_handler_read_json_02.json");
prm.parse_input_from_json(in, true);
AssertDimension(int1, 1);
int int2 = 0;
int int3 = 0;
int int4 = 0;
+ int int5 = 0;
ParameterHandler prm;
prm.add_parameter("int1", int1);
prm.add_parameter("int4", int4);
prm.leave_subsection();
+ prm.enter_subsection("test_underscore");
+ prm.add_parameter("int_5", int5);
+ prm.leave_subsection();
+
std::string source = SOURCE_DIR;
std::string filename = source + "/prm/parameter_handler_read_json_03.json";
prm.parse_input(filename, "", true, true);
AssertDimension(int2, 2);
AssertDimension(int3, 3);
AssertDimension(int4, 4);
+ AssertDimension(int5, 10);
return 0;
}
},
"ss1":
{
- "double_201":
+ "double 1":
{
"value": "2.234",
"default_value": "1.234",
},
"ss2":
{
- "double_202":
+ "double 2":
{
"value": "5.321",
"default_value": "4.321",
}
}
},
- "Testing_25testing":
+ "Testing%testing":
{
- "string_26list":
+ "string&list":
{
"value": "< & > ; \/",
"default_value": "< & > ; \/",
"pattern": "4",
"pattern_description": "[Anything]"
},
- "int_2aint":
+ "int*int":
{
"value": "2",
"default_value": "2",
"pattern": "5",
"pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
},
- "double_2bdouble":
+ "double+double":
{
"value": "7.1415926",
"default_value": "6.1415926",
"documentation": "docs 3",
"pattern": "6",
"pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
+ },
+ "double_double":
+ {
+ "value": "1.234",
+ "default_value": "0",
+ "documentation": "docs 4",
+ "pattern": "7",
+ "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
}
}
}
"dummy" : {"int3" : 3, "int4" : 4},
"int5": {"value": 5},
"int6": 6,
- "dummy2" : {"int7" : 7, "int8" : 8}
-}
\ No newline at end of file
+ "dummy2" : {"int7" : 7, "int8" : 8},
+ "test_underscore": {"int_5": 10}
+}