From: MFraters Date: Sun, 4 Mar 2018 02:25:43 +0000 (+0100) Subject: add json parser for input files. X-Git-Tag: v9.0.0-rc1~337^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6be5221f8b3111e26c0e71217e994eb82cffb3fe;p=dealii.git add json parser for input files. --- diff --git a/include/deal.II/base/parameter_handler.h b/include/deal.II/base/parameter_handler.h index 95668d351d..0635f28027 100644 --- a/include/deal.II/base/parameter_handler.h +++ b/include/deal.II/base/parameter_handler.h @@ -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. */ diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 604e1d0f3f..0b392a4cd5 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -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 () {