Reference documentation for deal.II version GIT 6113e8d4d8 2022-09-29 15:30:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
patterns.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2022 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_patterns_h
17 #define dealii_patterns_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/point.h>
26 #include <deal.II/base/utilities.h>
27 
29 
31 #include <boost/archive/basic_archive.hpp>
32 #include <boost/core/demangle.hpp>
33 #include <boost/property_tree/ptree_fwd.hpp>
34 #include <boost/property_tree/ptree_serialization.hpp>
35 #include <boost/serialization/split_member.hpp>
37 
38 #include <algorithm>
39 #include <array>
40 #include <deque>
41 #include <limits>
42 #include <list>
43 #include <map>
44 #include <memory>
45 #include <set>
46 #include <sstream>
47 #include <string>
48 #include <type_traits>
49 #include <unordered_map>
50 #include <unordered_set>
51 #include <utility>
52 #include <vector>
53 
55 
56 // forward declarations for interfaces and friendship
57 #ifndef DOXYGEN
58 class LogStream;
60 template <int dim>
61 class FunctionParser;
62 #endif
63 
72 namespace Patterns
73 {
81  {
82  public:
86  virtual ~PatternBase() = default;
87 
91  virtual bool
92  match(const std::string &test_string) const = 0;
93 
100  {
116  LaTeX
117  };
118 
122  virtual std::string
123  description(const OutputStyle style = Machine) const = 0;
124 
134  virtual std::unique_ptr<PatternBase>
135  clone() const = 0;
136 
152  virtual std::size_t
153  memory_consumption() const;
154  };
155 
159  std::unique_ptr<PatternBase>
160  pattern_factory(const std::string &description);
161 
162  namespace internal
163  {
169  std::string
170  escape(const std::string &input, const PatternBase::OutputStyle style);
171 
172  } // namespace internal
173 
190  class Integer : public PatternBase
191  {
192  public:
198  static const int min_int_value;
199 
205  static const int max_int_value;
206 
219  Integer(const int lower_bound = min_int_value,
220  const int upper_bound = max_int_value);
221 
226  virtual bool
227  match(const std::string &test_string) const override;
228 
234  virtual std::string
235  description(const OutputStyle style = Machine) const override;
236 
242  virtual std::unique_ptr<PatternBase>
243  clone() const override;
244 
250  static std::unique_ptr<Integer>
251  create(const std::string &description);
252 
253  private:
260  const int lower_bound;
261 
268  const int upper_bound;
269 
273  static const char *description_init;
274  };
275 
293  class Double : public PatternBase
294  {
295  public:
300  static const double min_double_value;
301 
306  static const double max_double_value;
307 
315  Double(const double lower_bound = min_double_value,
316  const double upper_bound = max_double_value);
317 
322  virtual bool
323  match(const std::string &test_string) const override;
324 
330  virtual std::string
331  description(const OutputStyle style = Machine) const override;
332 
338  virtual std::unique_ptr<PatternBase>
339  clone() const override;
340 
348  static std::unique_ptr<Double>
349  create(const std::string &description);
350 
351  private:
358  const double lower_bound;
359 
366  const double upper_bound;
367 
371  static const char *description_init;
372  };
373 
383  class Selection : public PatternBase
384  {
385  public:
390  Selection(const std::string &seq);
391 
396  virtual bool
397  match(const std::string &test_string) const override;
398 
404  virtual std::string
405  description(const OutputStyle style = Machine) const override;
406 
412  virtual std::unique_ptr<PatternBase>
413  clone() const override;
414 
419  std::size_t
420  memory_consumption() const override;
421 
427  static std::unique_ptr<Selection>
428  create(const std::string &description);
429 
430  private:
435  std::string sequence;
436 
440  static const char *description_init;
441  };
442 
443 
451  class List : public PatternBase
452  {
453  public:
459  static const unsigned int max_int_value;
460 
469  List(const PatternBase &base_pattern,
470  const unsigned int min_elements = 0,
471  const unsigned int max_elements = max_int_value,
472  const std::string &separator = ",");
473 
474 
478  const std::string &
479  get_separator() const;
480 
484  const PatternBase &
485  get_base_pattern() const;
486 
490  List(const List &other);
491 
496  virtual bool
497  match(const std::string &test_string) const override;
498 
503  virtual std::string
504  description(const OutputStyle style = Machine) const override;
505 
511  virtual std::unique_ptr<PatternBase>
512  clone() const override;
513 
519  static std::unique_ptr<List>
520  create(const std::string &description);
521 
526  std::size_t
527  memory_consumption() const override;
528 
538  int,
539  int,
540  << "The values " << arg1 << " and " << arg2
541  << " do not form a valid range.");
543  private:
547  std::unique_ptr<PatternBase> pattern;
548 
552  const unsigned int min_elements;
553 
557  const unsigned int max_elements;
558 
562  const std::string separator;
563 
567  static const char *description_init;
568  };
569 
570 
585  class Map : public PatternBase
586  {
587  public:
593  static const unsigned int max_int_value;
594 
603  Map(const PatternBase &key_pattern,
604  const PatternBase &value_pattern,
605  const unsigned int min_elements = 0,
606  const unsigned int max_elements = max_int_value,
607  const std::string &separator = ",",
608  const std::string &key_value_separator = ":");
609 
613  Map(const Map &other);
614 
619  virtual bool
620  match(const std::string &test_string) const override;
621 
626  virtual std::string
627  description(const OutputStyle style = Machine) const override;
628 
634  virtual std::unique_ptr<PatternBase>
635  clone() const override;
636 
642  static std::unique_ptr<Map>
643  create(const std::string &description);
644 
649  std::size_t
650  memory_consumption() const override;
651 
655  const PatternBase &
656  get_key_pattern() const;
657 
661  const PatternBase &
662  get_value_pattern() const;
663 
667  const std::string &
668  get_separator() const;
669 
673  const std::string &
674  get_key_value_separator() const;
675 
685  int,
686  int,
687  << "The values " << arg1 << " and " << arg2
688  << " do not form a valid range.");
690  private:
695  std::unique_ptr<PatternBase> key_pattern;
696  std::unique_ptr<PatternBase> value_pattern;
697 
701  const unsigned int min_elements;
702 
706  const unsigned int max_elements;
707 
711  const std::string separator;
712 
713 
717  const std::string key_value_separator;
718 
722  static const char *description_init;
723  };
724 
725 
726 
772  class Tuple : public PatternBase
773  {
774  public:
783  Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
784  const std::string & separator = ":");
785 
791  Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
792  const char * separator);
793 
794 
802  template <class... PatternTypes>
803  Tuple(const std::string &separator, const PatternTypes &...patterns);
804 
812  template <class... PatternTypes>
813  Tuple(const char *separator, const PatternTypes &...patterns);
814 
820  template <typename... Patterns>
821  Tuple(const Patterns &...patterns);
822 
826  Tuple(const Tuple &other);
827 
832  virtual bool
833  match(const std::string &test_string) const override;
834 
839  virtual std::string
840  description(const OutputStyle style = Machine) const override;
841 
847  virtual std::unique_ptr<PatternBase>
848  clone() const override;
849 
855  static std::unique_ptr<Tuple>
856  create(const std::string &description);
857 
862  std::size_t
863  memory_consumption() const override;
864 
868  const PatternBase &
869  get_pattern(const unsigned int i) const;
870 
874  const std::string &
875  get_separator() const;
876 
877  private:
881  std::vector<std::unique_ptr<PatternBase>> patterns;
882 
886  const std::string separator;
887 
891  static const char *description_init;
892  };
893 
894 
906  {
907  public:
911  MultipleSelection(const std::string &seq);
912 
917  virtual bool
918  match(const std::string &test_string) const override;
919 
925  virtual std::string
926  description(const OutputStyle style = Machine) const override;
927 
933  virtual std::unique_ptr<PatternBase>
934  clone() const override;
935 
941  static std::unique_ptr<MultipleSelection>
942  create(const std::string &description);
943 
948  std::size_t
949  memory_consumption() const override;
950 
961  int,
962  << "A comma was found at position " << arg1
963  << " of your input string, but commas are not allowed here.");
965  private:
970  std::string sequence;
971 
975  static const char *description_init;
976  };
977 
982  class Bool : public Selection
983  {
984  public:
988  Bool();
989 
994  virtual std::string
995  description(const OutputStyle style = Machine) const override;
996 
1002  virtual std::unique_ptr<PatternBase>
1003  clone() const override;
1004 
1010  static std::unique_ptr<Bool>
1011  create(const std::string &description);
1012 
1013  private:
1017  static const char *description_init;
1018  };
1019 
1023  class Anything : public PatternBase
1024  {
1025  public:
1030  Anything() = default;
1031 
1036  virtual bool
1037  match(const std::string &test_string) const override;
1038 
1043  virtual std::string
1044  description(const OutputStyle style = Machine) const override;
1045 
1051  virtual std::unique_ptr<PatternBase>
1052  clone() const override;
1053 
1059  static std::unique_ptr<Anything>
1060  create(const std::string &description);
1061 
1062  private:
1066  static const char *description_init;
1067  };
1068 
1069 
1084  class FileName : public PatternBase
1085  {
1086  public:
1092  {
1096  input = 0,
1100  output = 1
1101  };
1102 
1107  FileName(const FileType type = input);
1108 
1113  virtual bool
1114  match(const std::string &test_string) const override;
1115 
1120  virtual std::string
1121  description(const OutputStyle style = Machine) const override;
1122 
1128  virtual std::unique_ptr<PatternBase>
1129  clone() const override;
1130 
1135 
1141  static std::unique_ptr<FileName>
1142  create(const std::string &description);
1143 
1144  private:
1148  static const char *description_init;
1149  };
1150 
1151 
1165  {
1166  public:
1170  DirectoryName() = default;
1171 
1176  virtual bool
1177  match(const std::string &test_string) const override;
1178 
1183  virtual std::string
1184  description(const OutputStyle style = Machine) const override;
1185 
1191  virtual std::unique_ptr<PatternBase>
1192  clone() const override;
1193 
1199  static std::unique_ptr<DirectoryName>
1200  create(const std::string &description);
1201 
1202  private:
1206  static const char *description_init;
1207  };
1208 
1209 
1288  namespace Tools
1289  {
1299  template <class T, class Enable = void>
1300  struct Convert
1301  {
1311  static std::unique_ptr<Patterns::PatternBase>
1312  to_pattern() = delete;
1313 
1324  static std::string
1325  to_string(const T & s,
1327  delete;
1328 
1338  static T
1339  to_value(const std::string & s,
1341  delete;
1342  };
1343 
1362  template <typename T>
1363  std::string
1364  to_string(const T &t);
1365 
1391  template <typename T>
1392  void
1393  to_value(const std::string &s, T &t);
1394 
1404  std::string,
1405  std::string,
1406  << "The string \"" << arg1
1407  << "\" does not match the pattern \"" << arg2 << "\"");
1409  } // namespace Tools
1410 } // namespace Patterns
1411 
1412 
1413 // ---------------------- inline and template functions --------------------
1414 namespace Patterns
1415 {
1416  template <class... PatternTypes>
1417  Tuple::Tuple(const char *separator, const PatternTypes &...ps)
1418  : // forward to the version with std::string argument
1419  Tuple(std::string(separator), ps...)
1420  {}
1421 
1422 
1423 
1424  template <class... PatternTypes>
1425  Tuple::Tuple(const std::string &separator, const PatternTypes &...ps)
1426  : separator(separator)
1427  {
1429  "Not all of the input arguments of this function "
1430  "are derived from PatternBase");
1431  static_assert(sizeof...(ps) > 0,
1432  "The number of PatternTypes must be greater than zero!");
1433  const auto pattern_pointers = {(static_cast<const PatternBase *>(&ps))...};
1434  for (const auto p : pattern_pointers)
1435  patterns.push_back(p->clone());
1436  }
1437 
1438 
1439 
1440  template <class... PatternTypes>
1441  Tuple::Tuple(const PatternTypes &...ps)
1442  : // forward to the version with the separator argument
1443  Tuple(std::string(":"), ps...)
1444  {}
1445 
1446 
1447 
1448  namespace Tools
1449  {
1450  namespace internal
1451  {
1476  template <class T, class Enable = void>
1477  struct RankInfo
1478  {
1479  static constexpr int list_rank = 0;
1480  static constexpr int map_rank = 0;
1481  };
1482  } // namespace internal
1483 
1484  // Arithmetic types
1485  template <class T>
1486  struct Convert<T, std::enable_if_t<std::is_arithmetic<T>::value>>
1487  {
1488  template <typename Dummy = T>
1489  static std::enable_if_t<std::is_same<Dummy, T>::value &&
1490  std::is_same<T, bool>::value,
1491  std::unique_ptr<Patterns::PatternBase>>
1493  {
1494  return std::make_unique<Patterns::Bool>();
1495  }
1496 
1497  template <typename Dummy = T>
1498  static std::enable_if_t<std::is_same<Dummy, T>::value &&
1499  !std::is_same<T, bool>::value &&
1500  std::is_integral<T>::value,
1501  std::unique_ptr<Patterns::PatternBase>>
1503  {
1504  return std::make_unique<Patterns::Integer>(
1505  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1506  }
1507 
1508  template <typename Dummy = T>
1509  static std::enable_if_t<std::is_same<Dummy, T>::value &&
1510  !std::is_same<T, bool>::value &&
1511  std::is_floating_point<T>::value,
1512  std::unique_ptr<Patterns::PatternBase>>
1514  {
1515  return std::make_unique<Patterns::Double>(
1516  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1517  }
1518 
1519  static std::string
1520  to_string(const T & value,
1522  {
1523  std::stringstream str;
1524  if (std::is_same<T, unsigned char>::value ||
1525  std::is_same<T, signed char>::value || std::is_same<T, char>::value)
1526  str << static_cast<int>(value);
1527  else if (std::is_same<T, bool>::value)
1528  str << (static_cast<bool>(value) ? "true" : "false");
1529  else
1530  str << value;
1531  AssertThrow(p.match(str.str()), ExcNoMatch(str.str(), p.description()));
1532  return str.str();
1533  }
1534 
1535  static T
1536  to_value(const std::string & s,
1538  {
1539  AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
1540  T value;
1541  if (std::is_same<T, bool>::value)
1542  value = (s == "true");
1543  else
1544  {
1545  std::istringstream is(s);
1546  if (std::is_same<T, unsigned char>::value ||
1547  std::is_same<T, signed char>::value ||
1548  std::is_same<T, char>::value)
1549  {
1550  int i;
1551  is >> i;
1552  value = i;
1553  }
1554  else
1555  is >> value;
1556 
1557  // If someone passes "123 abc" to the function, the method yields an
1558  // integer 123 alright, but the space terminates the read from the
1559  // string although there is more to come. This case, however, is
1560  // checked for in the call p->match(s) at the beginning of this
1561  // function, and would throw earlier. Here it is safe to assume that
1562  // if we didn't fail the conversion with the operator >>, then we
1563  // are good to go.
1564  AssertThrow(
1565  !is.fail(),
1566  ExcMessage("Failed to convert from \"" + s + "\" to the type \"" +
1567  boost::core::demangle(typeid(T).name()) + "\""));
1568  }
1569  return value;
1570  }
1571  };
1572 
1573  namespace internal
1574  {
1575  constexpr std::array<const char *, 4> default_list_separator{
1576  {",", ";", "|", "%"}};
1577  constexpr std::array<const char *, 4> default_map_separator{
1578  {":", "=", "@", "#"}};
1579 
1580  // specialize a type for all of the STL containers and maps
1581  template <typename T>
1582  struct is_list_compatible : std::false_type
1583  {};
1584  template <typename... Args>
1585  struct is_list_compatible<std::vector<Args...>> : std::true_type
1586  {};
1587  template <typename... Args>
1588  struct is_list_compatible<std::deque<Args...>> : std::true_type
1589  {};
1590  template <typename... Args>
1591  struct is_list_compatible<std::list<Args...>> : std::true_type
1592  {};
1593  template <typename... Args>
1594  struct is_list_compatible<std::set<Args...>> : std::true_type
1595  {};
1596  template <typename... Args>
1597  struct is_list_compatible<std::multiset<Args...>> : std::true_type
1598  {};
1599  template <typename... Args>
1600  struct is_list_compatible<std::unordered_set<Args...>> : std::true_type
1601  {};
1602  template <typename... Args>
1603  struct is_list_compatible<std::unordered_multiset<Args...>>
1604  : std::true_type
1605  {};
1606 
1607  template <typename T>
1608  struct is_map_compatible : std::false_type
1609  {};
1610  template <class Key, class T, class Compare, class Allocator>
1611  struct is_map_compatible<std::map<Key, T, Compare, Allocator>>
1612  : std::true_type
1613  {};
1614  template <class Key, class T, class Compare, class Allocator>
1615  struct is_map_compatible<std::multimap<Key, T, Compare, Allocator>>
1616  : std::true_type
1617  {};
1618  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1620  std::unordered_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type
1621  {};
1622  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1624  std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>>
1625  : std::true_type
1626  {};
1627  } // namespace internal
1628 
1629  // type trait to use the implementation type traits as well as decay the
1630  // type
1631  template <typename T>
1633  {
1634  static constexpr bool const value =
1636  };
1637 
1638  template <typename T>
1640  {
1641  static constexpr bool const value =
1643  };
1644 
1645  namespace internal
1646  {
1647  // Helper function for list_rank
1648  template <class T>
1649  constexpr int
1651  {
1652  return RankInfo<T>::list_rank;
1653  }
1654 
1655  template <class T1, class T2, class... Types>
1656  constexpr int
1658  {
1659  return std::max(RankInfo<T1>::list_rank, max_list_rank<T2, Types...>());
1660  }
1661 
1662  // Helper function for map_rank
1663  template <class T>
1664  constexpr int
1666  {
1667  return RankInfo<T>::map_rank;
1668  }
1669 
1670  template <class T1, class T2, class... Types>
1671  constexpr int
1673  {
1674  return std::max(RankInfo<T1>::map_rank, max_map_rank<T2, Types...>());
1675  }
1676 
1677  // Rank of vector types
1678  template <class T>
1679  struct RankInfo<T, std::enable_if_t<is_list_compatible<T>::value>>
1680  {
1681  static constexpr int list_rank =
1683  static constexpr int map_rank =
1685  };
1686 
1687  // Rank of map types
1688  template <class T>
1689  struct RankInfo<T, std::enable_if_t<is_map_compatible<T>::value>>
1690  {
1691  static constexpr int list_rank =
1692  max_list_rank<typename T::key_type, typename T::mapped_type>() + 1;
1693  static constexpr int map_rank =
1694  max_map_rank<typename T::key_type, typename T::mapped_type>() + 1;
1695  };
1696 
1697  // Rank of Tensor types
1698  template <int rank, int dim, class Number>
1699  struct RankInfo<Tensor<rank, dim, Number>>
1700  {
1701  static constexpr int list_rank = rank + RankInfo<Number>::list_rank;
1702  static constexpr int map_rank = RankInfo<Number>::map_rank;
1703  };
1704 
1705  template <int dim, class Number>
1706  struct RankInfo<Point<dim, Number>> : RankInfo<Tensor<1, dim, Number>>
1707  {};
1708 
1709  // Rank of complex types
1710  template <class Number>
1711  struct RankInfo<std::complex<Number>>
1712  {
1713  static constexpr int list_rank = RankInfo<Number>::list_rank + 1;
1714  static constexpr int map_rank = RankInfo<Number>::map_rank;
1715  };
1716 
1717  // Rank of FunctionParser
1718  template <int dim>
1719  struct RankInfo<std::unique_ptr<FunctionParser<dim>>>
1720  {
1721  static constexpr int list_rank = 1;
1722  static constexpr int map_rank = 0;
1723  };
1724 
1725  // Rank of ComponentMask
1726  template <>
1728  {
1729  static constexpr int list_rank = 1;
1730  static constexpr int map_rank = 0;
1731  };
1732 
1733  // Rank of std::pair
1734  template <class Key, class Value>
1735  struct RankInfo<std::pair<Key, Value>>
1736  {
1737  static constexpr int list_rank =
1739  static constexpr int map_rank =
1741  };
1742 
1743  // Rank of std::tuple types
1744  template <class... Types>
1745  struct RankInfo<std::tuple<Types...>>
1746  {
1747  static constexpr int list_rank = max_list_rank<Types...>();
1748  static constexpr int map_rank = max_map_rank<Types...>() + 1;
1749  };
1750 
1751  // Rank of std::array types
1752  template <class T, std::size_t N>
1753  struct RankInfo<std::array<T, N>>
1754  {
1755  static constexpr int list_rank = RankInfo<T>::list_rank + 1;
1756  static constexpr int map_rank = RankInfo<T>::map_rank;
1757  };
1758  } // namespace internal
1759 
1760  // stl containers
1761  template <class T>
1762  struct Convert<T, std::enable_if_t<is_list_compatible<T>::value>>
1763  {
1764  static std::unique_ptr<Patterns::PatternBase>
1766  {
1767  static_assert(internal::RankInfo<T>::list_rank > 0,
1768  "Cannot use this class for non List-compatible types.");
1769  return std::make_unique<Patterns::List>(
1771  0,
1774  1]);
1775  }
1776 
1777  static std::string
1779  const T & t,
1780  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1781  {
1782  auto p = dynamic_cast<const Patterns::List *>(&pattern);
1783  AssertThrow(p,
1784  ExcMessage("I need a List pattern to convert a "
1785  "string to a List type."));
1786  auto base_p = p->get_base_pattern().clone();
1787  std::vector<std::string> vec(t.size());
1788 
1790  t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1791  return Convert<typename T::value_type>::to_string(entry, *base_p);
1792  });
1793 
1794  std::string s;
1795  if (vec.size() > 0)
1796  s = vec[0];
1797  for (unsigned int i = 1; i < vec.size(); ++i)
1798  s += p->get_separator() + " " + vec[i];
1799 
1800  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1801  return s;
1802  }
1803 
1804  static T
1805  to_value(const std::string & s,
1806  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1807  {
1808  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1809 
1810  auto p = dynamic_cast<const Patterns::List *>(&pattern);
1811  AssertThrow(p,
1812  ExcMessage("I need a List pattern to convert a string "
1813  "to a List type."));
1814 
1815  auto base_p = p->get_base_pattern().clone();
1816  T t;
1817 
1818  auto v = Utilities::split_string_list(s, p->get_separator());
1819  for (const auto &str : v)
1820  t.insert(t.end(),
1822 
1823  return t;
1824  }
1825  };
1826 
1827  // stl maps
1828  template <class T>
1829  struct Convert<T, std::enable_if_t<is_map_compatible<T>::value>>
1830  {
1831  static std::unique_ptr<Patterns::PatternBase>
1833  {
1834  static_assert(internal::RankInfo<T>::list_rank > 0,
1835  "Cannot use this class for non List-compatible types.");
1836  static_assert(internal::RankInfo<T>::map_rank > 0,
1837  "Cannot use this class for non Map-compatible types.");
1838  return std::make_unique<Patterns::Map>(
1841  0,
1844  1],
1846  }
1847 
1848  static std::string
1850  const T & t,
1851  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1852  {
1853  auto p = dynamic_cast<const Patterns::Map *>(&pattern);
1854  AssertThrow(p,
1855  ExcMessage("I need a Map pattern to convert a string to "
1856  "a Map compatible type."));
1857  auto key_p = p->get_key_pattern().clone();
1858  auto val_p = p->get_value_pattern().clone();
1859  std::vector<std::string> vec(t.size());
1860 
1861  unsigned int i = 0;
1862  for (const auto &ti : t)
1863  vec[i++] =
1864  Convert<typename T::key_type>::to_string(ti.first, *key_p) +
1865  p->get_key_value_separator() +
1867 
1868  std::string s;
1869  if (vec.size() > 0)
1870  s = vec[0];
1871  for (unsigned int i = 1; i < vec.size(); ++i)
1872  s += p->get_separator() + " " + vec[i];
1873 
1874  AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
1875  return s;
1876  }
1877 
1878  static T
1879  to_value(const std::string & s,
1880  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1881  {
1882  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1883 
1884  auto p = dynamic_cast<const Patterns::Map *>(&pattern);
1885  AssertThrow(p,
1886  ExcMessage("I need a Map pattern to convert a "
1887  "string to a Map compatible type."));
1888 
1889  auto key_p = p->get_key_pattern().clone();
1890  auto val_p = p->get_value_pattern().clone();
1891  T t;
1892 
1893  auto v = Utilities::split_string_list(s, p->get_separator());
1894  for (const auto &str : v)
1895  {
1896  auto key_val =
1897  Utilities::split_string_list(str, p->get_key_value_separator());
1898  AssertDimension(key_val.size(), 2);
1899  t.insert(std::make_pair(
1900  Convert<typename T::key_type>::to_value(key_val[0], *key_p),
1901  Convert<typename T::mapped_type>::to_value(key_val[1], *val_p)));
1902  }
1903 
1904  return t;
1905  }
1906  };
1907 
1908  // std::array
1909  template <class ValueType, std::size_t N>
1910  struct Convert<std::array<ValueType, N>>
1911  {
1912  using T = std::array<ValueType, N>;
1913 
1914  static std::unique_ptr<Patterns::PatternBase>
1916  {
1917  static_assert(internal::RankInfo<T>::list_rank > 0,
1918  "Cannot use this class for non List-compatible types.");
1919  return std::make_unique<Patterns::List>(
1921  N,
1922  N,
1924  1]);
1925  }
1926 
1927  static std::string
1929  const T & t,
1930  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1931  {
1932  auto p = dynamic_cast<const Patterns::List *>(&pattern);
1933  AssertThrow(p,
1934  ExcMessage("I need a List pattern to convert a "
1935  "string to a std::array."));
1936  auto base_p = p->get_base_pattern().clone();
1937  std::vector<std::string> vec(t.size());
1938 
1940  t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1941  return Convert<typename T::value_type>::to_string(entry, *base_p);
1942  });
1943 
1944  std::string s;
1945  if (vec.size() > 0)
1946  s = vec[0];
1947  for (unsigned int i = 1; i < vec.size(); ++i)
1948  s += p->get_separator() + " " + vec[i];
1949 
1950  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1951  return s;
1952  }
1953 
1954  static T
1955  to_value(const std::string & s,
1956  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1957  {
1958  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1959 
1960  auto p = dynamic_cast<const Patterns::List *>(&pattern);
1961  AssertThrow(p,
1962  ExcMessage("I need a List pattern to convert a string "
1963  "to a std::array."));
1964 
1965  auto base_p = p->get_base_pattern().clone();
1966  T t;
1967 
1968  auto v = Utilities::split_string_list(s, p->get_separator());
1969  AssertDimension(v.size(), N);
1970  for (unsigned int i = 0; i < N; ++i)
1971  t[i] = Convert<typename T::value_type>::to_value(v[i], *base_p);
1972  return t;
1973  }
1974  };
1975 
1976  // Tensors
1977  template <int rank, int dim, class Number>
1978  struct Convert<Tensor<rank, dim, Number>>
1979  {
1981  static std::unique_ptr<Patterns::PatternBase>
1983  {
1984  static_assert(internal::RankInfo<T>::list_rank > 0,
1985  "Cannot use this class for non List-compatible types.");
1986  return std::make_unique<Patterns::List>(
1988  dim,
1989  dim,
1991  1]);
1992  }
1993 
1994  static std::string
1996  const T & t,
1997  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1998  {
1999  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2000  AssertThrow(p,
2001  ExcMessage("I need a List pattern to convert a string "
2002  "to a List compatible type."));
2003  auto base_p = p->get_base_pattern().clone();
2004  std::vector<std::string> vec(dim);
2005 
2006  for (unsigned int i = 0; i < dim; ++i)
2007  vec[i] = Convert<typename T::value_type>::to_string(t[i], *base_p);
2008 
2009  std::string s;
2010  if (vec.size() > 0)
2011  s = vec[0];
2012  for (unsigned int i = 1; i < vec.size(); ++i)
2013  s += p->get_separator() + " " + vec[i];
2014 
2015  AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
2016  return s;
2017  }
2018 
2019  static T
2020  to_value(const std::string & s,
2021  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2022  {
2023  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2024 
2025  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2026  AssertThrow(p,
2027  ExcMessage("I need a List pattern to convert a string "
2028  "to a List compatible type."));
2029 
2030  auto base_p = p->get_base_pattern().clone();
2031  T t;
2032 
2033  auto v = Utilities::split_string_list(s, p->get_separator());
2034  unsigned int i = 0;
2035  for (const auto &str : v)
2036  t[i++] = Convert<typename T::value_type>::to_value(str, *base_p);
2037 
2038  return t;
2039  }
2040  };
2041 
2042  // Points
2043  template <int dim, class Number>
2044  struct Convert<Point<dim, Number>>
2045  {
2047 
2048  static std::unique_ptr<Patterns::PatternBase>
2050  {
2052  }
2053 
2054  static std::string
2056  const T & t,
2057  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2058  {
2060  Tensor<1, dim, Number>(t), pattern);
2061  }
2062 
2063  static T
2064  to_value(const std::string & s,
2065  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2066  {
2067  return T(Convert<Tensor<1, dim, Number>>::to_value(s, pattern));
2068  }
2069  };
2070 
2071  // Functions::FunctionParser
2072  template <int dim>
2073  struct Convert<std::unique_ptr<FunctionParser<dim>>>
2074  {
2075  using T = std::unique_ptr<FunctionParser<dim>>;
2076 
2077  static std::unique_ptr<Patterns::PatternBase>
2079  {
2080  static_assert(internal::RankInfo<T>::list_rank > 0,
2081  "Cannot use this class for non List-compatible types.");
2082 
2083  return std::make_unique<Patterns::List>(
2085  1,
2088  1]);
2089  }
2090 
2091  static std::string
2093  const T & t,
2094  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2095  {
2096  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2097  AssertThrow(p,
2098  ExcMessage("I need a List pattern to convert a string "
2099  "to a List compatible type."));
2100 
2101  const auto &expressions = t->get_expressions();
2102  if (expressions.size() == 0)
2103  return std::string();
2104 
2105  std::string s = expressions[0];
2106  for (unsigned int i = 1; i < expressions.size(); ++i)
2107  s = s + p->get_separator() + expressions[i];
2108 
2109  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2110  return s;
2111  }
2112 
2113  static T
2114  to_value(const std::string & s,
2115  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2116  {
2117  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2118 
2119  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2120  AssertThrow(p,
2121  ExcMessage("I need a List pattern to convert a string "
2122  "to a List compatible type."));
2123 
2124  const auto expressions =
2125  Utilities::split_string_list(s, p->get_separator());
2126 
2127  T t = std::make_unique<FunctionParser<dim>>(expressions.size());
2128  const std::string var =
2130  const typename FunctionParser<dim>::ConstMap constants;
2131  t->initialize(var, expressions, constants, true);
2132  return t;
2133  }
2134  };
2135 
2136  // ComponentMask
2137  template <>
2139  {
2140  using T = ComponentMask;
2141 
2142  static std::unique_ptr<Patterns::PatternBase>
2144  {
2146  }
2147 
2148  static std::string
2150  const T & t,
2151  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2152  {
2153  std::vector<bool> mask(t.size());
2154  for (unsigned int i = 0; i < t.size(); ++i)
2155  mask[i] = t[i];
2156 
2157  return Convert<std::vector<bool>>::to_string(mask, pattern);
2158  }
2159 
2160  static T
2161  to_value(const std::string & s,
2162  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2163  {
2164  const auto mask = Convert<std::vector<bool>>::to_value(s, pattern);
2165  return ComponentMask(mask);
2166  }
2167  };
2168 
2169  // Complex numbers
2170  template <class Number>
2171  struct Convert<std::complex<Number>>
2172  {
2173  using T = std::complex<Number>;
2174 
2175  static std::unique_ptr<Patterns::PatternBase>
2177  {
2178  static_assert(internal::RankInfo<T>::list_rank > 0,
2179  "Cannot use this class for non List-compatible types.");
2180  return std::make_unique<Patterns::List>(
2182  2,
2183  2,
2185  1]);
2186  }
2187 
2188  static std::string
2190  const T & t,
2191  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2192  {
2193  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2194  AssertThrow(p,
2195  ExcMessage("I need a List pattern to convert a string "
2196  "to a List compatible type."));
2197 
2198  auto base_p = p->get_base_pattern().clone();
2199  std::string s =
2200  Convert<typename T::value_type>::to_string(t.real(), *base_p) +
2201  p->get_separator() + " " +
2202  Convert<typename T::value_type>::to_string(t.imag(), *base_p);
2203 
2204  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2205  return s;
2206  }
2207 
2211  static T
2212  to_value(const std::string & s,
2213  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2214  {
2215  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2216 
2217  auto p = dynamic_cast<const Patterns::List *>(&pattern);
2218  AssertThrow(p,
2219  ExcMessage("I need a List pattern to convert a string "
2220  "to a List compatible type."));
2221 
2222  auto base_p = p->get_base_pattern().clone();
2223 
2224  auto v = Utilities::split_string_list(s, p->get_separator());
2225  AssertDimension(v.size(), 2);
2228  return t;
2229  }
2230  };
2231 
2232  // Strings
2233  template <>
2234  struct Convert<std::string>
2235  {
2236  using T = std::string;
2237 
2238  static std::unique_ptr<Patterns::PatternBase>
2240  {
2241  return std::make_unique<Patterns::Anything>();
2242  }
2243 
2244  static std::string
2246  const T & t,
2247  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2248  {
2249  AssertThrow(pattern.match(t), ExcNoMatch(t, pattern.description()));
2250  return t;
2251  }
2252 
2253  static T
2254  to_value(const std::string & s,
2255  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2256  {
2257  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2258  return s;
2259  }
2260  };
2261 
2262  // Pairs
2263  template <class Key, class Value>
2264  struct Convert<std::pair<Key, Value>>
2265  {
2266  using T = std::pair<Key, Value>;
2267 
2268  static std::unique_ptr<Patterns::PatternBase>
2270  {
2271  static_assert(internal::RankInfo<T>::map_rank > 0,
2272  "Cannot use this class for non Map-compatible types.");
2273  return std::make_unique<Patterns::Tuple>(
2277  }
2278 
2279  static std::string
2281  const T & t,
2282  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2283  {
2284  std::tuple<Key, Value> m(t);
2285  std::string s = Convert<decltype(m)>::to_string(m, pattern);
2286  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2287  return s;
2288  }
2289 
2290  static T
2291  to_value(const std::string & s,
2292  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2293  {
2294  std::tuple<Key, Value> m;
2295  m = Convert<decltype(m)>::to_value(s, pattern);
2296  return std::make_pair(std::get<0>(m), std::get<1>(m));
2297  }
2298  };
2299 
2300  // Tuples
2301  template <class... Args>
2302  struct Convert<std::tuple<Args...>>
2303  {
2304  using T = std::tuple<Args...>;
2305 
2306  static std::unique_ptr<Patterns::PatternBase>
2308  {
2309  static_assert(internal::RankInfo<T>::map_rank > 0,
2310  "Cannot use this class for non tuple-compatible types.");
2311  return std::make_unique<Patterns::Tuple>(
2314  }
2315 
2316  static std::string
2318  const T & t,
2319  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2320  {
2321  auto p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2322  AssertThrow(p,
2323  ExcMessage("I need a Tuple pattern to convert a tuple "
2324  "to a string."));
2325 
2326  const auto string_array = Convert<T>::to_string_internal_2(t, *p);
2327  std::string str;
2328  for (unsigned int i = 0; i < string_array.size(); ++i)
2329  str +=
2330  (i != 0u ? " " + p->get_separator() + " " : "") + string_array[i];
2331  AssertThrow(p->match(str), ExcNoMatch(str, p->description()));
2332  return str;
2333  }
2334 
2335  static T
2336  to_value(const std::string & s,
2337  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2338  {
2339  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2340 
2341  auto p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2342  AssertThrow(p,
2343  ExcMessage("I need a Tuple pattern to convert a string "
2344  "to a tuple type."));
2345 
2346  auto v = Utilities::split_string_list(s, p->get_separator());
2347 
2348  return Convert<T>::to_value_internal_2(v, *p);
2349  }
2350 
2351  private:
2352  template <std::size_t... U>
2353  static std::array<std::string, std::tuple_size<T>::value>
2355  const Patterns::Tuple &pattern,
2356  std::index_sequence<U...>)
2357  {
2358  std::array<std::string, std::tuple_size<T>::value> a = {
2360  std::get<U>(t), pattern.get_pattern(U))...}};
2361  return a;
2362  }
2363 
2364  static std::array<std::string, std::tuple_size<T>::value>
2365  to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
2366  {
2368  t, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2369  }
2370 
2371  template <std::size_t... U>
2372  static T
2373  to_value_internal_1(const std::vector<std::string> &s,
2374  const Patterns::Tuple & pattern,
2375  std::index_sequence<U...>)
2376  {
2377  return std::make_tuple(
2378  Convert<typename std::tuple_element<U, T>::type>::to_value(
2379  s[U], pattern.get_pattern(U))...);
2380  }
2381 
2382  static T
2383  to_value_internal_2(const std::vector<std::string> &s,
2384  const Patterns::Tuple & pattern)
2385  {
2387  s, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2388  }
2389  };
2390 
2391  // Utility function with default Pattern
2392  template <typename T>
2393  std::string
2394  to_string(const T &t)
2395  {
2396  return Convert<T>::to_string(t);
2397  }
2398 
2399  // Utility function with default Pattern
2400  template <typename T>
2401  void
2402  to_value(const std::string &s, T &t)
2403  {
2404  t = Convert<T>::to_value(s);
2405  }
2406  } // namespace Tools
2407 } // namespace Patterns
2408 
2409 
2411 
2412 #endif
unsigned int size() const
std::map< std::string, double > ConstMap
static std::string default_variable_names()
static std::unique_ptr< Anything > create(const std::string &description)
Definition: patterns.cc:1496
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1452
static const char * description_init
Definition: patterns.h:1066
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1460
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1488
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1399
static const char * description_init
Definition: patterns.h:1017
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1427
static std::unique_ptr< Bool > create(const std::string &description)
Definition: patterns.cc:1435
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1638
static const char * description_init
Definition: patterns.h:1206
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1610
static std::unique_ptr< DirectoryName > create(const std::string &description)
Definition: patterns.cc:1646
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1602
static std::unique_ptr< Double > create(const std::string &description)
Definition: patterns.cc:491
static const char * description_init
Definition: patterns.h:371
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:483
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
Definition: patterns.cc:352
const double lower_bound
Definition: patterns.h:358
const double upper_bound
Definition: patterns.h:366
static const double max_double_value
Definition: patterns.h:306
static const double min_double_value
Definition: patterns.h:300
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:383
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:360
FileType file_type
Definition: patterns.h:1134
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1518
FileName(const FileType type=input)
Definition: patterns.cc:1511
static const char * description_init
Definition: patterns.h:1148
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1562
static std::unique_ptr< FileName > create(const std::string &description)
Definition: patterns.cc:1570
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1526
static std::unique_ptr< Integer > create(const std::string &description)
Definition: patterns.cc:312
static const char * description_init
Definition: patterns.h:273
const int upper_bound
Definition: patterns.h:268
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:304
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
Definition: patterns.cc:213
const int lower_bound
Definition: patterns.h:260
static const int min_int_value
Definition: patterns.h:198
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:243
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:221
static const int max_int_value
Definition: patterns.h:205
const unsigned int max_elements
Definition: patterns.h:557
static const char * description_init
Definition: patterns.h:567
const unsigned int min_elements
Definition: patterns.h:552
std::unique_ptr< PatternBase > pattern
Definition: patterns.h:547
const std::string separator
Definition: patterns.h:562
std::size_t memory_consumption() const override
Definition: patterns.cc:768
static std::unique_ptr< List > create(const std::string &description)
Definition: patterns.cc:777
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:716
const PatternBase & get_base_pattern() const
Definition: patterns.cc:688
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:696
const std::string & get_separator() const
Definition: patterns.cc:680
List(const PatternBase &base_pattern, const unsigned int min_elements=0, const unsigned int max_elements=max_int_value, const std::string &separator=",")
Definition: patterns.cc:654
static const unsigned int max_int_value
Definition: patterns.h:459
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:760
static std::unique_ptr< Map > create(const std::string &description)
Definition: patterns.cc:969
std::unique_ptr< PatternBase > value_pattern
Definition: patterns.h:696
const unsigned int min_elements
Definition: patterns.h:701
const PatternBase & get_key_pattern() const
Definition: patterns.cc:1024
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:865
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=":")
Definition: patterns.cc:825
const unsigned int max_elements
Definition: patterns.h:706
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:945
const PatternBase & get_value_pattern() const
Definition: patterns.cc:1032
const std::string & get_separator() const
Definition: patterns.cc:1040
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:895
static const unsigned int max_int_value
Definition: patterns.h:593
std::unique_ptr< PatternBase > key_pattern
Definition: patterns.h:695
const std::string separator
Definition: patterns.h:711
std::size_t memory_consumption() const override
Definition: patterns.cc:957
static const char * description_init
Definition: patterns.h:722
const std::string & get_key_value_separator() const
Definition: patterns.cc:1047
const std::string key_value_separator
Definition: patterns.h:717
MultipleSelection(const std::string &seq)
Definition: patterns.cc:1241
static std::unique_ptr< MultipleSelection > create(const std::string &description)
Definition: patterns.cc:1370
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1256
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1354
static const char * description_init
Definition: patterns.h:975
std::size_t memory_consumption() const override
Definition: patterns.cc:1361
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1319
virtual std::size_t memory_consumption() const
Definition: patterns.cc:192
virtual std::string description(const OutputStyle style=Machine) const =0
virtual std::unique_ptr< PatternBase > clone() const =0
virtual bool match(const std::string &test_string) const =0
virtual ~PatternBase()=default
static const char * description_init
Definition: patterns.h:440
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:578
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:613
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:546
static std::unique_ptr< Selection > create(const std::string &description)
Definition: patterns.cc:629
std::size_t memory_consumption() const override
Definition: patterns.cc:620
Selection(const std::string &seq)
Definition: patterns.cc:534
std::string sequence
Definition: patterns.h:435
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1090
Tuple(const std::vector< std::unique_ptr< PatternBase >> &patterns, const std::string &separator=":")
Definition: patterns.cc:1057
std::size_t memory_consumption() const override
Definition: patterns.cc:1166
static std::unique_ptr< Tuple > create(const std::string &description)
Definition: patterns.cc:1175
std::vector< std::unique_ptr< PatternBase > > patterns
Definition: patterns.h:881
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1159
Tuple(const Patterns &...patterns)
const std::string separator
Definition: patterns.h:886
static const char * description_init
Definition: patterns.h:891
const std::string & get_separator() const
Definition: patterns.cc:1231
const PatternBase & get_pattern(const unsigned int i) const
Definition: patterns.cc:1223
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1109
Definition: point.h:111
Definition: tensor.h:503
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:457
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition: config.h:471
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:458
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition: config.h:510
__global__ void set(Number *val, const Number s, const size_type N)
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static ::ExceptionBase & ExcNoMatch(std::string arg1, std::string arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:532
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1695
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:509
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1611
static const char U
static const char T
static const char N
constexpr std::array< const char *, 4 > default_map_separator
Definition: patterns.h:1577
constexpr int max_map_rank()
Definition: patterns.h:1665
constexpr int max_list_rank()
Definition: patterns.h:1650
constexpr std::array< const char *, 4 > default_list_separator
Definition: patterns.h:1575
void to_value(const std::string &s, T &t)
Definition: patterns.h:2402
std::string to_string(const T &t)
Definition: patterns.h:2394
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
Definition: patterns.cc:55
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
Definition: patterns.cc:140
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition: utilities.cc:704
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Predicate &predicate, const unsigned int grainsize)
Definition: parallel.h:135
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2161
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2149
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2143
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2049
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2055
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2064
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1765
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1805
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1778
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1849
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1832
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1879
static std::enable_if_t< std::is_same< Dummy, T >::value &&std::is_same< T, bool >::value, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1492
static std::enable_if_t< std::is_same< Dummy, T >::value &&!std::is_same< T, bool >::value &&std::is_floating_point< T >::value, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1513
static std::string to_string(const T &value, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition: patterns.h:1520
static std::enable_if_t< std::is_same< Dummy, T >::value &&!std::is_same< T, bool >::value &&std::is_integral< T >::value, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1502
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition: patterns.h:1536
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2020
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1982
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1995
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1955
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1928
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1915
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2176
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2212
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2189
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2269
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2291
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2280
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2254
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2239
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2245
static T to_value_internal_2(const std::vector< std::string > &s, const Patterns::Tuple &pattern)
Definition: patterns.h:2383
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2336
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2307
static std::array< std::string, std::tuple_size< T >::value > to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
Definition: patterns.h:2365
static std::array< std::string, std::tuple_size< T >::value > to_string_internal_1(const T &t, const Patterns::Tuple &pattern, std::index_sequence< U... >)
Definition: patterns.h:2354
static T to_value_internal_1(const std::vector< std::string > &s, const Patterns::Tuple &pattern, std::index_sequence< U... >)
Definition: patterns.h:2373
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2317
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2114
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2078
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2092
static std::unique_ptr< Patterns::PatternBase > to_pattern()=delete
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
static std::string to_string(const T &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
static constexpr int list_rank
Definition: patterns.h:1479
static constexpr int map_rank
Definition: patterns.h:1480
static constexpr bool const value
Definition: patterns.h:1634
static constexpr bool const value
Definition: patterns.h:1641