]> https://gitweb.dealii.org/ - dealii.git/commitdiff
ParameterHandler::set(., bool) which was broken, see bug #49.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 30 Apr 2013 19:10:25 +0000 (19:10 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 30 Apr 2013 19:10:25 +0000 (19:10 +0000)
git-svn-id: https://svn.dealii.org/trunk@29415 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/base/parameter_handler.cc
tests/bits/parameter_handler_6_bool.cc [new file with mode: 0644]
tests/bits/parameter_handler_6_bool/cmp/generic [new file with mode: 0644]
tests/bits/parameter_handler_6_bool/prm [new file with mode: 0644]

index 399aac68cd0b96eab536b18eec98152497020b5f..9136c2375149f4a8a234330bd29d5a9ec4a40b91 100644 (file)
@@ -111,6 +111,12 @@ this function.
 
 <ol>
 
+<li> Fixed: The version of ParameterHandler::set that takes a boolean
+as second argument was broken and did not work. This is now fixed.
+<br>
+(Ashkan Dorostkar, Wolfgang Bangerth, 2013/04/30)
+</li>
+
 <li> Fixed: PETScWrappers::VectorBase::print now saves and restores
 the precision
 and width associated with the stream it prints to around setting
index 2b019ada2c3aff87242fe5911b3100e1c1e66135..6268cca6175af63322c0b990bfea5a9450f48439 100644 (file)
@@ -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 (file)
index 0000000..fe13a69
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+#include <iomanip>
+
+
+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 (file)
index 0000000..d60d4bf
--- /dev/null
@@ -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 (file)
index 0000000..b964410
--- /dev/null
@@ -0,0 +1,3 @@
+subsection Testing
+  set bool = false
+end

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.