// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
/**
* Return value of entry
- * <tt>entry_string</tt> as
+ * <tt>entry_name</tt> as
* <tt>double</tt>.
*/
- double get_double (const std::string &entry_string) const;
+ double get_double (const std::string &entry_name) const;
/**
* Return value of entry
- * <tt>entry_string</tt> as <tt>bool</tt>.
+ * <tt>entry_name</tt> as <tt>bool</tt>.
* The entry may be "true" or "yes"
* for <tt>true</tt>, "false" or
* "no" for <tt>false</tt> respectively.
*/
- bool get_bool (const std::string &entry_string) const;
+ bool get_bool (const std::string &entry_name) const;
+
+ /**
+ * Change the value presently stored for
+ * <tt>entry_name</tt> to the one given
+ * in the second argument.
+ *
+ * The parameter must already exist in
+ * the present subsection.
+ */
+ void set (const std::string &entry_name,
+ const std::string &new_value);
+ void set (const std::string &entry_name,
+ const char *new_value);
+
+ /**
+ * Change the value presently stored for
+ * <tt>entry_name</tt> to the one given
+ * in the second argument.
+ *
+ * The parameter must already exist in
+ * the present subsection.
+ */
+ void set (const std::string &entry_name,
+ const long int &new_value);
+
+ /**
+ * Change the value presently stored for
+ * <tt>entry_name</tt> to the one given
+ * in the second argument.
+ *
+ * The parameter must already exist in
+ * the present subsection.
+ *
+ * For internal purposes, the new value
+ * needs to be converted to a
+ * string. This is done using 16 digits
+ * of accuracy, so the set value and the
+ * one you can get back out using
+ * get_double() may differ in the 16th
+ * digit.
+ */
+ void set (const std::string &entry_name,
+ const double &new_value);
+
+ /**
+ * Change the value presently stored for
+ * <tt>entry_name</tt> to the one given
+ * in the second argument.
+ *
+ * The parameter must already exist in
+ * the present subsection.
+ */
+ void set (const std::string &entry_name,
+ const bool &new_value);
+
+
/**
* Print all parameters with the
* given style to
// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
-const std::string & ParameterHandler::get (const std::string &entry_string) const
+const std::string &
+ParameterHandler::get (const std::string &entry_string) const
{
const Section* pd = get_present_defaults_subsection ();
const Section* pc = get_present_changed_subsection ();
- // assert that the according entry is already
- // declared in the defaults tree
+ // assert that the according entry is
+ // already declared in the defaults tree
Assert (pd->entries.find (entry_string) != pd->entries.end(),
ExcEntryUndeclared(entry_string));
{
std::string s = get(entry_string);
- AssertThrow ((s=="true") || (s=="false") || (s=="yes") || (s=="no"), ExcConversionError(s));
+ AssertThrow ((s=="true") || (s=="false") ||
+ (s=="yes") || (s=="no"),
+ ExcConversionError(s));
if (s=="true" || s=="yes")
return true;
else
+void
+ParameterHandler::set (const std::string &entry_string,
+ const std::string &new_value)
+{
+ const Section* pd = get_present_defaults_subsection ();
+ Section* pc = get_present_changed_subsection ();
+
+ // assert that the according entry is
+ // already declared in the defaults tree
+ Assert (pd->entries.find (entry_string) != pd->entries.end(),
+ ExcEntryUndeclared(entry_string));
+
+ // entry exists; now set it (if the entry
+ // in pc hasn't existed yet, create it and
+ // set the pattern to the null pointer
+ // since it isn't used)
+ if (pc->entries.find (entry_string) == pc->entries.end())
+ pc->entries[entry_string].pattern = 0;
+ pc->entries[entry_string].value = new_value;
+}
+
+
+void
+ParameterHandler::set (const std::string &entry_string,
+ const char *new_value)
+{
+ // simply forward
+ set (entry_string, std::string(new_value));
+}
+
+
+void
+ParameterHandler::set (const std::string &entry_string,
+ const double &new_value)
+{
+#ifdef HAVE_STD_STRINGSTREAM
+ std::ostringstream s;
+#else
+ std::ostrstream s;
+#endif
+ s << std::setprecision(16);
+ s << new_value;
+#ifndef HAVE_STD_STRINGSTREAM
+ s << std::ends;
+#endif
+
+ // hand this off to the function that
+ // actually sets the value as a string
+ set (entry_string, s.str());
+}
+
+
+
+void
+ParameterHandler::set (const std::string &entry_string,
+ const long int &new_value)
+{
+#ifdef HAVE_STD_STRINGSTREAM
+ std::ostringstream s;
+#else
+ std::ostrstream s;
+#endif
+ s << new_value;
+#ifndef HAVE_STD_STRINGSTREAM
+ s << std::ends;
+#endif
+
+ // hand this off to the function that
+ // actually sets the value as a string
+ set (entry_string, s.str());
+}
+
+
+
+void
+ParameterHandler::set (const std::string &entry_string,
+ const bool &new_value)
+{
+#ifdef HAVE_STD_STRINGSTREAM
+ std::ostringstream s;
+#else
+ std::ostrstream s;
+#endif
+ s << new_value;
+#ifndef HAVE_STD_STRINGSTREAM
+ s << std::ends;
+#endif
+
+ // hand this off to the function that
+ // actually sets the value as a string
+ set (entry_string, s.str());
+}
+
+
+
std::ostream &
ParameterHandler::print_parameters (std::ostream &out,
const OutputStyle style)
<link href="../screen.css" rel="StyleSheet">
<title>The deal.II news page</title>
<meta name="author" content="the deal.II authors <authors@dealii.org>">
- <meta name="copyright" content="Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors">
+ <meta name="copyright" content="Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors">
<meta name="date" content="$Date$">
<meta name="keywords" content="deal.II"></head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<h3>base</h3>
<ol>
+ <li> <p>
+ New: There are now functions
+ <code>ParameterHandler::set</code> that allow to set the value of a
+ parameter to something different later on.
+ <br>
+ (Marc Secanell, WB 2006/1/2)
+ </p>
+
<li> <p>
New: There are new functions
<code>Utilities::match_at_string_start</code> and
--- /dev/null
+//---------------------------- parameter_handler_3.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2003, 2004, 2005, 2006 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(Text)
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <base/parameter_handler.h>
+#include <fstream>
+#include <iostream>
+
+
+int main ()
+{
+ try
+ {
+ std::ofstream logfile("parameter_handler_6/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 ("string list",
+ "a",
+ Patterns::List(Patterns::Selection("a|b|c|d|e|f|g|h")),
+ "docs 1");
+ prm.declare_entry ("int",
+ "1",
+ Patterns::Integer());
+ prm.declare_entry ("double",
+ "3.1415926",
+ Patterns::Double(),
+ "docs 3");
+ prm.leave_subsection ();
+
+ prm.read_input("parameter_handler_3.prm");
+
+ // now set some of the entries to
+ // different values
+ prm.enter_subsection ("Testing");
+ prm.set ("string list", "a, c, b");
+ prm.set ("int", "5");
+ prm.set ("double", "2.71828");
+ prm.leave_subsection ();
+
+ // then write
+ prm.print_parameters (logfile, ParameterHandler::Text);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+
+ return 0;
+}
--- /dev/null
+
+# Listing of Parameters
+# ---------------------
+subsection Testing
+ # docs 3
+ set double = 2.71828 # default: 3.1415926
+ set int = 5 # default: 1
+
+ # docs 1
+ set string list = a, c, b # default: a
+end
+
+