* numbers, every character in their names that is not a letter or number
* is replaced
* by an underscore followed by its two-digit hexadecimal representation.
- * In addition, the special names "value", "default_value", "pattern",
- * "pattern_index", and "documentation" are mangled when used as
- * names of parameters given that these names are also used to name
+ * In addition, the special name "value" is mangled when used as the
+ * name of a parameter, given that this name is also used to name
* special files in the hierarchy structure.
* Finally, the entire tree is wrapped into a tag
* <code>%ParameterHandler</code> to satisfy the XML requirement that there
// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011, 2012 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011, 2012, 2013 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
ParameterHandler::mangle (const std::string &s)
{
std::string u;
+
+ // reserve the minimum number of characters we will need. it may
+ // be more but this is the least we can do
u.reserve (s.size());
- static const std::string allowed_characters
- ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+ // see if the name is special and if so mangle the whole thing
+ const bool mangle_whole_string = (s == "value");
// for all parts of the string, see
// if it is an allowed character or
// not
for (unsigned int i=0; i<s.size(); ++i)
- if (allowed_characters.find (s[i]) != std::string::npos)
- u.push_back (s[i]);
- else
- {
- u.push_back ('_');
- static const char hex[16]
- = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- u.push_back (hex[static_cast<unsigned char>(s[i])/16]);
- u.push_back (hex[static_cast<unsigned char>(s[i])%16]);
- }
+ {
+ static const std::string allowed_characters
+ ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+
+ if (mangle_whole_string
+ ||
+ (allowed_characters.find (s[i]) != std::string::npos))
+ u.push_back (s[i]);
+ else
+ {
+ u.push_back ('_');
+ static const char hex[16]
+ = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
+ u.push_back (hex[static_cast<unsigned char>(s[i])/16]);
+ u.push_back (hex[static_cast<unsigned char>(s[i])%16]);
+ }
+ }
return u;
}
bool
ParameterHandler::is_parameter_node (const boost::property_tree::ptree &p)
{
- // A parameter node must have a value key
- if (p.get_optional<std::string>("value"))
- {
- // and the associated child ptree must be final, i.e. no children:
- if(p.get_child("value").size() == 0)
- return true;
- }
- return false;
+ return (p.get_optional<std::string>("value"));
}
--- /dev/null
+//---------------------------- parameter_handler_14.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2002, 2003, 2004, 2005, 2010, 2012, 2013 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_14.cc ---------------------------
+
+
+// ParameterHandler could not deal with parameters named "value" as well as a
+// few other names. see the thread on the mailing starting with a post by
+// Denis Davydov on March 30, 2013
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+void check ()
+{
+ ParameterHandler foo;
+ foo.enter_subsection("bar");
+ foo.declare_entry("value", "1.0", dealii::Patterns::Double(), "");
+ foo.leave_subsection();
+
+ try
+ {
+ foo.read_input("parameter_handler_14/tmp.prm");
+ }
+ catch (...)
+ {
+ deallog << "Exception caught, but none should happen here!!!"
+ << std::endl;
+ }
+
+ foo.enter_subsection("bar");
+ deallog << foo.get ("value") << std::endl;
+ foo.leave_subsection();
+
+ // delete tmp file again
+ std::remove("parameter_handler_14/tmp.prm");
+}
+
+
+int main ()
+{
+ std::ofstream logfile("parameter_handler_14/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ check ();
+
+ return 0;
+}