* 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;
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;
* 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());
* 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());
* 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 ();
*
* 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 ();
* };
#include <strstream>
#include <cstdlib>
#include <algorithm>
+#include <list>
bool Patterns::Integer::match (const string &test_string) 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)
};
-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
};
-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")
{};