24 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
25 #include <boost/io/ios_state.hpp>
26 #include <boost/property_tree/json_parser.hpp>
27 #include <boost/property_tree/ptree.hpp>
28 #include <boost/property_tree/xml_parser.hpp>
29 #undef BOOST_BIND_GLOBAL_PLACEHOLDERS
65 u.reserve(input.size());
66 for (
const auto c : input)
83 u.append(
"\\textbackslash{}");
119 has_only_whitespace(std::istream &in)
130 if ((c !=
' ') && (c !=
'\t'))
139 std::unique_ptr<PatternBase>
142 std::unique_ptr<PatternBase> p;
194 if (
dynamic_cast<const Integer *
>(
this) !=
nullptr)
196 else if (
dynamic_cast<const Double *
>(
this) !=
nullptr)
198 else if (
dynamic_cast<const Bool *
>(
this) !=
nullptr)
200 else if (
dynamic_cast<const Anything *
>(
this) !=
nullptr)
203 return sizeof(*this) + 32;
215 , upper_bound(upper_bound)
223 std::istringstream str(test_string);
229 if (!has_only_whitespace(str))
303 std::unique_ptr<PatternBase>
311 std::unique_ptr<Integer>
329 return std_cxx14::make_unique<Integer>();
331 is.ignore(strlen(
"..."));
334 return std_cxx14::make_unique<Integer>();
339 return std_cxx14::make_unique<Integer>();
342 return std::unique_ptr<Integer>();
354 , upper_bound(upper_bound)
362 std::istringstream str(test_string);
369 if (!has_only_whitespace(str))
426 description <<
"A floating point number v such that ";
444 return "A floating point number";
452 description <<
"A floating point number @f$v@f$ such that @f$";
471 return "A floating point number";
482 std::unique_ptr<PatternBase>
490 std::unique_ptr<Double>
495 description_init_str.size(),
496 description_init_str) != 0)
497 return std::unique_ptr<Double>();
499 return std::unique_ptr<Double>();
501 std::string temp =
description.substr(description_init_str.size());
503 return std_cxx14::make_unique<Double>(1.0,
506 if (temp.find(
"...") != std::string::npos)
507 temp.replace(temp.find(
"..."), 3,
" ");
511 std::istringstream is(temp);
512 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
513 is.ignore(std::strlen(
" -MAX_DOUBLE"));
518 return std::unique_ptr<Double>();
537 while (
sequence.find(
" |") != std::string::npos)
539 while (
sequence.find(
"| ") != std::string::npos)
551 while ((tmp.length() != 0) && (std::isspace(tmp[0])))
555 while (tmp.find(
'|') != std::string::npos)
557 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
560 tmp.erase(0, tmp.find(
'|') + 1);
564 while ((tmp.length() != 0) && (std::isspace(*(tmp.end() - 1))))
565 tmp.erase(tmp.end() - 1);
568 if (test_string == tmp)
612 std::unique_ptr<PatternBase>
628 std::unique_ptr<Selection>
640 return std_cxx14::make_unique<Selection>(
sequence);
643 return std::unique_ptr<Selection>();
655 const unsigned int min_elements,
656 const unsigned int max_elements,
657 const std::string &separator)
659 , min_elements(min_elements)
660 , max_elements(max_elements)
661 , separator(separator)
666 ExcMessage(
"The separator must have a non-zero length."));
672 : pattern(other.pattern->clone())
673 , min_elements(other.min_elements)
674 , max_elements(other.max_elements)
675 , separator(other.separator)
698 const std::vector<std::string> split_list =
706 for (
const std::string &
string : split_list)
707 if (
pattern->match(
string) ==
false)
725 <<
pattern->description(style) <<
">"
745 <<
pattern->description(style) <<
"]";
759 std::unique_ptr<PatternBase>
762 return std::unique_ptr<PatternBase>(
776 std::unique_ptr<List>
789 std::getline(is, str,
'>');
793 is.ignore(strlen(
" of length "));
795 return std_cxx14::make_unique<List>(*base_pattern);
797 is.ignore(strlen(
"..."));
799 return std_cxx14::make_unique<List>(*base_pattern,
min_elements);
801 is.ignore(strlen(
" (inclusive) separated by <"));
808 return std_cxx14::make_unique<List>(*base_pattern,
814 return std::unique_ptr<List>();
827 const unsigned int min_elements,
828 const unsigned int max_elements,
829 const std::string &separator,
830 const std::string &key_value_separator)
831 : key_pattern(p_key.clone())
832 , value_pattern(p_value.clone())
833 , min_elements(min_elements)
834 , max_elements(max_elements)
835 , separator(separator)
836 , key_value_separator(key_value_separator)
841 ExcMessage(
"The separator must have a non-zero length."));
843 ExcMessage(
"The key_value_separator must have a non-zero length."));
846 "The separator can not be the same of the key_value_separator "
847 "since that is used as the separator between the two elements "
848 "of <key:value> pairs"));
854 : key_pattern(other.key_pattern->clone())
855 , value_pattern(other.value_pattern->clone())
856 , min_elements(other.min_elements)
857 , max_elements(other.max_elements)
858 , separator(other.separator)
859 , key_value_separator(other.key_value_separator)
867 std::vector<std::string> split_list =
873 for (
const auto &key_value_pair : split_list)
875 std::vector<std::string> pair =
879 if (pair.size() != 2)
929 <<
" and each value is ["
944 std::unique_ptr<PatternBase>
959 return (
sizeof(*
this) +
981 std::getline(is, key,
'>');
988 std::getline(is,
value,
'>');
993 is.ignore(strlen(
" of length "));
997 is.ignore(strlen(
"..."));
1003 is.ignore(strlen(
" (inclusive) separated by <"));
1018 return std::unique_ptr<Map>();
1058 const std::string & separator)
1059 : separator(separator)
1062 ExcMessage(
"The Patterns list must have a non-zero length."));
1064 ExcMessage(
"The separator must have a non-zero length."));
1066 for (
unsigned int i = 0; i < ps.size(); ++i)
1073 const char * separator)
1074 :
Tuple(ps, std::string(separator))
1080 : separator(other.separator)
1083 for (
unsigned int i = 0; i < other.
patterns.size(); ++i)
1092 std::vector<std::string> split_list =
1094 if (split_list.size() !=
patterns.size())
1097 for (
unsigned int i = 0; i <
patterns.size(); ++i)
1118 <<
"> elements <" <<
patterns[0]->description(style)
1120 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1139 <<
patterns[0]->description(style) <<
"]";
1140 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1143 <<
patterns[i]->description(style) <<
"]";
1158 std::unique_ptr<PatternBase>
1174 std::unique_ptr<Tuple>
1181 std::vector<std::unique_ptr<PatternBase>>
patterns;
1187 std::getline(is, len,
'>');
1190 ExcMessage(
"Provide at least 1 element in the tuple."));
1193 is.ignore(strlen(
" elements <"));
1195 std::string element;
1196 std::getline(is, element,
'>');
1199 for (
unsigned int i = 1; i < n_elements; ++i)
1201 is.ignore(strlen(
", <"));
1202 std::getline(is, element,
'>');
1206 is.ignore(strlen(
" separated by <"));
1217 return std::unique_ptr<Tuple>();
1243 Assert(seq.find(
',') == std::string::npos,
1247 while (
sequence.find(
" |") != std::string::npos)
1249 while (
sequence.find(
"| ") != std::string::npos)
1258 std::string tmp = test_string_list;
1259 std::vector<std::string> split_names;
1262 while (tmp.length() != 0)
1267 if (name.find(
',') != std::string::npos)
1269 name.erase(name.find(
','), std::string::npos);
1270 tmp.erase(0, tmp.find(
',') + 1);
1275 while ((name.length() != 0) && (std::isspace(name[0])))
1277 while (std::isspace(name[name.length() - 1]))
1278 name.erase(name.length() - 1, 1);
1280 split_names.push_back(name);
1285 for (
const auto &test_string : split_names)
1287 bool string_found =
false;
1290 while (tmp.find(
'|') != std::string::npos)
1292 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
1298 string_found =
true;
1302 tmp.erase(0, tmp.find(
'|') + 1);
1306 if (test_string == tmp)
1307 string_found =
true;
1336 description <<
"A comma-separated list of any of "
1353 std::unique_ptr<PatternBase>
1369 std::unique_ptr<MultipleSelection>
1381 return std_cxx14::make_unique<MultipleSelection>(
sequence);
1384 return std::unique_ptr<MultipleSelection>();
1414 return "A boolean value (true or false)";
1426 std::unique_ptr<PatternBase>
1429 return std::unique_ptr<PatternBase>(
new Bool());
1434 std::unique_ptr<Bool>
1440 return std_cxx14::make_unique<Bool>();
1442 return std::unique_ptr<Bool>();
1475 return "Any string";
1487 std::unique_ptr<PatternBase>
1490 return std::unique_ptr<PatternBase>(
new Anything());
1495 std::unique_ptr<Anything>
1501 return std_cxx14::make_unique<Anything>();
1503 return std::unique_ptr<Anything>();
1547 return "an input filename";
1549 return "an output filename";
1561 std::unique_ptr<PatternBase>
1569 std::unique_ptr<FileName>
1589 return std_cxx14::make_unique<FileName>(type);
1592 return std::unique_ptr<FileName>();
1625 return "A directory name";
1637 std::unique_ptr<PatternBase>
1645 std::unique_ptr<DirectoryName>
1651 return std_cxx14::make_unique<DirectoryName>();
1653 return std::unique_ptr<DirectoryName>();