]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Rename Patterns::Sequence to Patterns::Selection and introduce Patterns::MultipleSele...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 Aug 1999 11:55:47 +0000 (11:55 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 Aug 1999 11:55:47 +0000 (11:55 +0000)
git-svn-id: https://svn.dealii.org/trunk@1621 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 581daab19948a5b581943f51a2df38e5ec173585..1ba627fc22148731382eb46513ed2d733c8aa4ca 100644 (file)
@@ -103,9 +103,9 @@ struct Patterns {
                                      * signs do not matter and are
                                      * eliminated.
                                      */
-    class Sequence : public PatternBase {
+    class Selection : public PatternBase {
       public:
-       Sequence (const string &seq);
+       Selection (const string &seq);
        virtual bool match (const string &test_string) const;
        virtual string description () const;
        virtual PatternBase * clone () const;
@@ -113,12 +113,43 @@ struct Patterns {
        string sequence;
     };
 
+
+                                    /**
+                                     * This class is much like the #Selection#
+                                     * class, but it allows the input to be
+                                     * a comma-separated list of values which
+                                     * each have to be given in the constructor
+                                     * argument. For example, if the string to
+                                     * the constructor was #"ucd|gmv|eps"#, then
+                                     * the following would be legal input:
+                                     * #eps, gmv#. You may give an arbitrarily
+                                     * long list of values, where there may be
+                                     * as many spaces around commas as you like.
+                                     * However, commas are not allowed inside
+                                     * the values given to the constructor.
+                                     */
+    class MultipleSelection : public PatternBase {
+      public:
+       MultipleSelection (const string &seq);
+       virtual bool match (const string &test_string) const;
+       virtual string description () const;
+       virtual PatternBase * clone () const;
+
+       DeclException1 (ExcCommasNotAllowed,
+                       int,
+                       << "A comma was found at position " << arg1
+                       << " of your input string, but commas are not allowed here.");
+       
+      private:
+       string sequence;
+    };
+
                                     /**
                                      * Test for the string being either
                                      * "true" or "false". This is mapped
-                                     * to the #Sequence# class.
+                                     * to the #Selection# class.
                                      */
-    class Bool : public Sequence {
+    class Bool : public Selection {
       public:
        Bool ();
        virtual PatternBase * clone () const;
@@ -196,7 +227,7 @@ struct Patterns {
  *       prm.enter_subsection("Linear solver");
  *       prm.declare_entry ("Solver",
  *                          "CG",
- *                         Patterns::Sequence("CG|GMRES|GaussElim"));
+ *                         Patterns::Selection("CG|GMRES|GaussElim"));
  *       prm.declare_entry ("Maximum number of iterations",
  *                          "20",
  *                         ParameterHandler::RegularExpressions::Integer());
@@ -407,7 +438,7 @@ struct Patterns {
  *       prm.enter_subsection ("Linear solver");
  *       prm.declare_entry ("Solver",
  *                          "CG",
- *                          Patterns::Sequence("CG|BiCGStab|GMRES"));
+ *                          Patterns::Selection("CG|BiCGStab|GMRES"));
  *       prm.declare_entry ("Maximum number of iterations",
  *                          "20",
  *                          Patterns::Integer());
@@ -442,7 +473,7 @@ struct Patterns {
  *       prm.enter_subsection ("Equation 1");
  *       prm.declare_entry ("Matrix type",
  *                          "Sparse",
- *                          Patterns::Sequence("Full|Sparse|Diagonal"));
+ *                          Patterns::Selection("Full|Sparse|Diagonal"));
  *       LinEq::declare_parameters (prm);  // for eq1
  *       prm.leave_subsection ();
  *           
@@ -451,7 +482,7 @@ struct Patterns {
  *       prm.enter_subsection ("Equation 2");
  *       prm.declare_entry ("Matrix type",
  *                          "Sparse",
- *                          Patterns::Sequence("Full|Sparse|Diagonal"));
+ *                          Patterns::Selection("Full|Sparse|Diagonal"));
  *       LinEq::declare_parameters (prm);  // for eq2
  *       prm.leave_subsection ();
  *     };
index 3411378e3c7228f808bc8fe04285103393dccd27..bfb2ae2579df4d27a2ede9438a263547a18a7a01 100644 (file)
@@ -8,6 +8,7 @@
 #include <strstream>
 #include <cstdlib>
 #include <algorithm>
+#include <list>
 
 
 bool Patterns::Integer::match (const string &test_string) const {
@@ -49,8 +50,9 @@ Patterns::Double::clone () const {
 
 
 
-Patterns::Sequence::Sequence (const string &seq) {
+Patterns::Selection::Selection (const string &seq) {
   sequence = seq;
+
   while (sequence.find(" |") != string::npos)
     sequence.replace (sequence.find(" |"), 2, '|');
   while (sequence.find("| ") != string::npos)
@@ -58,7 +60,7 @@ Patterns::Sequence::Sequence (const string &seq) {
 };
 
 
-bool Patterns::Sequence::match (const string &test_string) const {
+bool Patterns::Selection::match (const string &test_string) const {
   vector<string> choices;
   string tmp(sequence);
                                   // check the different possibilities
@@ -78,20 +80,100 @@ bool Patterns::Sequence::match (const string &test_string) const {
 };
 
 
-string Patterns::Sequence::description () const {
+string Patterns::Selection::description () const {
+  return sequence;
+};
+
+
+Patterns::PatternBase *
+Patterns::Selection::clone () const {
+  return new Patterns::Selection(sequence);
+};
+
+
+
+Patterns::MultipleSelection::MultipleSelection (const string &seq) {
+  Assert (seq.find (",") == string::npos, ExcCommasNotAllowed(seq.find(",")));
+  
+  sequence = seq;
+  while (sequence.find(" |") != string::npos)
+    sequence.replace (sequence.find(" |"), 2, '|');
+  while (sequence.find("| ") != string::npos)
+    sequence.replace (sequence.find("| "), 2, '|');
+};
+
+
+bool Patterns::MultipleSelection::match (const string &test_string_list) const {
+  string tmp = test_string_list;
+  list<string> split_list;
+
+                                  // first split the input list
+  while (tmp.length())
+    {
+      string name;
+      name = tmp;
+      
+      if (name.find(",") != string::npos)
+       {
+         name.erase (name.find(","), string::npos);
+         tmp.erase (0, test_string_list.find(",")+1);
+       }
+      else
+       tmp = "";
+      
+      while (name[0] == ' ')
+       name.erase (0,1);
+      while (name[name.length()-1] == ' ')
+       name.erase (name.length()-1, 1);
+
+      split_list.push_back (name);
+    };
+  
+
+                                  // check the different possibilities
+  for (list<string>::const_iterator test_string = split_list.begin();
+       test_string != split_list.end(); ++test_string) 
+    {
+      bool string_found = false;
+      
+      tmp = sequence;
+      while (tmp.find('|') != string::npos) 
+       {
+         if (*test_string == string(tmp, 0, tmp.find('|')))
+           {
+             string_found = true;
+             continue;
+           };
+         
+         tmp.erase (0, tmp.find('|')+1);
+       };
+                                      // check last choice, not finished by |
+      if (!string_found)
+       if (*test_string == tmp)
+         string_found = true;
+
+      if (!string_found)
+       return false;
+    };
+
+  return true;
+};
+
+
+string Patterns::MultipleSelection::description () const {
   return sequence;
 };
 
 
 Patterns::PatternBase *
-Patterns::Sequence::clone () const {
-  return new Patterns::Sequence(sequence);
+Patterns::MultipleSelection::clone () const {
+  return new Patterns::Selection(sequence);
 };
 
 
 
 Patterns::Bool::Bool () :
-               Sequence ("true|false")
+               Selection ("true|false")
 {};
 
 

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.