From: Wolfgang Bangerth Date: Mon, 24 Aug 1998 08:13:09 +0000 (+0000) Subject: Add functions to get a bool variable out of the parameter handler module. X-Git-Tag: v8.0.0~22745 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e540198c52a463863038dbb68dffee6a4e67269;p=dealii.git Add functions to get a bool variable out of the parameter handler module. git-svn-id: https://svn.dealii.org/trunk@509 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index 19e6c989ef..77dc43b07f 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -111,7 +111,18 @@ struct Patterns { private: string sequence; }; - + + /** + * Test for the string being either + * "true" or "false". This is mapped + * to the #Sequence# class. + */ + class Bool : public Sequence { + public: + Bool (); + virtual PatternBase * clone () const; + }; + /** * Always returns true when testing a * string. @@ -302,8 +313,9 @@ struct Patterns { * i.e. an input entry value which does not match the regular expression is not stored. * * You can use #get# to retrieve the parameter in text form, #get_integer# to get an integer - * or #get_double# to get a double. It will cause an internal error if - * the string could not be converted to an integer or a double. This should, though, not + * or #get_double# to get a double. You can also use #get_bool#. + * It will cause an internal error if the string could not be + * converted to an integer, double or a bool. This should, though, not * happen if you correctly specified the regular expression for this entry; you should not * try to get out an integer or a double from an entry for which no according regular * expression was set. The internal error is raised through the #Assert()# macro family @@ -638,16 +650,21 @@ class ParameterHandler { /** * Return value of entry #entry_string# as - * long integer. + * #long int#. */ long int get_integer (const string &entry_string) const; /** * Return value of entry #entry_string# as - * double. + * #double#. */ double get_double (const string &entry_string) const; + /** + * Return value of entry #entry_string# as + * #bool#. + */ + bool get_bool (const string &entry_string) const; /** * Print all parameters with the given style * to #out#. Presently only Text and LaTeX diff --git a/deal.II/base/source/parameter_handler.cc b/deal.II/base/source/parameter_handler.cc index 8758a728b8..27400efe2a 100644 --- a/deal.II/base/source/parameter_handler.cc +++ b/deal.II/base/source/parameter_handler.cc @@ -88,6 +88,18 @@ Patterns::Sequence::clone () const { +Patterns::Bool::Bool () : + Sequence ("true|false") +{}; + + +Patterns::PatternBase * +Patterns::Bool::clone () const { + return new Patterns::Bool(); +}; + + + bool Patterns::Anything::match (const string &) const { return true; }; @@ -330,6 +342,17 @@ double ParameterHandler::get_double (const string &entry_string) const { +bool ParameterHandler::get_bool (const string &entry_string) const { + string s = get(entry_string); + + Assert ((s=="true") || (s=="false"), ExcConversionError(s)); + if (s=="true") + return true; + else + return false; +}; + + ostream & ParameterHandler::print_parameters (ostream &out, OutputStyle style) { // assert that only known formats are