22#define BOOST_BIND_GLOBAL_PLACEHOLDERS
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>
27#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
62 u.reserve(input.size());
63 for (
const auto c : input)
80 u.append(
"\\textbackslash{}");
116 has_only_whitespace(std::istream &in)
127 if ((c !=
' ') && (c !=
'\t'))
136 std::unique_ptr<PatternBase>
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 : lower_bound(lower_bound)
212 , upper_bound(upper_bound)
220 std::istringstream str(test_string);
226 if (!has_only_whitespace(str))
300 std::unique_ptr<PatternBase>
308 std::unique_ptr<Integer>
326 return std::make_unique<Integer>();
328 is.ignore(std::strlen(
"..."));
331 return std::make_unique<Integer>();
336 return std::make_unique<Integer>();
339 return std::unique_ptr<Integer>();
350 : lower_bound(lower_bound)
351 , upper_bound(upper_bound)
359 std::istringstream str(test_string);
366 if (!has_only_whitespace(str))
423 description <<
"A floating point number v such that ";
441 return "A floating point number";
449 description <<
"A floating point number @f$v@f$ such that @f$";
468 return "A floating point number";
479 std::unique_ptr<PatternBase>
487 std::unique_ptr<Double>
492 description_init_str.size(),
493 description_init_str) != 0)
494 return std::unique_ptr<Double>();
496 return std::unique_ptr<Double>();
498 std::string temp =
description.substr(description_init_str.size());
500 return std::make_unique<Double>(1.0,
503 if (temp.find(
"...") != std::string::npos)
504 temp.replace(temp.find(
"..."), 3,
" ");
508 std::istringstream is(temp);
509 if (0 == temp.compare(0, std::strlen(
" -MAX_DOUBLE"),
" -MAX_DOUBLE"))
510 is.ignore(std::strlen(
" -MAX_DOUBLE"));
515 return std::unique_ptr<Double>();
534 while (
sequence.find(
" |") != std::string::npos)
536 while (
sequence.find(
"| ") != std::string::npos)
548 while ((tmp.size() != 0) && (std::isspace(tmp.front()) != 0))
552 while (tmp.find(
'|') != std::string::npos)
554 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
557 tmp.erase(0, tmp.find(
'|') + 1);
561 while ((tmp.size() != 0) && (std::isspace(tmp.back()) != 0))
562 tmp.erase(tmp.end() - 1);
565 if (test_string == tmp)
609 std::unique_ptr<PatternBase>
625 std::unique_ptr<Selection>
637 return std::make_unique<Selection>(
sequence);
640 return std::unique_ptr<Selection>();
646 std::numeric_limits<unsigned int>::max();
652 const unsigned int min_elements,
653 const unsigned int max_elements,
654 const std::string &separator)
656 , min_elements(min_elements)
657 , max_elements(max_elements)
658 , separator(separator)
663 ExcMessage(
"The separator must have a non-zero length."));
669 : pattern(other.pattern->clone())
670 , min_elements(other.min_elements)
671 , max_elements(other.max_elements)
672 , separator(other.separator)
695 const std::vector<std::string> split_list =
703 for (
const std::string &
string : split_list)
704 if (
pattern->match(
string) ==
false)
722 <<
pattern->description(style) <<
">"
742 <<
pattern->description(style) <<
"]";
756 std::unique_ptr<PatternBase>
759 return std::unique_ptr<PatternBase>(
773 std::unique_ptr<List>
782 std::string::const_iterator it =
description.begin() +
784 std::strlen(
" of <");
786 int n_open_angular = 1;
787 auto tmp_it = it - 1;
788 while (n_open_angular > 0)
790 tmp_it = std::find_if(tmp_it + 1,
description.end(), [](
char c) {
791 return (c ==
'>' || c ==
'<');
795 "Couldn't find a closing '>' in description!"));
802 std::string base_pattern_string(it, tmp_it);
803 std::unique_ptr<PatternBase> base_pattern(
806 std::istringstream is(
807 std::string(tmp_it + std::strlen(
" of length "),
description.end()));
809 return std::make_unique<List>(*base_pattern);
811 is.ignore(std::strlen(
"..."));
813 return std::make_unique<List>(*base_pattern,
min_elements);
815 is.ignore(std::strlen(
" (inclusive) separated by <"));
822 return std::make_unique<List>(*base_pattern,
828 return std::unique_ptr<List>();
834 std::numeric_limits<unsigned int>::max();
841 const unsigned int min_elements,
842 const unsigned int max_elements,
843 const std::string &separator,
844 const std::string &key_value_separator)
845 : key_pattern(p_key.clone())
846 , value_pattern(p_value.clone())
847 , min_elements(min_elements)
848 , max_elements(max_elements)
849 , separator(separator)
850 , key_value_separator(key_value_separator)
855 ExcMessage(
"The separator must have a non-zero length."));
857 ExcMessage(
"The key_value_separator must have a non-zero length."));
860 "The separator can not be the same of the key_value_separator "
861 "since that is used as the separator between the two elements "
862 "of <key:value> pairs"));
868 : key_pattern(other.key_pattern->clone())
869 , value_pattern(other.value_pattern->clone())
870 , min_elements(other.min_elements)
871 , max_elements(other.max_elements)
872 , separator(other.separator)
873 , key_value_separator(other.key_value_separator)
881 std::vector<std::string> split_list =
887 for (
const auto &key_value_pair : split_list)
889 std::vector<std::string> pair =
893 if (pair.size() != 2)
943 <<
" and each value is ["
958 std::unique_ptr<PatternBase>
973 return (
sizeof(*
this) +
995 std::getline(is, key,
'>');
1002 std::getline(is, value,
'>');
1007 is.ignore(std::strlen(
" of length "));
1011 is.ignore(std::strlen(
"..."));
1017 is.ignore(std::strlen(
" (inclusive) separated by <"));
1032 return std::unique_ptr<Map>();
1072 const std::string &separator)
1073 : separator(separator)
1076 ExcMessage(
"The Patterns list must have a non-zero length."));
1078 ExcMessage(
"The separator must have a non-zero length."));
1080 for (
unsigned int i = 0; i < ps.size(); ++i)
1087 const char *separator)
1088 :
Tuple(ps,
std::string(separator))
1094 : separator(other.separator)
1097 for (
unsigned int i = 0; i < other.
patterns.size(); ++i)
1106 std::vector<std::string> split_list =
1108 if (split_list.size() !=
patterns.size())
1111 for (
unsigned int i = 0; i <
patterns.size(); ++i)
1132 <<
"> elements <" <<
patterns[0]->description(style)
1134 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1153 <<
patterns[0]->description(style) <<
"]";
1154 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1157 <<
patterns[i]->description(style) <<
"]";
1172 std::unique_ptr<PatternBase>
1188 std::unique_ptr<Tuple>
1195 std::vector<std::unique_ptr<PatternBase>>
patterns;
1201 std::getline(is, len,
'>');
1204 ExcMessage(
"Provide at least 1 element in the tuple."));
1207 is.ignore(std::strlen(
" elements <"));
1209 std::string element;
1210 std::getline(is, element,
'>');
1213 for (
unsigned int i = 1; i < n_elements; ++i)
1215 is.ignore(std::strlen(
", <"));
1216 std::getline(is, element,
'>');
1220 is.ignore(std::strlen(
" separated by <"));
1231 return std::unique_ptr<Tuple>();
1257 Assert(seq.find(
',') == std::string::npos,
1261 while (
sequence.find(
" |") != std::string::npos)
1263 while (
sequence.find(
"| ") != std::string::npos)
1272 std::string tmp = test_string_list;
1273 std::vector<std::string> split_names;
1276 while (tmp.size() != 0)
1281 if (name.find(
',') != std::string::npos)
1283 name.erase(name.find(
','), std::string::npos);
1284 tmp.erase(0, tmp.find(
',') + 1);
1289 while ((name.size() != 0) && (std::isspace(name.front()) != 0))
1291 while ((name.size() != 0) && (std::isspace(name.back()) != 0))
1292 name.erase(name.size() - 1, 1);
1294 split_names.push_back(name);
1299 for (
const auto &test_string : split_names)
1301 bool string_found =
false;
1304 while (tmp.find(
'|') != std::string::npos)
1306 if (test_string == std::string(tmp, 0, tmp.find(
'|')))
1312 string_found =
true;
1316 tmp.erase(0, tmp.find(
'|') + 1);
1320 if (test_string == tmp)
1321 string_found =
true;
1350 description <<
"A comma-separated list of any of "
1367 std::unique_ptr<PatternBase>
1383 std::unique_ptr<MultipleSelection>
1395 return std::make_unique<MultipleSelection>(
sequence);
1398 return std::unique_ptr<MultipleSelection>();
1428 return "A boolean value (true or false)";
1440 std::unique_ptr<PatternBase>
1443 return std::unique_ptr<PatternBase>(
new Bool());
1448 std::unique_ptr<Bool>
1454 return std::make_unique<Bool>();
1456 return std::unique_ptr<Bool>();
1489 return "Any string";
1501 std::unique_ptr<PatternBase>
1504 return std::unique_ptr<PatternBase>(
new Anything());
1509 std::unique_ptr<Anything>
1515 return std::make_unique<Anything>();
1517 return std::unique_ptr<Anything>();
1561 return "an input filename";
1563 return "an output filename";
1575 std::unique_ptr<PatternBase>
1583 std::unique_ptr<FileName>
1603 return std::make_unique<FileName>(type);
1606 return std::unique_ptr<FileName>();
1639 return "A directory name";
1651 std::unique_ptr<PatternBase>
1659 std::unique_ptr<DirectoryName>
1665 return std::make_unique<DirectoryName>();
1667 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)
#define DEAL_II_NOT_IMPLEMENTED()
std::enable_if_t< std::is_fundamental_v< T >, 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)