*/
namespace Patterns
{
+
/**
* Base class to declare common
* interface. The purpose of this
virtual unsigned int memory_consumption () const;
};
+ /**
+ * Returns pointer to the correct
+ * derived class based on description.
+ */
+ PatternBase * pattern_factory (const std::string& description);
+
/**
* Test for the string being an
* integer. If bounds are given
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static Integer* create (const std::string& description);
private:
/**
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static Double* create (const std::string& description);
private:
/**
* bytes) of this object.
*/
unsigned int memory_consumption () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static Selection* create (const std::string& description);
private:
/**
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static List* create (const std::string& description);
/**
* Determine an estimate for
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static MultipleSelection* create (const std::string& description);
/**
* Determine an estimate for
*/
Bool ();
+ /**
+ * Return a description of
+ * the pattern that valid
+ * strings are expected to
+ * match.
+ */
+ virtual std::string description () const;
+
/**
* Return a copy of the
* present object, which is
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static Bool* create (const std::string& description);
+
+ private:
+ /**
+ * Initial part of description
+ */
+ static const char* description_init;
};
/**
* function.
*/
virtual PatternBase * clone () const;
-
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static Anything* create (const std::string& description);
+
+ private:
/**
* Initial part of description
*/
* file type flag
*/
FileType file_type;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static FileName* create (const std::string& description);
private:
/**
* function.
*/
virtual PatternBase * clone () const;
+
+ /**
+ * Creates new object if the start
+ * of description matches description_init.
+ * Ownership of that object is
+ * transferred to the caller of this
+ * function.
+ */
+ static DirectoryName* create (const std::string& description);
private:
/**
+ PatternBase* pattern_factory (const std::string& description)
+ {
+ PatternBase* p;
+
+ p = Integer::create(description);
+ if (p != 0)
+ return p;
+
+ p = Double::create(description);
+ if (p !=0 )
+ return p;
+
+ p = Selection::create(description);
+ if (p !=0 )
+ return p;
+
+ p = List::create(description);
+ if (p !=0 )
+ return p;
+
+ p = MultipleSelection::create(description);
+ if (p !=0 )
+ return p;
+
+ p = Bool::create(description);
+ if (p!=0 )
+ return p;
+
+ p = Anything::create(description);
+ if (p !=0 )
+ return p;
+
+ p = FileName::create(description);
+ if (p !=0 )
+ return p;
+
+ p = DirectoryName::create(description);
+ if (p!=0 )
+ return p;
+
+ Assert(false, ExcNotImplemented());
+
+ return 0;
+ }
+
+
+
PatternBase::~PatternBase ()
{}
return sizeof(*this) + 32;
}
-
+
const int Integer::min_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
+ Integer* Integer::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ std::istringstream is(description);
+
+ if(is.str().size() > strlen(description_init) + 1)
+ {
+//TODO: verify that description matches the pattern "^\[Integer range \d+\.\.\.\d+\]$"
+ int lower_bound, upper_bound;
+
+ is.ignore(strlen(description_init) + strlen(" range "));
+
+ if(!(is >> lower_bound))
+ return new Integer();
+
+ is.ignore(strlen("..."));
+
+ if(!(is >> upper_bound))
+ return new Integer();
+
+ return new Integer(lower_bound, upper_bound);
+ }
+ else
+ return new Integer();
+ }
+ else
+ return 0;
+ }
+
+
+
const double Double::min_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
-std::numeric_limits<double>::max();
+ Double* Double::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ std::istringstream is(description);
+
+ if(is.str().size() > strlen(description_init) + 1)
+ {
+ double lower_bound, upper_bound;
+
+ is.ignore(strlen(description_init) + strlen(" range "));
+
+ if(!(is >> lower_bound))
+ return new Double();
+
+ is.ignore(strlen("..."));
+
+ if(!(is >> upper_bound))
+ return new Double();
+
+ return new Double(lower_bound, upper_bound);
+ }
+ else
+ return new Double();
+ }
+ else
+ return 0;
+ }
+
+
+
const char* Selection::description_init = "[Selection";
+ Selection* Selection::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ std::string sequence(description);
+
+ sequence.erase(0, std::strlen(description_init) + 1);
+ sequence.erase(sequence.length()-2, 2);
+
+ return new Selection(sequence);
+ }
+ else
+ return 0;
+ }
+
+
+
const unsigned int List::max_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
std::numeric_limits<unsigned int>::max();
+ List* List::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ int min_elements, max_elements;
+
+ std::istringstream is(description);
+ is.ignore(strlen(description_init) + strlen(" list of <"));
+
+ std::auto_ptr<char> new_description (new char[is.str().size() + 1]);
+ is.getline(&(*new_description), is.str().size(), '>');
+ std::string str(&(*new_description));
+
+ std::auto_ptr<PatternBase> base_pattern (pattern_factory(str));
+
+ is.ignore(strlen(" of length "));
+ if(!(is >> min_elements))
+ return new List(*base_pattern);
+
+ is.ignore(strlen("..."));
+ if(!(is >> max_elements))
+ return new List(*base_pattern);
+
+ return new List(*base_pattern, min_elements, max_elements);
+ }
+ else
+ return 0;
+ }
+
+
+
const char* MultipleSelection::description_init = "[MultipleSelection";
+ MultipleSelection* MultipleSelection::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ std::string sequence(description);
+
+ sequence.erase(0, std::strlen(description_init) + 1);
+ sequence.erase(sequence.length()-2, 2);
+
+ return new MultipleSelection(sequence);
+ }
+ else
+ return 0;
+ }
+
+
+
+ const char* Bool::description_init = "[Bool";
+
+
Bool::Bool ()
:
Selection ("true|false")
+ std::string Bool::description () const
+ {
+ std::ostringstream description;
+
+ description << description_init
+ << "]";
+
+ return description.str();
+ }
+
+
+
PatternBase *
Bool::clone () const
{
+ Bool* Bool::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ return new Bool();
+ else
+ return 0;
+ }
+
+
+
const char* Anything::description_init = "[Anything";
+ Anything* Anything::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ return new Anything();
+ else
+ return 0;
+ }
+
+
+
const char* FileName::description_init = "[FileName";
+ FileName* FileName::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ {
+ std::istringstream is(description);
+ std::string file_type;
+ FileType type;
+
+ is.ignore(strlen(description_init) + strlen(" (Type:"));
+
+ is >> file_type;
+
+ if (file_type == "input)]")
+ type = input;
+ else
+ type = output;
+
+ return new FileName(type);
+ }
+ else
+ return 0;
+ }
+
+
+
const char* DirectoryName::description_init = "[DirectoryName";
return new DirectoryName();
}
+
+
+ DirectoryName* DirectoryName::create (const std::string& description)
+ {
+ if(description.compare(0, std::strlen(description_init), description_init) == 0)
+ return new DirectoryName();
+ else
+ return 0;
+ }
+
} // end namespace Patterns