From: Wolfgang Bangerth Date: Sun, 31 Mar 2013 21:48:23 +0000 (+0000) Subject: Fix ParameterHandler in a different way. X-Git-Tag: v8.0.0~834 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58eb389e01049ad589e09dfc005e24979460a32d;p=dealii.git Fix ParameterHandler in a different way. git-svn-id: https://svn.dealii.org/trunk@29126 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index d108c770aa..af36ae7ade 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -89,6 +89,12 @@ this function.
    +
  1. Fixed: The ParameterHandler class could not deal with parameters named +"value" (and a few other names). This is now fixed. +
    +(Denis Davydov, Matthias Maier, Wolfgang Bangerth, 2013/3/31) +
  2. +
  3. Changed: TimerOutput no longer assumes that sections are not nested when outputting percentage and total run time.
    diff --git a/deal.II/include/deal.II/base/parameter_handler.h b/deal.II/include/deal.II/base/parameter_handler.h index 7d1a7ba379..bf9aad7c0e 100644 --- a/deal.II/include/deal.II/base/parameter_handler.h +++ b/deal.II/include/deal.II/base/parameter_handler.h @@ -1772,9 +1772,8 @@ namespace Patterns * 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 * %ParameterHandler to satisfy the XML requirement that there diff --git a/deal.II/source/base/parameter_handler.cc b/deal.II/source/base/parameter_handler.cc index 40c512cce1..c1846a87cb 100644 --- a/deal.II/source/base/parameter_handler.cc +++ b/deal.II/source/base/parameter_handler.cc @@ -2,7 +2,7 @@ // $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 @@ -1067,25 +1067,35 @@ std::string 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[i])/16]); - u.push_back (hex[static_cast(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(s[i])/16]); + u.push_back (hex[static_cast(s[i])%16]); + } + } return u; } @@ -1228,14 +1238,7 @@ ParameterHandler::demangle (const std::string &s) bool ParameterHandler::is_parameter_node (const boost::property_tree::ptree &p) { - // A parameter node must have a value key - if (p.get_optional("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("value")); } diff --git a/tests/bits/parameter_handler_14.cc b/tests/bits/parameter_handler_14.cc new file mode 100644 index 0000000000..74dca556c0 --- /dev/null +++ b/tests/bits/parameter_handler_14.cc @@ -0,0 +1,60 @@ +//---------------------------- 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 +#include +#include + +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; +} diff --git a/tests/bits/parameter_handler_14/cmp/generic b/tests/bits/parameter_handler_14/cmp/generic new file mode 100644 index 0000000000..3d77c7dfcc --- /dev/null +++ b/tests/bits/parameter_handler_14/cmp/generic @@ -0,0 +1,3 @@ + +DEAL::Exception caught, but none should happen here!!! +DEAL::1.0