From 411dca439083c811bd917acb68a3f4ce610e88cf Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 4 Aug 1999 11:55:47 +0000 Subject: [PATCH] Rename Patterns::Sequence to Patterns::Selection and introduce Patterns::MultipleSelectetion. git-svn-id: https://svn.dealii.org/trunk@1621 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/parameter_handler.h | 47 ++++++++-- deal.II/base/source/parameter_handler.cc | 94 +++++++++++++++++-- 2 files changed, 127 insertions(+), 14 deletions(-) diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index 581daab199..1ba627fc22 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -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 (); * }; diff --git a/deal.II/base/source/parameter_handler.cc b/deal.II/base/source/parameter_handler.cc index 3411378e3c..bfb2ae2579 100644 --- a/deal.II/base/source/parameter_handler.cc +++ b/deal.II/base/source/parameter_handler.cc @@ -8,6 +8,7 @@ #include #include #include +#include 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 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 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::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") {}; -- 2.39.5