17 #include <deal.II/base/patterns.h> 18 #include <deal.II/base/logstream.h> 19 #include <deal.II/base/path_search.h> 20 #include <deal.II/base/memory_consumption.h> 21 #include <deal.II/base/utilities.h> 23 #include <boost/property_tree/ptree.hpp> 24 #include <boost/property_tree/xml_parser.hpp> 25 #include <boost/property_tree/json_parser.hpp> 27 #include <boost/io/ios_state.hpp> 40 DEAL_II_NAMESPACE_OPEN
64 u.reserve (input.size());
82 u.append(
"\\textbackslash{}");
117 bool has_only_whitespace (std::istream &in)
128 if ((c !=
' ') && (c !=
'\t'))
139 std::unique_ptr<PatternBase> p;
191 if (dynamic_cast<const Integer *>(
this) !=
nullptr)
193 else if (dynamic_cast<const Double *>(
this) !=
nullptr)
195 else if (dynamic_cast<const Bool *>(
this) !=
nullptr)
197 else if (dynamic_cast<const Anything *>(
this) !=
nullptr)
200 return sizeof(*this) + 32;
211 const int upper_bound)
213 lower_bound (lower_bound),
214 upper_bound (upper_bound)
221 std::istringstream str(test_string);
227 if (!has_only_whitespace (str))
325 return std_cxx14::make_unique<Integer>();
327 is.ignore(strlen(
"..."));
330 return std_cxx14::make_unique<Integer>();
335 return std_cxx14::make_unique<Integer>();
338 return std::unique_ptr<Integer>();
349 const double upper_bound)
351 lower_bound (lower_bound),
352 upper_bound (upper_bound)
359 std::istringstream str(test_string);
366 if (!has_only_whitespace (str))
419 description <<
"A floating point number v such that ";
433 return "A floating point number";
441 description <<
"A floating point number @f$v@f$ such that @f$";
456 return "A floating point number";
477 if (
description.compare(0, description_init_str.size(), description_init_str) != 0)
478 return std::unique_ptr<Double>();
480 return std::unique_ptr<Double>();
482 std::string temp =
description.substr(description_init_str.size());
484 return std_cxx14::make_unique<Double>(1.0, -1.0);
486 if (temp.find(
"...") != std::string::npos)
487 temp.replace(temp.find(
"..."), 3,
" ");
492 std::istringstream is(temp);
493 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
494 is.ignore(std::strlen(
" -MAX_DOUBLE"));
499 return std::unique_ptr<Double>();
518 while (
sequence.find(
" |") != std::string::npos)
520 while (
sequence.find(
"| ") != std::string::npos)
531 while ((tmp.length() != 0) && (std::isspace (tmp[0])))
535 while (tmp.find(
'|') != std::string::npos)
537 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
540 tmp.erase (0, tmp.find(
'|')+1);
544 while ((tmp.length() != 0) && (std::isspace (*(tmp.end()-1))))
545 tmp.erase (tmp.end()-1);
548 if (test_string == tmp)
616 return std_cxx14::make_unique<Selection>(
sequence);
619 return std::unique_ptr<Selection>();
625 = std::numeric_limits<unsigned int>::max();
631 const unsigned int min_elements,
632 const unsigned int max_elements,
633 const std::string &separator)
636 min_elements (min_elements),
637 max_elements (max_elements),
638 separator (separator)
643 ExcMessage (
"The separator must have a non-zero length."));
650 pattern (other.pattern->clone()),
651 min_elements (other.min_elements),
652 max_elements (other.max_elements),
653 separator (other.separator)
673 const std::vector<std::string> split_list =
681 for (
const std::string &
string : split_list)
682 if (
pattern->match (
string) ==
false)
699 <<
" of <" <<
pattern->description(style) <<
">" 745 return (
sizeof(*
this) +
762 std::getline(is, str,
'>');
766 is.ignore(strlen(
" of length "));
768 return std_cxx14::make_unique<List>(*base_pattern);
770 is.ignore(strlen(
"..."));
772 return std_cxx14::make_unique<List>(*base_pattern,
min_elements);
774 is.ignore(strlen(
" (inclusive) separated by <"));
784 return std::unique_ptr<List>();
790 = std::numeric_limits<unsigned int>::max();
797 const unsigned int min_elements,
798 const unsigned int max_elements,
799 const std::string &separator,
800 const std::string &key_value_separator)
802 key_pattern (p_key.clone()),
803 value_pattern (p_value.clone()),
804 min_elements (min_elements),
805 max_elements (max_elements),
806 separator (separator),
807 key_value_separator(key_value_separator)
812 ExcMessage (
"The separator must have a non-zero length."));
814 ExcMessage (
"The key_value_separator must have a non-zero length."));
816 ExcMessage (
"The separator can not be the same of the key_value_separator " 817 "since that is used as the separator between the two elements " 818 "of <key:value> pairs"));
825 key_pattern (other.key_pattern->clone()),
826 value_pattern (other.value_pattern->clone()),
827 min_elements (other.min_elements),
828 max_elements (other.max_elements),
829 separator (other.separator),
830 key_value_separator(other.key_value_separator)
837 std::vector<std::string> split_list =
843 for (
auto &key_value_pair : split_list)
845 std::vector<std::string> pair =
849 if (pair.size() != 2)
855 if (value_pattern->match (pair[1]) ==
false)
876 << value_pattern->description(style) <<
">" 900 <<
" and each value is [" 901 << value_pattern->description(style)
918 return std::unique_ptr<PatternBase>(
new Map(*
key_pattern, *value_pattern,
927 return (
sizeof(*
this) +
946 std::getline(is, key,
'>');
953 std::getline(is, value,
'>');
958 is.ignore(strlen(
" of length "));
960 return std_cxx14::make_unique<Map>(*
key_pattern, *value_pattern);
962 is.ignore(strlen(
"..."));
966 is.ignore(strlen(
" (inclusive) separated by <"));
973 return std_cxx14::make_unique<Map>(*
key_pattern, *value_pattern,
978 return std::unique_ptr<Map>();
992 return *value_pattern;
1014 const std::string &separator)
1016 separator (separator)
1019 ExcMessage (
"The Patterns list must have a non-zero length."));
1021 ExcMessage (
"The separator must have a non-zero length."));
1023 for (
unsigned int i=0; i<ps.size(); ++i)
1030 const char *separator) :
1038 separator (other.separator)
1041 for (
unsigned int i=0; i<other.
patterns.size(); ++i)
1049 std::vector<std::string> split_list =
1051 if (split_list.size() !=
patterns.size())
1054 for (
unsigned int i=0; i<
patterns.size(); ++i)
1075 <<
patterns.size() <<
"> elements <" 1078 for (
unsigned int i=1; i<
patterns.size(); ++i)
1102 for (
unsigned int i=1; i<
patterns.size(); ++i)
1105 <<
"[" <<
patterns[i]->description(style) <<
"]";
1130 return (
sizeof(*
this) +
1141 std::vector<std::unique_ptr<PatternBase> >
patterns;
1147 std::getline(is, len,
'>');
1150 ExcMessage(
"Provide at least 1 element in the tuple."));
1153 is.ignore(strlen(
" elements <"));
1155 std::string element;
1156 std::getline(is, element,
'>');
1159 for (
unsigned int i=1; i<n_elements; ++i)
1161 is.ignore(strlen(
", <"));
1162 std::getline(is, element,
'>');
1166 is.ignore(strlen(
" separated by <"));
1177 return std::unique_ptr<Tuple>();
1204 while (
sequence.find(
" |") != std::string::npos)
1206 while (
sequence.find(
"| ") != std::string::npos)
1214 std::string tmp = test_string_list;
1215 std::vector<std::string> split_names;
1218 while (tmp.length() != 0)
1223 if (name.find(
',') != std::string::npos)
1225 name.erase (name.find(
','), std::string::npos);
1226 tmp.erase (0, tmp.find(
',')+1);
1231 while ((name.length() != 0) &&
1232 (std::isspace (name[0])))
1234 while (std::isspace (name[name.length()-1]))
1235 name.erase (name.length()-1, 1);
1237 split_names.push_back (name);
1242 for (std::vector<std::string>::const_iterator test_string = split_names.begin();
1243 test_string != split_names.end(); ++test_string)
1245 bool string_found =
false;
1248 while (tmp.find(
'|') != std::string::npos)
1250 if (*test_string == std::string(tmp, 0, tmp.find(
'|')))
1256 string_found =
true;
1260 tmp.erase (0, tmp.find(
'|')+1);
1264 if (*test_string == tmp)
1265 string_found =
true;
1296 description <<
"A comma-separated list of any of " 1335 return std_cxx14::make_unique<MultipleSelection>(
sequence);
1338 return std::unique_ptr<MultipleSelection>();
1369 return "A boolean value (true or false)";
1383 return std::unique_ptr<PatternBase>(
new Bool());
1391 return std_cxx14::make_unique<Bool>();
1393 return std::unique_ptr<Bool>();
1425 return "Any string";
1439 return std::unique_ptr<PatternBase>(
new Anything());
1447 return std_cxx14::make_unique<Anything>();
1449 return std::unique_ptr<Anything>();
1491 return "an input filename";
1493 return "an output filename";
1529 return std_cxx14::make_unique<FileName>(type);
1532 return std::unique_ptr<FileName>();
1563 return "A directory name";
1585 return std_cxx14::make_unique<DirectoryName>();
1587 return std::unique_ptr<DirectoryName>();
1592 DEAL_II_NAMESPACE_CLOSE
const std::string & get_separator() const
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
std::size_t memory_consumption() const
const std::string & get_separator() const
virtual bool match(const std::string &test_string) const
virtual bool match(const std::string &test_string) const
static std::unique_ptr< FileName > create(const std::string &description)
static const char * description_init
static const char * description_init
static std::unique_ptr< Tuple > create(const std::string &description)
virtual bool match(const std::string &test_string) const
virtual std::unique_ptr< PatternBase > clone() const
const PatternBase & get_value_pattern() const
const std::string separator
std::size_t memory_consumption() const
const std::string separator
static std::unique_ptr< List > create(const std::string &description)
std::unique_ptr< PatternBase > pattern
static const unsigned int max_int_value
static const char * description_init
virtual bool match(const std::string &test_string) const
virtual std::string description(const OutputStyle style=Machine) const
virtual std::unique_ptr< PatternBase > clone() const
static const int max_int_value
#define AssertThrow(cond, exc)
const std::string & get_separator() const
const unsigned int max_elements
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
static const char * description_init
static std::unique_ptr< Anything > create(const std::string &description)
Tuple(const std::vector< std::unique_ptr< PatternBase > > &patterns, const std::string &separator=":")
static const int min_int_value
virtual std::unique_ptr< PatternBase > clone() const
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
virtual std::unique_ptr< PatternBase > clone() const
FileName(const FileType type=input)
static const char * description_init
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char * description_init
static std::unique_ptr< DirectoryName > create(const std::string &description)
static const char * description_init
virtual std::string description(const OutputStyle style=Machine) const
virtual std::string description(const OutputStyle style=Machine) const
std::vector< std::unique_ptr< PatternBase > > patterns
const PatternBase & get_key_pattern() const
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
#define Assert(cond, exc)
List(const PatternBase &base_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",")
MultipleSelection(const std::string &seq)
virtual std::size_t memory_consumption() const
static const char * description_init
static std::unique_ptr< Map > create(const std::string &description)
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static const char * description_init
std::unique_ptr< PatternBase > key_pattern
const PatternBase & get_base_pattern() const
static std::unique_ptr< Double > create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const
std::size_t memory_consumption() const
static const double min_double_value
virtual std::string description(const OutputStyle style=Machine) const
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
virtual bool match(const std::string &test_string) const
virtual std::unique_ptr< PatternBase > clone() const
static const char * description_init
const std::string & get_key_value_separator() const
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
virtual std::string description(const OutputStyle style=Machine) const
virtual std::string description(const OutputStyle style=Machine) const
virtual std::unique_ptr< PatternBase > clone() const
virtual bool match(const std::string &test_string) const
virtual bool match(const std::string &test_string) const
virtual std::unique_ptr< PatternBase > clone() const
static const char * description_init
std::size_t memory_consumption() const
static const double max_double_value
virtual std::string description(const OutputStyle style=Machine) const
const PatternBase & get_pattern(const unsigned int &i) const
virtual bool match(const std::string &test_string) const
static std::unique_ptr< MultipleSelection > create(const std::string &description)
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
static std::unique_ptr< Bool > create(const std::string &description)
static std::unique_ptr< Selection > create(const std::string &description)
virtual std::unique_ptr< PatternBase > clone() const
int string_to_int(const std::string &s)
Selection(const std::string &seq)
virtual std::unique_ptr< PatternBase > clone() const
static ::ExceptionBase & ExcNotImplemented()
Map(const PatternBase &key_pattern, const PatternBase &value_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",", const std::string &key_value_separator=":")
virtual bool match(const std::string &test_string) const
virtual std::unique_ptr< PatternBase > clone() const
const unsigned int min_elements
static const unsigned int max_int_value
const std::string separator
virtual std::string description(const OutputStyle style=Machine) const
const std::string key_value_separator
const unsigned int max_elements
virtual std::string description(const OutputStyle style=Machine) const
virtual std::unique_ptr< PatternBase > clone() const
virtual bool match(const std::string &test_string) const
const unsigned int min_elements
static std::unique_ptr< Integer > create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const
std::size_t memory_consumption() const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)