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;
214 : lower_bound(lower_bound)
215 , upper_bound(upper_bound)
223 std::istringstream str(test_string);
229 if (!has_only_whitespace(str))
258 return description.str();
271 description <<
"An integer n such that " <<
lower_bound 274 return description.str();
285 description <<
"An integer @f$n@f$ such that @f$" <<
lower_bound 288 return description.str();
303 std::unique_ptr<PatternBase>
311 std::unique_ptr<Integer>
314 if (description.compare(0,
318 std::istringstream is(description);
328 if (!(is >> lower_bound))
329 return std::make_unique<Integer>();
331 is.ignore(strlen(
"..."));
333 if (!(is >> upper_bound))
334 return std::make_unique<Integer>();
339 return std::make_unique<Integer>();
342 return std::unique_ptr<Integer>();
353 : lower_bound(lower_bound)
354 , upper_bound(upper_bound)
362 std::istringstream str(test_string);
369 if (!has_only_whitespace(str))
400 description <<
"-MAX_DOUBLE";
403 description <<
"...";
407 description <<
"MAX_DOUBLE";
410 description <<
" (inclusive)]";
411 return description.str();
417 return description.str();
426 description <<
"A floating point number v such that ";
430 description <<
"-MAX_DOUBLE";
433 description <<
" <= v <= ";
437 description <<
"MAX_DOUBLE";
441 return description.str();
444 return "A floating point number";
452 description <<
"A floating point number @f$v@f$ such that @f$";
456 description <<
"-\\text{MAX\\_DOUBLE}";
459 description <<
" \\leq v \\leq ";
463 description <<
"\\text{MAX\\_DOUBLE}";
466 description <<
"@f$";
468 return description.str();
471 return "A floating point number";
482 std::unique_ptr<PatternBase>
490 std::unique_ptr<Double>
494 if (description.compare(0,
495 description_init_str.size(),
496 description_init_str) != 0)
497 return std::unique_ptr<Double>();
498 if (*description.rbegin() !=
']')
499 return std::unique_ptr<Double>();
501 std::string temp = description.substr(description_init_str.size());
503 return std::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"));
517 if (!(is >> lower_bound))
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)
588 return description.str();
595 description <<
"Any one of " 600 return description.str();
612 std::unique_ptr<PatternBase>
628 std::unique_ptr<Selection>
631 if (description.compare(0,
638 sequence.erase(sequence.length() - 2, 2);
640 return std::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)
663 Assert(min_elements <= max_elements,
665 Assert(separator.size() > 0,
666 ExcMessage(
"The separator must have a non-zero length."));
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) <<
">" 729 description <<
" separated by <" <<
separator <<
">";
732 return description.str();
742 description <<
"separated by <" 744 description <<
"where each element is [" 745 <<
pattern->description(style) <<
"]";
747 return description.str();
759 std::unique_ptr<PatternBase>
762 return std::unique_ptr<PatternBase>(
776 std::unique_ptr<List>
779 if (description.compare(0,
785 std::istringstream is(description);
789 std::getline(is, str,
'>');
793 is.ignore(strlen(
" of length "));
794 if (!(is >> min_elements))
795 return std::make_unique<List>(*base_pattern);
797 is.ignore(strlen(
"..."));
799 return std::make_unique<List>(*base_pattern,
min_elements);
801 is.ignore(strlen(
" (inclusive) separated by <"));
804 std::getline(is, separator,
'>');
808 return std::make_unique<List>(*base_pattern,
814 return std::unique_ptr<List>();
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)
838 Assert(min_elements <= max_elements,
840 Assert(separator.size() > 0,
841 ExcMessage(
"The separator must have a non-zero length."));
842 Assert(key_value_separator.size() > 0,
843 ExcMessage(
"The key_value_separator must have a non-zero length."));
844 Assert(separator != key_value_separator,
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"));
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)
910 description <<
" separated by <" <<
separator <<
">";
913 return description.str();
920 description <<
"A key" 925 description <<
" separated by <" 927 description <<
" where each key is [" 929 <<
" and each value is [" 932 return description.str();
944 std::unique_ptr<PatternBase>
959 return (
sizeof(*
this) +
971 if (description.compare(0,
977 std::istringstream is(description);
981 std::getline(is, key,
'>');
984 std::getline(is, key_value_separator,
'<');
988 std::getline(is, value,
'>');
993 is.ignore(strlen(
" of length "));
994 if (!(is >> min_elements))
997 is.ignore(strlen(
"..."));
1003 is.ignore(strlen(
" (inclusive) separated by <"));
1006 std::getline(is, separator,
'>');
1018 return std::unique_ptr<Map>();
1059 : separator(separator)
1062 ExcMessage(
"The Patterns list must have a non-zero length."));
1063 Assert(separator.size() > 0,
1064 ExcMessage(
"The separator must have a non-zero length."));
1066 for (
unsigned int i = 0; i < ps.size(); ++i)
1074 :
Tuple(ps,
std::string(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)
1124 description <<
" separated by <" <<
separator <<
">";
1127 return description.str();
1134 description <<
"A Tuple of " <<
patterns.size() <<
" elements ";
1136 description <<
" separated by <" 1138 description <<
" where each element is [" 1139 <<
patterns[0]->description(style) <<
"]";
1140 for (
unsigned int i = 1; i <
patterns.size(); ++i)
1143 <<
patterns[i]->description(style) <<
"]";
1145 return description.str();
1158 std::unique_ptr<PatternBase>
1174 std::unique_ptr<Tuple>
1177 if (description.compare(0,
1181 std::vector<std::unique_ptr<PatternBase>>
patterns;
1183 std::istringstream is(description);
1187 std::getline(is, len,
'>');
1190 ExcMessage(
"Provide at least 1 element in the tuple."));
1191 patterns.resize(n_elements);
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 <"));
1210 std::getline(is, separator,
'>');
1217 return std::unique_ptr<Tuple>();
1243 Assert(seq.find(
',') == std::string::npos,
1244 ExcCommasNotAllowed(seq.find(
',')));
1247 while (sequence.find(
" |") != std::string::npos)
1248 sequence.replace(sequence.find(
" |"), 2,
"|");
1249 while (sequence.find(
"| ") != std::string::npos)
1250 sequence.replace(sequence.find(
"| "), 2,
"|");
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;
1329 return description.str();
1336 description <<
"A comma-separated list of any of " 1341 return description.str();
1353 std::unique_ptr<PatternBase>
1369 std::unique_ptr<MultipleSelection>
1372 if (description.compare(0,
1376 std::string sequence(description);
1379 sequence.erase(sequence.length() - 2, 2);
1381 return std::make_unique<MultipleSelection>(sequence);
1384 return std::unique_ptr<MultipleSelection>();
1409 return description.str();
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>
1437 if (description.compare(0,
1440 return std::make_unique<Bool>();
1442 return std::unique_ptr<Bool>();
1470 return description.str();
1475 return "Any string";
1487 std::unique_ptr<PatternBase>
1490 return std::unique_ptr<PatternBase>(
new Anything());
1495 std::unique_ptr<Anything>
1498 if (description.compare(0,
1501 return std::make_unique<Anything>();
1503 return std::unique_ptr<Anything>();
1537 description <<
" (Type: input)]";
1539 description <<
" (Type: output)]";
1541 return description.str();
1547 return "an input filename";
1549 return "an output filename";
1561 std::unique_ptr<PatternBase>
1569 std::unique_ptr<FileName>
1572 if (description.compare(0,
1576 std::istringstream is(description);
1584 if (file_type ==
"input)]")
1589 return std::make_unique<FileName>(type);
1592 return std::unique_ptr<FileName>();
1620 return description.str();
1625 return "A directory name";
1637 std::unique_ptr<PatternBase>
1645 std::unique_ptr<DirectoryName>
1648 if (description.compare(0,
1651 return std::make_unique<DirectoryName>();
1653 return std::unique_ptr<DirectoryName>();
const std::string & get_separator() const
Iterator lower_bound(Iterator first, Iterator last, const T &val)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
virtual std::string description(const OutputStyle style=Machine) const override
const std::string & get_separator() const
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
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
const PatternBase & get_pattern(const unsigned int i) const
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 PatternBase & get_value_pattern() const
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
#define AssertThrow(cond, exc)
const std::string & get_separator() const
const unsigned int max_elements
static const char * description_init
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
static const int min_int_value
virtual std::unique_ptr< PatternBase > clone() const override
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
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
const PatternBase & get_key_pattern() const
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)
virtual std::size_t memory_consumption() const
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
const PatternBase & get_base_pattern() const
std::size_t memory_consumption() const override
static std::unique_ptr< Double > create(const std::string &description)
#define DEAL_II_NAMESPACE_CLOSE
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
const std::string & get_key_value_separator() const
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)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
virtual std::unique_ptr< PatternBase > clone() const override
std::size_t memory_consumption() const override
static const char * description_init
static const double max_double_value
virtual std::unique_ptr< PatternBase > clone() const override
virtual std::string description(const OutputStyle style=Machine) const override
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_OPEN
T min(const T &t, const MPI_Comm &mpi_communicator)
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
virtual std::string description(const OutputStyle style=Machine) const override
const unsigned int min_elements
static const unsigned int max_int_value
virtual std::string description(const OutputStyle style=Machine) const override
std::unique_ptr< PatternBase > value_pattern
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
T max(const T &t, const MPI_Comm &mpi_communicator)
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)
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