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());
62 for (
const auto c : input)
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))
299 std::unique_ptr<PatternBase>
307 std::unique_ptr<Integer>
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 : lower_bound(lower_bound)
350 , upper_bound(upper_bound)
358 std::istringstream str(test_string);
365 if (!has_only_whitespace(str))
422 description <<
"A floating point number v such that ";
440 return "A floating point number";
448 description <<
"A floating point number @f$v@f$ such that @f$";
467 return "A floating point number";
478 std::unique_ptr<PatternBase>
486 std::unique_ptr<Double>
491 description_init_str.size(),
492 description_init_str) != 0)
493 return std::unique_ptr<Double>();
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"));
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)
608 std::unique_ptr<PatternBase>
624 std::unique_ptr<Selection>
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)
662 ExcMessage(
"The separator must have a non-zero length."));
668 : pattern(other.pattern->clone())
669 , min_elements(other.min_elements)
670 , max_elements(other.max_elements)
671 , separator(other.separator)
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) <<
">"
739 << internal::escape(
separator, style) <<
"> ";
741 <<
pattern->description(style) <<
"]";
755 std::unique_ptr<PatternBase>
758 return std::unique_ptr<PatternBase>(
772 std::unique_ptr<List>
785 std::getline(is, str,
'>');
789 is.ignore(strlen(
" of length "));
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 <"));
804 return std_cxx14::make_unique<List>(*base_pattern,
810 return std::unique_ptr<List>();
816 std::numeric_limits<unsigned int>::max();
823 const unsigned int min_elements,
824 const unsigned int max_elements,
825 const std::string &separator,
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)
837 ExcMessage(
"The separator must have a non-zero length."));
839 ExcMessage(
"The key_value_separator must have a non-zero length."));
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"));
850 : key_pattern(other.key_pattern->clone())
851 , value_pattern(other.value_pattern->clone())
852 , min_elements(other.min_elements)
853 , max_elements(other.max_elements)
854 , separator(other.separator)
855 , key_value_separator(other.key_value_separator)
863 std::vector<std::string> split_list =
869 for (
const 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) <<
">"
922 << internal::escape(
separator, style) <<
"> ";
925 <<
" and each value is ["
926 << value_pattern->description(style) <<
"]";
940 std::unique_ptr<PatternBase>
955 return (
sizeof(*
this) +
977 std::getline(is, key,
'>');
984 std::getline(is, value,
'>');
989 is.ignore(strlen(
" of length "));
991 return std_cxx14::make_unique<Map>(*
key_pattern, *value_pattern);
993 is.ignore(strlen(
"..."));
999 is.ignore(strlen(
" (inclusive) separated by <"));
1014 return std::unique_ptr<Map>();
1030 return *value_pattern;
1054 const std::string & separator)
1055 : separator(separator)
1058 ExcMessage(
"The Patterns list must have a non-zero length."));
1060 ExcMessage(
"The separator must have a non-zero length."));
1062 for (
unsigned int i = 0; i < ps.size(); ++i)
1069 const char * separator)
1070 :
Tuple(ps, std::string(separator))
1076 : separator(other.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)
1133 << internal::escape(
separator, style) <<
"> ";
1135 <<
patterns[0]->description(style) <<
"]";
1136 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1139 <<
patterns[i]->description(style) <<
"]";
1154 std::unique_ptr<PatternBase>
1170 std::unique_ptr<Tuple>
1177 std::vector<std::unique_ptr<PatternBase>>
patterns;
1183 std::getline(is, len,
'>');
1186 ExcMessage(
"Provide at least 1 element in the tuple."));
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 <"));
1213 return std::unique_ptr<Tuple>();
1239 Assert(seq.find(
',') == std::string::npos,
1243 while (
sequence.find(
" |") != std::string::npos)
1245 while (
sequence.find(
"| ") != std::string::npos)
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;
1335 description <<
"A comma-separated list of any of "
1336 << internal::escape(
1352 std::unique_ptr<PatternBase>
1368 std::unique_ptr<MultipleSelection>
1380 return std_cxx14::make_unique<MultipleSelection>(
sequence);
1383 return std::unique_ptr<MultipleSelection>();
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>
1439 return std_cxx14::make_unique<Bool>();
1441 return std::unique_ptr<Bool>();
1474 return "Any string";
1486 std::unique_ptr<PatternBase>
1489 return std::unique_ptr<PatternBase>(
new Anything());
1494 std::unique_ptr<Anything>
1500 return std_cxx14::make_unique<Anything>();
1502 return std::unique_ptr<Anything>();
1546 return "an input filename";
1548 return "an output filename";
1560 std::unique_ptr<PatternBase>
1568 std::unique_ptr<FileName>
1588 return std_cxx14::make_unique<FileName>(type);
1591 return std::unique_ptr<FileName>();
1624 return "A directory name";
1636 std::unique_ptr<PatternBase>
1644 std::unique_ptr<DirectoryName>
1650 return std_cxx14::make_unique<DirectoryName>();
1652 return std::unique_ptr<DirectoryName>();
1657 DEAL_II_NAMESPACE_CLOSE