read_xml_recursively (const boost::property_tree::ptree &source,
const std::string ¤t_path,
const char path_separator,
+ const std::vector<std_cxx1x::shared_ptr<const Patterns::PatternBase> > &
+ patterns,
boost::property_tree::ptree &destination)
{
for (boost::property_tree::ptree::const_iterator p = source.begin();
path_separator +
"value"))
{
+ // first make sure that the
+ // new entry actually
+ // satisfies its constraints
+ const std::string new_value
+ = p->second.get<std::string>("value");
+
+ const unsigned int pattern_index
+ = destination.get<unsigned int> (full_path +
+ path_separator +
+ "pattern");
+ if (patterns[pattern_index]->match(new_value) == false)
+ {
+ std::cerr << " The entry value" << std::endl
+ << " " << new_value << std::endl
+ << " for the entry named" << std::endl
+ << " " << full_path << std::endl
+ << " does not match the given pattern" << std::endl
+ << " " << patterns[pattern_index]->description()
+ << std::endl;
+ return false;
+ }
+
// set the found parameter in
// the destination argument
destination.put (full_path + path_separator + "value",
- p->second.get_optional<std::string>("value"));
+ new_value);
// this node might have
// sub-nodes in addition to
p->first :
current_path + path_separator + p->first),
path_separator,
+ patterns,
destination);
// see if the recursive read
const boost::property_tree::ptree
&my_entries = single_node_tree.get_child("ParameterHandler");
- return read_xml_recursively (my_entries, "", path_separator, *entries);
+ return read_xml_recursively (my_entries, "", path_separator, patterns,
+ *entries);
}
<?xml version="1.0" encoding="utf-8"?>
-<ParameterHandler><int1><value> 2</value><default_value>1</default_value><documentation>doc 1</documentation><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int1><int2><value> 3</value><default_value>2</default_value><documentation>doc 2</documentation><pattern>1</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int2><ss1><double_201><value> 2.234</value><default_value>1.234</default_value><documentation>doc 3</documentation><pattern>2</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_201><ss2><double_202><value> 5.321</value><default_value>4.321</default_value><documentation>doc 4</documentation><pattern>3</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_202></ss2></ss1><Testing_25testing><string_26list><value> __< & > ; /</value><default_value>< & > ; /</default_value><documentation>docs 1</documentation><pattern>4</pattern><pattern_description>[Anything]</pattern_description></string_26list><int_2aint><value> __2</value><default_value>2</default_value><documentation/><pattern>5</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int_2aint><double_2bdouble><value> 7.1415926</value><default_value>6.1415926</default_value><documentation>docs 3</documentation><pattern>6</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_2bdouble></Testing_25testing></ParameterHandler>
+<ParameterHandler><int1><value> 2</value><default_value>1</default_value><documentation>doc 1</documentation><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int1><int2><value> 3</value><default_value>2</default_value><documentation>doc 2</documentation><pattern>1</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int2><ss1><double_201><value> 2.234</value><default_value>1.234</default_value><documentation>doc 3</documentation><pattern>2</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_201><ss2><double_202><value> 5.321</value><default_value>4.321</default_value><documentation>doc 4</documentation><pattern>3</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_202></ss2></ss1><Testing_25testing><string_26list><value> __< & > ; /</value><default_value>< & > ; /</default_value><documentation>docs 1</documentation><pattern>4</pattern><pattern_description>[Anything]</pattern_description></string_26list><int_2aint><value> 2</value><default_value>2</default_value><documentation/><pattern>5</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int_2aint><double_2bdouble><value> 7.1415926</value><default_value>6.1415926</default_value><documentation>docs 3</documentation><pattern>6</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_2bdouble></Testing_25testing></ParameterHandler>
<?xml version="1.0" encoding="utf-8"?>
-<ParameterHandler><int1><value>2</value><default_value>1</default_value><documentation>doc 1</documentation><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int1><int2><value>3</value><default_value>2</default_value><documentation>doc 2</documentation><pattern>1</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int2><ss1><double_201><value>2.234</value><default_value>1.234</default_value><documentation>doc 3</documentation><pattern>2</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_201><ss2><double_202><value>5.321</value><default_value>4.321</default_value><documentation>doc 4</documentation><pattern>3</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_202></ss2></ss1><Testing_25testing><string_26list><value>__< & > ; /</value><default_value>< & > ; /</default_value><documentation>docs 1</documentation><pattern>4</pattern><pattern_description>[Anything]</pattern_description></string_26list><int_2aint><value>__2</value><default_value>2</default_value><documentation/>
+<ParameterHandler><int1><value>2</value><default_value>1</default_value><documentation>doc 1</documentation><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int1><int2><value>3</value><default_value>2</default_value><documentation>doc 2</documentation><pattern>1</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int2><ss1><double_201><value>2.234</value><default_value>1.234</default_value><documentation>doc 3</documentation><pattern>2</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_201><ss2><double_202><value>5.321</value><default_value>4.321</default_value><documentation>doc 4</documentation><pattern>3</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_202></ss2></ss1><Testing_25testing><string_26list><value>__< & > ; /</value><default_value>< & > ; /</default_value><documentation>docs 1</documentation><pattern>4</pattern><pattern_description>[Anything]</pattern_description></string_26list><int_2aint><value>2</value><default_value>2</default_value><documentation/>
<pattern>5</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int_2aint><double_2bdouble><value>7.1415926</value><default_value>6.1415926</default_value><documentation>docs 3</documentation><pattern>6</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_2bdouble></Testing_25testing></ParameterHandler>
--- /dev/null
+//---------------------------- parameter_handler_read_xml_error_04.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2002, 2003, 2004, 2005, 2010 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- parameter_handler_read_xml_error_04.cc ---------------------------
+
+
+// check ParameterHandler::read_input_from_xml. try to read a file with a
+// parameter that does not satisfy its pattern
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <base/parameter_handler.h>
+#include <fstream>
+
+
+int main ()
+{
+ std::ofstream logfile("parameter_handler_read_xml_error_04/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ ParameterHandler prm;
+ prm.declare_entry ("int1",
+ "1",
+ Patterns::Integer(),
+ "doc 1");
+ prm.declare_entry ("int2",
+ "2",
+ Patterns::Integer(),
+ "doc 2");
+ prm.enter_subsection ("ss1");
+ {
+ prm.declare_entry ("double 1",
+ "1.234",
+ Patterns::Double(),
+ "doc 3");
+
+ prm.enter_subsection ("ss2");
+ {
+ prm.declare_entry ("double 2",
+ "4.321",
+ Patterns::Double(),
+ "doc 4");
+ }
+ prm.leave_subsection ();
+ }
+ prm.leave_subsection ();
+
+ // things with strange characters
+ prm.enter_subsection ("Testing%testing");
+ {
+ prm.declare_entry ("string&list",
+ "< & > ; /",
+ Patterns::Anything(),
+ "docs 1");
+ prm.declare_entry ("int*int",
+ "2",
+ Patterns::Integer());
+ prm.declare_entry ("double+double",
+ "6.1415926",
+ Patterns::Double(),
+ "docs 3");
+ }
+ prm.leave_subsection ();
+
+ // read from XML
+ std::ifstream in ("parameter_handler_read_xml_error_04/prm");
+ bool result = prm.read_input_from_xml (in);
+ Assert (result == false, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+
+ return 0;
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+<?xml version="1.0" encoding="utf-8"?>
+<ParameterHandler><int1><value>2x</value><default_value>1</default_value><documentation>doc 1</documentation><pattern>0</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int1><int2><value>3</value><default_value>2</default_value><documentation>doc 2</documentation><pattern>1</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int2><ss1><double_201><value>2.234</value><default_value>1.234</default_value><documentation>doc 3</documentation><pattern>2</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_201><ss2><double_202><value>5.321</value><default_value>4.321</default_value><documentation>doc 4</documentation><pattern>3</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_202></ss2></ss1><Testing_25testing><string_26list><value>__< & > ; /</value><default_value>< & > ; /</default_value><documentation>docs 1</documentation><pattern>4</pattern><pattern_description>[Anything]</pattern_description></string_26list><int_2aint><value>2</value><default_value>2</default_value><documentation/>
+<pattern>5</pattern><pattern_description>[Integer range -2147483648...2147483647 (inclusive)]</pattern_description></int_2aint><double_2bdouble><value>7.1415926</value><default_value>6.1415926</default_value><documentation>docs 3</documentation><pattern>6</pattern><pattern_description>[Double -1.79769e+308...1.79769e+308 (inclusive)]</pattern_description></double_2bdouble></Testing_25testing></ParameterHandler>