17 #include <deal.II/base/logstream.h> 18 #include <deal.II/base/memory_consumption.h> 19 #include <deal.II/base/path_search.h> 20 #include <deal.II/base/patterns.h> 21 #include <deal.II/base/utilities.h> 23 #include <boost/io/ios_state.hpp> 24 #include <boost/property_tree/json_parser.hpp> 25 #include <boost/property_tree/ptree.hpp> 26 #include <boost/property_tree/xml_parser.hpp> 39 DEAL_II_NAMESPACE_OPEN
61 u.reserve(input.size());
79 u.append(
"\\textbackslash{}");
115 has_only_whitespace(std::istream &in)
126 if ((c !=
' ') && (c !=
'\t'))
135 std::unique_ptr<PatternBase>
138 std::unique_ptr<PatternBase> p;
190 if (dynamic_cast<const Integer *>(
this) !=
nullptr)
192 else if (dynamic_cast<const Double *>(
this) !=
nullptr)
194 else if (dynamic_cast<const Bool *>(
this) !=
nullptr)
196 else if (dynamic_cast<const Anything *>(
this) !=
nullptr)
199 return sizeof(*this) + 32;
210 : lower_bound(lower_bound)
211 , upper_bound(upper_bound)
219 std::istringstream str(test_string);
225 if (!has_only_whitespace(str))
254 return description.str();
267 description <<
"An integer n such that " <<
lower_bound 270 return description.str();
281 description <<
"An integer @f$n@f$ such that @f$" <<
lower_bound 284 return description.str();
299 std::unique_ptr<PatternBase>
307 std::unique_ptr<Integer>
310 if (description.compare(0,
314 std::istringstream is(description);
324 if (!(is >> lower_bound))
325 return std_cxx14::make_unique<Integer>();
327 is.ignore(strlen(
"..."));
329 if (!(is >> upper_bound))
330 return std_cxx14::make_unique<Integer>();
335 return std_cxx14::make_unique<Integer>();
338 return std::unique_ptr<Integer>();
349 : lower_bound(lower_bound)
350 , upper_bound(upper_bound)
358 std::istringstream str(test_string);
365 if (!has_only_whitespace(str))
396 description <<
"-MAX_DOUBLE";
399 description <<
"...";
403 description <<
"MAX_DOUBLE";
406 description <<
" (inclusive)]";
407 return description.str();
413 return description.str();
422 description <<
"A floating point number v such that ";
426 description <<
"-MAX_DOUBLE";
429 description <<
" <= v <= ";
433 description <<
"MAX_DOUBLE";
437 return description.str();
440 return "A floating point number";
448 description <<
"A floating point number @f$v@f$ such that @f$";
452 description <<
"-\\text{MAX\\_DOUBLE}";
455 description <<
" \\leq v \\leq ";
459 description <<
"\\text{MAX\\_DOUBLE}";
462 description <<
"@f$";
464 return description.str();
467 return "A floating point number";
478 std::unique_ptr<PatternBase>
486 std::unique_ptr<Double>
490 if (description.compare(0,
491 description_init_str.size(),
492 description_init_str) != 0)
493 return std::unique_ptr<Double>();
494 if (*description.rbegin() !=
']')
495 return std::unique_ptr<Double>();
497 std::string temp = description.substr(description_init_str.size());
499 return std_cxx14::make_unique<Double>(1.0,
502 if (temp.find(
"...") != std::string::npos)
503 temp.replace(temp.find(
"..."), 3,
" ");
507 std::istringstream is(temp);
508 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
509 is.ignore(std::strlen(
" -MAX_DOUBLE"));
513 if (!(is >> lower_bound))
514 return std::unique_ptr<Double>();
533 while (
sequence.find(
" |") != std::string::npos)
535 while (
sequence.find(
"| ") != std::string::npos)
547 while ((tmp.length() != 0) && (std::isspace(tmp[0])))
551 while (tmp.find(
'|') != std::string::npos)
553 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
556 tmp.erase(0, tmp.find(
'|') + 1);
560 while ((tmp.length() != 0) && (std::isspace(*(tmp.end() - 1))))
561 tmp.erase(tmp.end() - 1);
564 if (test_string == tmp)
584 return description.str();
591 description <<
"Any one of " 596 return description.str();
608 std::unique_ptr<PatternBase>
624 std::unique_ptr<Selection>
627 if (description.compare(0,
634 sequence.erase(sequence.length() - 2, 2);
636 return std_cxx14::make_unique<Selection>(
sequence);
639 return std::unique_ptr<Selection>();
645 std::numeric_limits<unsigned int>::max();
651 const unsigned int min_elements,
652 const unsigned int max_elements,
653 const std::string &separator)
655 , min_elements(min_elements)
656 , max_elements(max_elements)
657 , separator(separator)
659 Assert(min_elements <= max_elements,
661 Assert(separator.size() > 0,
662 ExcMessage(
"The separator must have a non-zero length."));
694 const std::vector<std::string> split_list =
702 for (
const std::string &
string : split_list)
703 if (
pattern->match(
string) ==
false)
721 <<
pattern->description(style) <<
">" 725 description <<
" separated by <" <<
separator <<
">";
728 return description.str();
738 description <<
"separated by <" 739 << internal::escape(
separator, style) <<
"> ";
740 description <<
"where each element is [" 741 <<
pattern->description(style) <<
"]";
743 return description.str();
755 std::unique_ptr<PatternBase>
758 return std::unique_ptr<PatternBase>(
772 std::unique_ptr<List>
775 if (description.compare(0,
781 std::istringstream is(description);
785 std::getline(is, str,
'>');
789 is.ignore(strlen(
" of length "));
790 if (!(is >> min_elements))
791 return std_cxx14::make_unique<List>(*base_pattern);
793 is.ignore(strlen(
"..."));
795 return std_cxx14::make_unique<List>(*base_pattern,
min_elements);
797 is.ignore(strlen(
" (inclusive) separated by <"));
800 std::getline(is, separator,
'>');
804 return std_cxx14::make_unique<List>(*base_pattern,
810 return std::unique_ptr<List>();
816 std::numeric_limits<unsigned int>::max();
826 const std::string &key_value_separator)
827 : key_pattern(p_key.
clone())
828 , value_pattern(p_value.
clone())
829 , min_elements(min_elements)
830 , max_elements(max_elements)
831 , separator(separator)
832 , key_value_separator(key_value_separator)
834 Assert(min_elements <= max_elements,
836 Assert(separator.size() > 0,
837 ExcMessage(
"The separator must have a non-zero length."));
838 Assert(key_value_separator.size() > 0,
839 ExcMessage(
"The key_value_separator must have a non-zero length."));
840 Assert(separator != key_value_separator,
842 "The separator can not be the same of the key_value_separator " 843 "since that is used as the separator between the two elements " 844 "of <key:value> pairs"));
851 , value_pattern(other.value_pattern->
clone())
863 std::vector<std::string> split_list =
869 for (
auto &key_value_pair : split_list)
871 std::vector<std::string> pair =
875 if (pair.size() != 2)
881 if (value_pattern->match(pair[1]) ==
false)
902 << value_pattern->description(style) <<
">" 906 description <<
" separated by <" <<
separator <<
">";
909 return description.str();
916 description <<
"A key" 921 description <<
" separated by <" 922 << internal::escape(
separator, style) <<
"> ";
923 description <<
" where each key is [" 925 <<
" and each value is [" 926 << value_pattern->description(style) <<
"]";
928 return description.str();
940 std::unique_ptr<PatternBase>
955 return (
sizeof(*
this) +
967 if (description.compare(0,
973 std::istringstream is(description);
977 std::getline(is, key,
'>');
980 std::getline(is, key_value_separator,
'<');
984 std::getline(is, value,
'>');
989 is.ignore(strlen(
" of length "));
990 if (!(is >> min_elements))
991 return std_cxx14::make_unique<Map>(*
key_pattern, *value_pattern);
993 is.ignore(strlen(
"..."));
999 is.ignore(strlen(
" (inclusive) separated by <"));
1002 std::getline(is, separator,
'>');
1014 return std::unique_ptr<Map>();
1030 return *value_pattern;
1055 : separator(separator)
1058 ExcMessage(
"The Patterns list must have a non-zero length."));
1059 Assert(separator.size() > 0,
1060 ExcMessage(
"The separator must have a non-zero length."));
1062 for (
unsigned int i = 0; i < ps.size(); ++i)
1070 :
Tuple(ps,
std::string(separator))
1079 for (
unsigned int i = 0; i < other.
patterns.size(); ++i)
1088 std::vector<std::string> split_list =
1090 if (split_list.size() !=
patterns.size())
1093 for (
unsigned int i = 0; i <
patterns.size(); ++i)
1114 <<
"> elements <" <<
patterns[0]->description(style)
1116 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1120 description <<
" separated by <" <<
separator <<
">";
1123 return description.str();
1130 description <<
"A Tuple of " <<
patterns.size() <<
" elements ";
1132 description <<
" separated by <" 1133 << internal::escape(
separator, style) <<
"> ";
1134 description <<
" where each element is [" 1135 <<
patterns[0]->description(style) <<
"]";
1136 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1138 description << internal::escape(
separator, style) <<
"[" 1139 <<
patterns[i]->description(style) <<
"]";
1141 return description.str();
1154 std::unique_ptr<PatternBase>
1170 std::unique_ptr<Tuple>
1173 if (description.compare(0,
1177 std::vector<std::unique_ptr<PatternBase>>
patterns;
1179 std::istringstream is(description);
1183 std::getline(is, len,
'>');
1186 ExcMessage(
"Provide at least 1 element in the tuple."));
1187 patterns.resize(n_elements);
1189 is.ignore(strlen(
" elements <"));
1191 std::string element;
1192 std::getline(is, element,
'>');
1195 for (
unsigned int i = 1; i < n_elements; ++i)
1197 is.ignore(strlen(
", <"));
1198 std::getline(is, element,
'>');
1202 is.ignore(strlen(
" separated by <"));
1206 std::getline(is, separator,
'>');
1213 return std::unique_ptr<Tuple>();
1239 Assert(seq.find(
',') == std::string::npos,
1240 ExcCommasNotAllowed(seq.find(
',')));
1243 while (sequence.find(
" |") != std::string::npos)
1244 sequence.replace(sequence.find(
" |"), 2,
"|");
1245 while (sequence.find(
"| ") != std::string::npos)
1246 sequence.replace(sequence.find(
"| "), 2,
"|");
1254 std::string tmp = test_string_list;
1255 std::vector<std::string> split_names;
1258 while (tmp.length() != 0)
1263 if (name.find(
',') != std::string::npos)
1265 name.erase(name.find(
','), std::string::npos);
1266 tmp.erase(0, tmp.find(
',') + 1);
1271 while ((name.length() != 0) && (std::isspace(name[0])))
1273 while (std::isspace(name[name.length() - 1]))
1274 name.erase(name.length() - 1, 1);
1276 split_names.push_back(name);
1281 for (std::vector<std::string>::const_iterator test_string =
1282 split_names.begin();
1283 test_string != split_names.end();
1286 bool string_found =
false;
1289 while (tmp.find(
'|') != std::string::npos)
1291 if (*test_string == std::string(tmp, 0, tmp.find(
'|')))
1297 string_found =
true;
1301 tmp.erase(0, tmp.find(
'|') + 1);
1305 if (*test_string == tmp)
1306 string_found =
true;
1328 return description.str();
1335 description <<
"A comma-separated list of any of " 1336 << internal::escape(
1340 return description.str();
1352 std::unique_ptr<PatternBase>
1368 std::unique_ptr<MultipleSelection>
1371 if (description.compare(0,
1375 std::string sequence(description);
1378 sequence.erase(sequence.length() - 2, 2);
1380 return std_cxx14::make_unique<MultipleSelection>(sequence);
1383 return std::unique_ptr<MultipleSelection>();
1408 return description.str();
1413 return "A boolean value (true or false)";
1425 std::unique_ptr<PatternBase>
1428 return std::unique_ptr<PatternBase>(
new Bool());
1433 std::unique_ptr<Bool>
1436 if (description.compare(0,
1439 return std_cxx14::make_unique<Bool>();
1441 return std::unique_ptr<Bool>();
1469 return description.str();
1474 return "Any string";
1486 std::unique_ptr<PatternBase>
1489 return std::unique_ptr<PatternBase>(
new Anything());
1494 std::unique_ptr<Anything>
1497 if (description.compare(0,
1500 return std_cxx14::make_unique<Anything>();
1502 return std::unique_ptr<Anything>();
1536 description <<
" (Type: input)]";
1538 description <<
" (Type: output)]";
1540 return description.str();
1546 return "an input filename";
1548 return "an output filename";
1560 std::unique_ptr<PatternBase>
1568 std::unique_ptr<FileName>
1571 if (description.compare(0,
1575 std::istringstream is(description);
1583 if (file_type ==
"input)]")
1588 return std_cxx14::make_unique<FileName>(type);
1591 return std::unique_ptr<FileName>();
1619 return description.str();
1624 return "A directory name";
1636 std::unique_ptr<PatternBase>
1644 std::unique_ptr<DirectoryName>
1647 if (description.compare(0,
1650 return std_cxx14::make_unique<DirectoryName>();
1652 return std::unique_ptr<DirectoryName>();
1657 DEAL_II_NAMESPACE_CLOSE
const PatternBase & get_key_pattern() const
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
const std::string & get_separator() const
virtual std::string description(const OutputStyle style=Machine) const override
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 override
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::unique_ptr< PatternBase > clone() const override
const std::string separator
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
std::size_t memory_consumption() const override
virtual std::unique_ptr< PatternBase > clone() const override
virtual bool match(const std::string &test_string) const override
static const int max_int_value
const std::string & get_separator() const
#define AssertThrow(cond, exc)
const unsigned int max_elements
static const char * description_init
const PatternBase & get_base_pattern() const
virtual std::string description(const OutputStyle style=Machine) const override
static std::unique_ptr< Anything > create(const std::string &description)
virtual std::unique_ptr< PatternBase > clone() const override
virtual bool match(const std::string &test_string) const override
const PatternBase & get_value_pattern() const
static const int min_int_value
virtual std::unique_ptr< PatternBase > clone() const override
static::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
FileName(const FileType type=input)
virtual bool match(const std::string &test_string) const override
static const char * description_init
virtual bool match(const std::string &test_string) const override
static::ExceptionBase & ExcMessage(std::string arg1)
virtual std::unique_ptr< PatternBase > clone() const override
static const char * description_init
static std::unique_ptr< DirectoryName > create(const std::string &description)
std::size_t memory_consumption() const override
static const char * description_init
std::vector< std::unique_ptr< PatternBase > > patterns
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)
static const char * description_init
static std::unique_ptr< Map > create(const std::string &description)
virtual bool match(const std::string &test_string) const override
static::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static const char * description_init
virtual bool match(const std::string &test_string) const override
std::unique_ptr< PatternBase > key_pattern
virtual std::string description(const OutputStyle style=Machine) const override
std::size_t memory_consumption() const override
static std::unique_ptr< Double > create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const override
static const double min_double_value
virtual bool match(const std::string &test_string) const override
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
std::size_t memory_consumption() const override
static const char * description_init
virtual bool match(const std::string &test_string) const override
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
virtual std::unique_ptr< PatternBase > clone() const override
std::size_t memory_consumption() const override
static const char * description_init
virtual std::size_t memory_consumption() const
static const double max_double_value
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::string description(const OutputStyle style=Machine) const override
static std::unique_ptr< MultipleSelection > create(const std::string &description)
virtual bool match(const std::string &test_string) const override
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)
int string_to_int(const std::string &s)
Selection(const std::string &seq)
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=":")
Tuple(const std::vector< std::unique_ptr< PatternBase >> &patterns, const std::string &separator=":")
virtual std::string description(const OutputStyle style=Machine) const override
const PatternBase & get_pattern(const unsigned int &i) const
virtual std::string description(const OutputStyle style=Machine) const override
const unsigned int min_elements
const std::string & get_key_value_separator() const
static const unsigned int max_int_value
virtual std::string description(const OutputStyle style=Machine) const override
virtual std::string description(const OutputStyle style=Machine) const override
const std::string separator
const std::string key_value_separator
const unsigned int max_elements
virtual std::string description(const OutputStyle style=Machine) const override
virtual std::string description(const OutputStyle style=Machine) const override
const unsigned int min_elements
static std::unique_ptr< Integer > create(const std::string &description)
const std::string & get_separator() const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::unique_ptr< PatternBase > clone() const override