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 )
+ if (p !=0 )
return p;
-
+
p = MultipleSelection::create(description);
- if (p !=0 )
+ 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
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
else
return 0;
}
-
+
const double Double::min_double_value =
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
else
return 0;
}
-
+
const char* Selection::description_init = "[Selection";
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 =
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;
}
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")
return new Bool();
else
return 0;
- }
+ }
return new Anything();
else
return 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
+ else
type = output;
-
+
return new FileName(type);
- }
+ }
else
return 0;
- }
+ }
return new DirectoryName();
else
return 0;
- }
+ }
} // end namespace Patterns
out << std::setw(indent_level*2+6) << ""
<< description_str[i] << std::endl;
}
- else if (description_str.size() > 0)
+ else if (description_str.empty() == false)
out << " " << description_str[0] << std::endl;
else
out << std::endl;