]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add functions to get a bool variable out of the parameter handler module.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 24 Aug 1998 08:13:09 +0000 (08:13 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 24 Aug 1998 08:13:09 +0000 (08:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@509 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/parameter_handler.h
deal.II/base/source/parameter_handler.cc

index 19e6c989efd1e13e2fd19659a55606b02eb7b00a..77dc43b07f87a12f22071222738a7f7cc4c253f7 100644 (file)
@@ -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
index 8758a728b8d5c6a767eb9a05e590b0518e3a2eee..27400efe2a1a38aa21b3978c15bb1853edf21d38 100644 (file)
@@ -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

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.