23#define BOOST_BIND_GLOBAL_PLACEHOLDERS
24#include <boost/io/ios_state.hpp>
25#include <boost/property_tree/json_parser.hpp>
26#include <boost/property_tree/ptree.hpp>
27#include <boost/property_tree/xml_parser.hpp>
28#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
63 u.reserve(input.size());
64 for (
const auto c : input)
81 u.append(
"\\textbackslash{}");
117 has_only_whitespace(std::istream &in)
128 if ((c !=
' ') && (c !=
'\t'))
137 std::unique_ptr<PatternBase>
140 std::unique_ptr<PatternBase> p;
192 if (
dynamic_cast<const Integer *
>(
this) !=
nullptr)
194 else if (
dynamic_cast<const Double *
>(
this) !=
nullptr)
196 else if (
dynamic_cast<const Bool *
>(
this) !=
nullptr)
198 else if (
dynamic_cast<const Anything *
>(
this) !=
nullptr)
201 return sizeof(*this) + 32;
212 : lower_bound(lower_bound)
213 , upper_bound(upper_bound)
221 std::istringstream str(test_string);
227 if (!has_only_whitespace(str))
301 std::unique_ptr<PatternBase>
309 std::unique_ptr<Integer>
327 return std::make_unique<Integer>();
329 is.ignore(std::strlen(
"..."));
332 return std::make_unique<Integer>();
337 return std::make_unique<Integer>();
340 return std::unique_ptr<Integer>();
351 : lower_bound(lower_bound)
352 , upper_bound(upper_bound)
360 std::istringstream str(test_string);
367 if (!has_only_whitespace(str))
424 description <<
"A floating point number v such that ";
442 return "A floating point number";
450 description <<
"A floating point number @f$v@f$ such that @f$";
469 return "A floating point number";
480 std::unique_ptr<PatternBase>
488 std::unique_ptr<Double>
493 description_init_str.size(),
494 description_init_str) != 0)
495 return std::unique_ptr<Double>();
497 return std::unique_ptr<Double>();
499 std::string temp =
description.substr(description_init_str.size());
501 return std::make_unique<Double>(1.0,
504 if (temp.find(
"...") != std::string::npos)
505 temp.replace(temp.find(
"..."), 3,
" ");
509 std::istringstream is(temp);
510 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
511 is.ignore(std::strlen(
" -MAX_DOUBLE"));
516 return std::unique_ptr<Double>();
535 while (
sequence.find(
" |") != std::string::npos)
537 while (
sequence.find(
"| ") != std::string::npos)
549 while ((tmp.size() != 0) && (std::isspace(tmp.front()) != 0))
553 while (tmp.find(
'|') != std::string::npos)
555 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
558 tmp.erase(0, tmp.find(
'|') + 1);
562 while ((tmp.size() != 0) && (std::isspace(tmp.back()) != 0))
563 tmp.erase(tmp.end() - 1);
566 if (test_string == tmp)
610 std::unique_ptr<PatternBase>
626 std::unique_ptr<Selection>
638 return std::make_unique<Selection>(
sequence);
641 return std::unique_ptr<Selection>();
647 std::numeric_limits<unsigned int>::max();
653 const unsigned int min_elements,
654 const unsigned int max_elements,
655 const std::string &separator)
657 , min_elements(min_elements)
658 , max_elements(max_elements)
659 , separator(separator)
664 ExcMessage(
"The separator must have a non-zero length."));
670 : pattern(other.pattern->clone())
671 , min_elements(other.min_elements)
672 , max_elements(other.max_elements)
673 , separator(other.separator)
696 const std::vector<std::string> split_list =
704 for (
const std::string &
string : split_list)
705 if (
pattern->match(
string) ==
false)
723 <<
pattern->description(style) <<
">"
743 <<
pattern->description(style) <<
"]";
757 std::unique_ptr<PatternBase>
760 return std::unique_ptr<PatternBase>(
774 std::unique_ptr<List>
783 std::string::const_iterator it =
description.begin() +
785 std::strlen(
" of <");
787 int n_open_angular = 1;
788 auto tmp_it = it - 1;
789 while (n_open_angular > 0)
791 tmp_it = std::find_if(tmp_it + 1,
description.end(), [](
char c) {
792 return (c ==
'>' || c ==
'<');
796 "Couldn't find a closing '>' in description!"));
803 std::string base_pattern_string(it, tmp_it);
804 std::unique_ptr<PatternBase> base_pattern(
807 std::istringstream is(
808 std::string(tmp_it + std::strlen(
" of length "),
description.end()));
810 return std::make_unique<List>(*base_pattern);
812 is.ignore(std::strlen(
"..."));
814 return std::make_unique<List>(*base_pattern,
min_elements);
816 is.ignore(std::strlen(
" (inclusive) separated by <"));
823 return std::make_unique<List>(*base_pattern,
829 return std::unique_ptr<List>();
835 std::numeric_limits<unsigned int>::max();
842 const unsigned int min_elements,
843 const unsigned int max_elements,
844 const std::string &separator,
845 const std::string &key_value_separator)
846 : key_pattern(p_key.clone())
847 , value_pattern(p_value.clone())
848 , min_elements(min_elements)
849 , max_elements(max_elements)
850 , separator(separator)
851 , key_value_separator(key_value_separator)
856 ExcMessage(
"The separator must have a non-zero length."));
858 ExcMessage(
"The key_value_separator must have a non-zero length."));
861 "The separator can not be the same of the key_value_separator "
862 "since that is used as the separator between the two elements "
863 "of <key:value> pairs"));
869 : key_pattern(other.key_pattern->clone())
870 , value_pattern(other.value_pattern->clone())
871 , min_elements(other.min_elements)
872 , max_elements(other.max_elements)
873 , separator(other.separator)
874 , key_value_separator(other.key_value_separator)
882 std::vector<std::string> split_list =
888 for (
const auto &key_value_pair : split_list)
890 std::vector<std::string> pair =
894 if (pair.size() != 2)
944 <<
" and each value is ["
959 std::unique_ptr<PatternBase>
974 return (
sizeof(*
this) +
996 std::getline(is, key,
'>');
1003 std::getline(is, value,
'>');
1008 is.ignore(std::strlen(
" of length "));
1012 is.ignore(std::strlen(
"..."));
1018 is.ignore(std::strlen(
" (inclusive) separated by <"));
1033 return std::unique_ptr<Map>();
1073 const std::string & separator)
1074 : separator(separator)
1077 ExcMessage(
"The Patterns list must have a non-zero length."));
1079 ExcMessage(
"The separator must have a non-zero length."));
1081 for (
unsigned int i = 0; i < ps.size(); ++i)
1088 const char * separator)
1089 :
Tuple(ps,
std::string(separator))
1095 : separator(other.separator)
1098 for (
unsigned int i = 0; i < other.
patterns.size(); ++i)
1107 std::vector<std::string> split_list =
1109 if (split_list.size() !=
patterns.size())
1112 for (
unsigned int i = 0; i <
patterns.size(); ++i)
1133 <<
"> elements <" <<
patterns[0]->description(style)
1135 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1154 <<
patterns[0]->description(style) <<
"]";
1155 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1158 <<
patterns[i]->description(style) <<
"]";
1173 std::unique_ptr<PatternBase>
1189 std::unique_ptr<Tuple>
1196 std::vector<std::unique_ptr<PatternBase>>
patterns;
1202 std::getline(is, len,
'>');
1205 ExcMessage(
"Provide at least 1 element in the tuple."));
1208 is.ignore(std::strlen(
" elements <"));
1210 std::string element;
1211 std::getline(is, element,
'>');
1214 for (
unsigned int i = 1; i < n_elements; ++i)
1216 is.ignore(std::strlen(
", <"));
1217 std::getline(is, element,
'>');
1221 is.ignore(std::strlen(
" separated by <"));
1232 return std::unique_ptr<Tuple>();
1258 Assert(seq.find(
',') == std::string::npos,
1262 while (
sequence.find(
" |") != std::string::npos)
1264 while (
sequence.find(
"| ") != std::string::npos)
1273 std::string tmp = test_string_list;
1274 std::vector<std::string> split_names;
1277 while (tmp.size() != 0)
1282 if (name.find(
',') != std::string::npos)
1284 name.erase(name.find(
','), std::string::npos);
1285 tmp.erase(0, tmp.find(
',') + 1);
1290 while ((name.size() != 0) && (std::isspace(name.front()) != 0))
1292 while ((name.size() != 0) && (std::isspace(name.back()) != 0))
1293 name.erase(name.size() - 1, 1);
1295 split_names.push_back(name);
1300 for (
const auto &test_string : split_names)
1302 bool string_found =
false;
1305 while (tmp.find(
'|') != std::string::npos)
1307 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
1313 string_found =
true;
1317 tmp.erase(0, tmp.find(
'|') + 1);
1321 if (test_string == tmp)
1322 string_found =
true;
1351 description <<
"A comma-separated list of any of "
1368 std::unique_ptr<PatternBase>
1384 std::unique_ptr<MultipleSelection>
1396 return std::make_unique<MultipleSelection>(
sequence);
1399 return std::unique_ptr<MultipleSelection>();
1429 return "A boolean value (true or false)";
1441 std::unique_ptr<PatternBase>
1444 return std::unique_ptr<PatternBase>(
new Bool());
1449 std::unique_ptr<Bool>
1455 return std::make_unique<Bool>();
1457 return std::unique_ptr<Bool>();
1490 return "Any string";
1502 std::unique_ptr<PatternBase>
1505 return std::unique_ptr<PatternBase>(
new Anything());
1510 std::unique_ptr<Anything>
1516 return std::make_unique<Anything>();
1518 return std::unique_ptr<Anything>();
1562 return "an input filename";
1564 return "an output filename";
1576 std::unique_ptr<PatternBase>
1584 std::unique_ptr<FileName>
1604 return std::make_unique<FileName>(type);
1607 return std::unique_ptr<FileName>();
1640 return "A directory name";
1652 std::unique_ptr<PatternBase>
1660 std::unique_ptr<DirectoryName>
1666 return std::make_unique<DirectoryName>();
1668 return std::unique_ptr<DirectoryName>();
static std::unique_ptr< Anything > create(const std::string &description)
virtual bool match(const std::string &test_string) const override
static const char * description_init
virtual std::string description(const OutputStyle style=Machine) const override
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::string description(const OutputStyle style=Machine) const override
static const char * description_init
virtual std::unique_ptr< PatternBase > clone() const override
static std::unique_ptr< Bool > create(const std::string &description)
virtual std::unique_ptr< PatternBase > clone() const override
static const char * description_init
virtual std::string description(const OutputStyle style=Machine) const override
static std::unique_ptr< DirectoryName > create(const std::string &description)
virtual bool match(const std::string &test_string) const override
static std::unique_ptr< Double > create(const std::string &description)
static const char * description_init
virtual std::unique_ptr< PatternBase > clone() const override
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
static const double max_double_value
static const double min_double_value
virtual std::string description(const OutputStyle style=Machine) const override
virtual bool match(const std::string &test_string) const override
virtual bool match(const std::string &test_string) const override
FileName(const FileType type=input)
static const char * description_init
virtual std::unique_ptr< PatternBase > clone() const override
static std::unique_ptr< FileName > create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const override
static std::unique_ptr< Integer > create(const std::string &description)
static const char * description_init
virtual std::unique_ptr< PatternBase > clone() const override
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
static const int min_int_value
virtual std::string description(const OutputStyle style=Machine) const override
virtual bool match(const std::string &test_string) const override
static const int max_int_value
const unsigned int max_elements
static const char * description_init
const unsigned int min_elements
std::unique_ptr< PatternBase > pattern
const std::string separator
std::size_t memory_consumption() const override
static std::unique_ptr< List > create(const std::string &description)
virtual std::string description(const OutputStyle style=Machine) const override
const PatternBase & get_base_pattern() const
virtual bool match(const std::string &test_string) const override
const std::string & get_separator() const
List(const PatternBase &base_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",")
static const unsigned int max_int_value
virtual std::unique_ptr< PatternBase > clone() const override
static std::unique_ptr< Map > create(const std::string &description)
std::unique_ptr< PatternBase > value_pattern
const unsigned int min_elements
const PatternBase & get_key_pattern() const
virtual bool match(const std::string &test_string) const override
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=":")
const unsigned int max_elements
virtual std::unique_ptr< PatternBase > clone() const override
const PatternBase & get_value_pattern() const
const std::string & get_separator() const
virtual std::string description(const OutputStyle style=Machine) const override
static const unsigned int max_int_value
std::unique_ptr< PatternBase > key_pattern
const std::string separator
std::size_t memory_consumption() const override
static const char * description_init
const std::string & get_key_value_separator() const
const std::string key_value_separator
MultipleSelection(const std::string &seq)
static std::unique_ptr< MultipleSelection > create(const std::string &description)
virtual bool match(const std::string &test_string) const override
virtual std::unique_ptr< PatternBase > clone() const override
static const char * description_init
std::size_t memory_consumption() const override
virtual std::string description(const OutputStyle style=Machine) const override
virtual std::size_t memory_consumption() const
static const char * description_init
virtual std::string description(const OutputStyle style=Machine) const override
virtual std::unique_ptr< PatternBase > clone() const override
virtual bool match(const std::string &test_string) const override
static std::unique_ptr< Selection > create(const std::string &description)
std::size_t memory_consumption() const override
Selection(const std::string &seq)
virtual bool match(const std::string &test_string) const override
std::size_t memory_consumption() const override
static std::unique_ptr< Tuple > create(const std::string &description)
std::vector< std::unique_ptr< PatternBase > > patterns
virtual std::unique_ptr< PatternBase > clone() const override
const std::string separator
static const char * description_init
Tuple(const std::vector< std::unique_ptr< PatternBase > > &patterns, const std::string &separator=":")
const std::string & get_separator() const
const PatternBase & get_pattern(const unsigned int i) const
virtual std::string description(const OutputStyle style=Machine) const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
int string_to_int(const std::string &s)