From 6be5221f8b3111e26c0e71217e994eb82cffb3fe Mon Sep 17 00:00:00 2001 From: MFraters Date: Sun, 4 Mar 2018 03:25:43 +0100 Subject: [PATCH] add json parser for input files. --- include/deal.II/base/parameter_handler.h | 9 +++++++++ source/base/parameter_handler.cc | 15 +++++++++++++++ 2 files changed, 24 insertions(+) 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 () { -- 2.39.5