]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Demangle json during output 13815/head
authorMagdalena Schreter <schreter.magdalena@gmail.com>
Mon, 23 May 2022 21:36:08 +0000 (23:36 +0200)
committerMagdalena Schreter <schreter.magdalena@gmail.com>
Wed, 25 May 2022 12:56:37 +0000 (14:56 +0200)
Co-authored-by: Peter Munch <peterrmuench@gmail.com>
doc/news/changes/incompatibilities/20220525SchreterMunch [new file with mode: 0644]
source/base/parameter_handler.cc
tests/parameter_handler/parameter_acceptor_09.output
tests/parameter_handler/parameter_handler_27.output
tests/parameter_handler/parameter_handler_28.output
tests/parameter_handler/parameter_handler_read_json.output
tests/parameter_handler/parameter_handler_write_json.output

diff --git a/doc/news/changes/incompatibilities/20220525SchreterMunch b/doc/news/changes/incompatibilities/20220525SchreterMunch
new file mode 100644 (file)
index 0000000..c8a2dbf
--- /dev/null
@@ -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)
index 1eaf231056a160ec2f2ddd263a2fb0973c91fc24..f22211794f21cb1da9741bb8335c38bbc4b48676 100644 (file)
@@ -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.
    */
@@ -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;
     }
 
index 5dda9338fa39ef744a5d673c903b904f384c0674..ca7aa0a93455af39e5c23bb75341d14087c02b7d 100644 (file)
@@ -15,7 +15,7 @@ DEAL::Generate and read input.json
 {
     "Test":
     {
-        "A_20point":
+        "A point":
         {
             "value": "0, 0, 0",
             "default_value": "0, 0, 0",
index 890ec1bca0e3668495e64b17d3bc21665955d602..db5c34a362123976500eed1969e9e3d45285a06c 100644 (file)
@@ -20,7 +20,7 @@ DEAL::========================================
 {
     "Testing":
     {
-        "A_20bool":
+        "A bool":
         {
             "value": "true",
             "default_value": "true",
@@ -29,7 +29,7 @@ DEAL::========================================
             "pattern_description": "[Bool]",
             "actions": "1"
         },
-        "A_20double":
+        "A double":
         {
             "value": "1",
             "default_value": "1",
@@ -38,7 +38,7 @@ DEAL::========================================
             "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
             "actions": "0"
         },
-        "A_20string":
+        "A string":
         {
             "value": "Ciao",
             "default_value": "Ciao",
index 2ed6063af129eaff2b7c3e29cd974bafb28ae74c..76f17358848a17231002c175679e1fa273ab168e 100644 (file)
@@ -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"
     }
 }
 
index 6b2b26bbdb7d87cc07d50d1cc832a8bf920ac8a3..70095fb249890f0788e3703498947fece51ec3f6 100644 (file)
@@ -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",
@@ -29,7 +29,7 @@
             "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]",
             "actions": "6"
         },
-        "int_2aint":
+        "int*int":
         {
             "value": "2",
             "default_value": "2",
@@ -38,7 +38,7 @@
             "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]",
             "actions": "5"
         },
-        "string_26list":
+        "string&list":
         {
             "value": "< & > ; \/",
             "default_value": "< & > ; \/",
@@ -50,7 +50,7 @@
     },
     "ss1":
     {
-        "double_201":
+        "double 1":
         {
             "value": "2.234",
             "default_value": "1.234",
@@ -61,7 +61,7 @@
         },
         "ss2":
         {
-            "double_202":
+            "double 2":
             {
                 "value": "5.321",
                 "default_value": "4.321",
index 824c2c36e57a72bc2b4132619251487aea5d995a..ab55c98c3e40a83222e87d55e18dbaf5de25da69 100644 (file)
@@ -16,9 +16,9 @@
         "pattern": "1",
         "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
     },
-    "Testing_25testing":
+    "Testing%testing":
     {
-        "double_2bdouble":
+        "double+double":
         {
             "value": "6.1415926",
             "default_value": "6.1415926",
@@ -26,7 +26,7 @@
             "pattern": "6",
             "pattern_description": "[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]"
         },
-        "int_2aint":
+        "int*int":
         {
             "value": "2",
             "default_value": "2",
@@ -34,7 +34,7 @@
             "pattern": "5",
             "pattern_description": "[Integer range -2147483648...2147483647 (inclusive)]"
         },
-        "string_26list":
+        "string&list":
         {
             "value": "< & > ; \/",
             "default_value": "< & > ; \/",
@@ -45,7 +45,7 @@
     },
     "ss1":
     {
-        "double_201":
+        "double 1":
         {
             "value": "1.234",
             "default_value": "1.234",
@@ -55,7 +55,7 @@
         },
         "ss2":
         {
-            "double_202":
+            "double 2":
             {
                 "value": "4.321",
                 "default_value": "4.321",
 {
     "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"
         }
     }
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.