From 99199a7def84fb1b9698bcfde19c9a4990d285bc Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 30 Apr 2013 19:10:25 +0000 Subject: [PATCH] ParameterHandler::set(., bool) which was broken, see bug #49. git-svn-id: https://svn.dealii.org/trunk@29415 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 6 ++ deal.II/source/base/parameter_handler.cc | 6 +- tests/bits/parameter_handler_6_bool.cc | 88 +++++++++++++++++++ .../bits/parameter_handler_6_bool/cmp/generic | 17 ++++ tests/bits/parameter_handler_6_bool/prm | 3 + 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 tests/bits/parameter_handler_6_bool.cc create mode 100644 tests/bits/parameter_handler_6_bool/cmp/generic create mode 100644 tests/bits/parameter_handler_6_bool/prm diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 399aac68cd..9136c23751 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -111,6 +111,12 @@ this function.
    +
  1. Fixed: The version of ParameterHandler::set that takes a boolean +as second argument was broken and did not work. This is now fixed. +
    +(Ashkan Dorostkar, Wolfgang Bangerth, 2013/04/30) +
  2. +
  3. Fixed: PETScWrappers::VectorBase::print now saves and restores the precision and width associated with the stream it prints to around setting diff --git a/deal.II/source/base/parameter_handler.cc b/deal.II/source/base/parameter_handler.cc index 2b019ada2c..6268cca617 100644 --- a/deal.II/source/base/parameter_handler.cc +++ b/deal.II/source/base/parameter_handler.cc @@ -1732,12 +1732,10 @@ void ParameterHandler::set (const std::string &entry_string, const bool &new_value) { - std::ostringstream s; - s << new_value; - // hand this off to the function that // actually sets the value as a string - set (entry_string, s.str()); + set (entry_string, + (new_value ? "true" : "false")); } diff --git a/tests/bits/parameter_handler_6_bool.cc b/tests/bits/parameter_handler_6_bool.cc new file mode 100644 index 0000000000..fe13a6916a --- /dev/null +++ b/tests/bits/parameter_handler_6_bool.cc @@ -0,0 +1,88 @@ +//---------------------------- parameter_handler_3.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2003, 2004, 2005, 2006, 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_3.cc --------------------------- + + +// test ParameterHandler::set(., bool) which was broken, see bug #49 + +#include "../tests.h" +#include +#include +#include +#include + + +int main () +{ + try + { + std::ofstream logfile("parameter_handler_6_bool/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + // same as parameter_handler_3 + ParameterHandler prm; + prm.enter_subsection ("Testing"); + prm.declare_entry ("bool", + "true", + Patterns::Bool(), + "docs 1"); + prm.leave_subsection (); + + prm.read_input("parameter_handler_6_bool/prm"); + + // now set the parameter to a different + // value + prm.enter_subsection ("Testing"); + prm.set ("bool", true); + prm.leave_subsection (); + + // then write + prm.print_parameters (logfile, ParameterHandler::Text); + + // and do it again with the opposite + // value + prm.enter_subsection ("Testing"); + prm.set ("bool", false); + prm.leave_subsection (); + + // then write + prm.print_parameters (logfile, ParameterHandler::Text); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + + return 0; +} diff --git a/tests/bits/parameter_handler_6_bool/cmp/generic b/tests/bits/parameter_handler_6_bool/cmp/generic new file mode 100644 index 0000000000..d60d4bff75 --- /dev/null +++ b/tests/bits/parameter_handler_6_bool/cmp/generic @@ -0,0 +1,17 @@ + +# Listing of Parameters +# --------------------- +subsection Testing + # docs 1 + set bool = true +end + + +# Listing of Parameters +# --------------------- +subsection Testing + # docs 1 + set bool = false # default: true +end + + diff --git a/tests/bits/parameter_handler_6_bool/prm b/tests/bits/parameter_handler_6_bool/prm new file mode 100644 index 0000000000..b964410bc0 --- /dev/null +++ b/tests/bits/parameter_handler_6_bool/prm @@ -0,0 +1,3 @@ +subsection Testing + set bool = false +end -- 2.39.5