]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add json parser for input files.
authorMFraters <menno.fraters@hotmail.com>
Sun, 4 Mar 2018 02:25:43 +0000 (03:25 +0100)
committerMFraters <menno.fraters@hotmail.com>
Thu, 8 Mar 2018 16:15:42 +0000 (17:15 +0100)
include/deal.II/base/parameter_handler.h
source/base/parameter_handler.cc

index 95668d351dab3297e39ba05a78494b8e51c68e46..0635f280275a1c8f727fb021a817e5a1340d9b03 100644 (file)
@@ -963,6 +963,15 @@ public:
    */
   virtual void parse_input_from_xml (std::istream &input);
 
+  /**
+   * Parse input from an JSON stream to populate known parameter fields. This
+   * could be from a file originally written by the print_parameters() function
+   * using the XML output style and then modified by hand as necessary, or from
+   * a file written using this method and then modified by the graphical
+   * parameter GUI (see the general documentation of this class).
+   */
+  virtual void parse_input_from_json (std::istream &input);
+
   /**
    * Clear all contents.
    */
index 604e1d0f3fbde194e45937a15c252baba679b1e1..0b392a4cd5e5cc43f28a414e5c84d657288c5b18 100644 (file)
@@ -580,6 +580,21 @@ void ParameterHandler::parse_input_from_xml (std::istream &in)
 }
 
 
+void ParameterHandler::parse_input_from_json (std::istream &in)
+{
+  AssertThrow(in, ExcIO());
+
+  boost::property_tree::ptree node_tree;
+  // This boost function will raise an exception if this is not a valid JSON
+  // file.
+  read_json (in, node_tree);
+
+  // The xml function is reused to read in the xml into the paramter file.
+  // This means that only mangled files can be read.
+  read_xml_recursively (node_tree, "", path_separator, patterns, *entries);
+}
+
+
 
 void ParameterHandler::clear ()
 {

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.