Reference documentation for deal.II version GIT 7b2de2f2f9 2023-09-24 11:00: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 - 2023 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 
30 #include <boost/archive/basic_archive.hpp>
31 #include <boost/core/demangle.hpp>
32 #include <boost/property_tree/ptree_fwd.hpp>
33 #include <boost/property_tree/ptree_serialization.hpp>
34 #include <boost/serialization/split_member.hpp>
35 
36 #include <algorithm>
37 #include <array>
38 #include <deque>
39 #include <limits>
40 #include <list>
41 #include <map>
42 #include <memory>
43 #include <set>
44 #include <sstream>
45 #include <string>
46 #include <type_traits>
47 #include <unordered_map>
48 #include <unordered_set>
49 #include <utility>
50 #include <vector>
51 
53 
54 // forward declarations for interfaces and friendship
55 #ifndef DOXYGEN
56 class LogStream;
58 template <int dim>
59 class FunctionParser;
60 #endif
61 
70 namespace Patterns
71 {
79  {
80  public:
84  virtual ~PatternBase() = default;
85 
89  virtual bool
90  match(const std::string &test_string) const = 0;
91 
98  {
114  LaTeX
115  };
116 
120  virtual std::string
121  description(const OutputStyle style = Machine) const = 0;
122 
132  virtual std::unique_ptr<PatternBase>
133  clone() const = 0;
134 
150  virtual std::size_t
151  memory_consumption() const;
152  };
153 
157  std::unique_ptr<PatternBase>
158  pattern_factory(const std::string &description);
159 
160  namespace internal
161  {
167  std::string
168  escape(const std::string &input, const PatternBase::OutputStyle style);
169 
170  } // namespace internal
171 
188  class Integer : public PatternBase
189  {
190  public:
196  static const int min_int_value;
197 
203  static const int max_int_value;
204 
217  Integer(const int lower_bound = min_int_value,
218  const int upper_bound = max_int_value);
219 
224  virtual bool
225  match(const std::string &test_string) const override;
226 
232  virtual std::string
233  description(const OutputStyle style = Machine) const override;
234 
240  virtual std::unique_ptr<PatternBase>
241  clone() const override;
242 
248  static std::unique_ptr<Integer>
249  create(const std::string &description);
250 
251  private:
258  const int lower_bound;
259 
266  const int upper_bound;
267 
271  static const char *description_init;
272  };
273 
291  class Double : public PatternBase
292  {
293  public:
298  static const double min_double_value;
299 
304  static const double max_double_value;
305 
313  Double(const double lower_bound = min_double_value,
314  const double upper_bound = max_double_value);
315 
320  virtual bool
321  match(const std::string &test_string) const override;
322 
328  virtual std::string
329  description(const OutputStyle style = Machine) const override;
330 
336  virtual std::unique_ptr<PatternBase>
337  clone() const override;
338 
346  static std::unique_ptr<Double>
347  create(const std::string &description);
348 
349  private:
356  const double lower_bound;
357 
364  const double upper_bound;
365 
369  static const char *description_init;
370  };
371 
381  class Selection : public PatternBase
382  {
383  public:
388  Selection(const std::string &seq);
389 
394  virtual bool
395  match(const std::string &test_string) const override;
396 
402  virtual std::string
403  description(const OutputStyle style = Machine) const override;
404 
410  virtual std::unique_ptr<PatternBase>
411  clone() const override;
412 
417  std::size_t
418  memory_consumption() const override;
419 
425  static std::unique_ptr<Selection>
426  create(const std::string &description);
427 
428  private:
433  std::string sequence;
434 
438  static const char *description_init;
439  };
440 
441 
449  class List : public PatternBase
450  {
451  public:
457  static const unsigned int max_int_value;
458 
467  List(const PatternBase &base_pattern,
468  const unsigned int min_elements = 0,
469  const unsigned int max_elements = max_int_value,
470  const std::string &separator = ",");
471 
472 
476  const std::string &
477  get_separator() const;
478 
482  const PatternBase &
483  get_base_pattern() const;
484 
488  List(const List &other);
489 
494  virtual bool
495  match(const std::string &test_string) const override;
496 
501  virtual std::string
502  description(const OutputStyle style = Machine) const override;
503 
509  virtual std::unique_ptr<PatternBase>
510  clone() const override;
511 
517  static std::unique_ptr<List>
518  create(const std::string &description);
519 
524  std::size_t
525  memory_consumption() const override;
526 
536  int,
537  int,
538  << "The values " << arg1 << " and " << arg2
539  << " do not form a valid range.");
541  private:
545  std::unique_ptr<PatternBase> pattern;
546 
550  const unsigned int min_elements;
551 
555  const unsigned int max_elements;
556 
560  const std::string separator;
561 
565  static const char *description_init;
566  };
567 
568 
583  class Map : public PatternBase
584  {
585  public:
591  static const unsigned int max_int_value;
592 
601  Map(const PatternBase &key_pattern,
602  const PatternBase &value_pattern,
603  const unsigned int min_elements = 0,
604  const unsigned int max_elements = max_int_value,
605  const std::string &separator = ",",
606  const std::string &key_value_separator = ":");
607 
611  Map(const Map &other);
612 
617  virtual bool
618  match(const std::string &test_string) const override;
619 
624  virtual std::string
625  description(const OutputStyle style = Machine) const override;
626 
632  virtual std::unique_ptr<PatternBase>
633  clone() const override;
634 
640  static std::unique_ptr<Map>
641  create(const std::string &description);
642 
647  std::size_t
648  memory_consumption() const override;
649 
653  const PatternBase &
654  get_key_pattern() const;
655 
659  const PatternBase &
660  get_value_pattern() const;
661 
665  const std::string &
666  get_separator() const;
667 
671  const std::string &
672  get_key_value_separator() const;
673 
683  int,
684  int,
685  << "The values " << arg1 << " and " << arg2
686  << " do not form a valid range.");
688  private:
693  std::unique_ptr<PatternBase> key_pattern;
694  std::unique_ptr<PatternBase> value_pattern;
695 
699  const unsigned int min_elements;
700 
704  const unsigned int max_elements;
705 
709  const std::string separator;
710 
711 
715  const std::string key_value_separator;
716 
720  static const char *description_init;
721  };
722 
723 
724 
770  class Tuple : public PatternBase
771  {
772  public:
781  Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
782  const std::string &separator = ":");
783 
789  Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
790  const char *separator);
791 
792 
800  template <class... PatternTypes>
801  Tuple(const std::string &separator, const PatternTypes &...patterns);
802 
810  template <class... PatternTypes>
811  Tuple(const char *separator, const PatternTypes &...patterns);
812 
818  template <typename... Patterns>
819  Tuple(const Patterns &...patterns);
820 
824  Tuple(const Tuple &other);
825 
830  virtual bool
831  match(const std::string &test_string) const override;
832 
837  virtual std::string
838  description(const OutputStyle style = Machine) const override;
839 
845  virtual std::unique_ptr<PatternBase>
846  clone() const override;
847 
853  static std::unique_ptr<Tuple>
854  create(const std::string &description);
855 
860  std::size_t
861  memory_consumption() const override;
862 
866  const PatternBase &
867  get_pattern(const unsigned int i) const;
868 
872  const std::string &
873  get_separator() const;
874 
875  private:
879  std::vector<std::unique_ptr<PatternBase>> patterns;
880 
884  const std::string separator;
885 
889  static const char *description_init;
890  };
891 
892 
904  {
905  public:
909  MultipleSelection(const std::string &seq);
910 
915  virtual bool
916  match(const std::string &test_string) const override;
917 
923  virtual std::string
924  description(const OutputStyle style = Machine) const override;
925 
931  virtual std::unique_ptr<PatternBase>
932  clone() const override;
933 
939  static std::unique_ptr<MultipleSelection>
940  create(const std::string &description);
941 
946  std::size_t
947  memory_consumption() const override;
948 
959  int,
960  << "A comma was found at position " << arg1
961  << " of your input string, but commas are not allowed here.");
963  private:
968  std::string sequence;
969 
973  static const char *description_init;
974  };
975 
980  class Bool : public Selection
981  {
982  public:
986  Bool();
987 
992  virtual std::string
993  description(const OutputStyle style = Machine) const override;
994 
1000  virtual std::unique_ptr<PatternBase>
1001  clone() const override;
1002 
1008  static std::unique_ptr<Bool>
1009  create(const std::string &description);
1010 
1011  private:
1015  static const char *description_init;
1016  };
1017 
1021  class Anything : public PatternBase
1022  {
1023  public:
1028  Anything() = default;
1029 
1034  virtual bool
1035  match(const std::string &test_string) const override;
1036 
1041  virtual std::string
1042  description(const OutputStyle style = Machine) const override;
1043 
1049  virtual std::unique_ptr<PatternBase>
1050  clone() const override;
1051 
1057  static std::unique_ptr<Anything>
1058  create(const std::string &description);
1059 
1060  private:
1064  static const char *description_init;
1065  };
1066 
1067 
1082  class FileName : public PatternBase
1083  {
1084  public:
1090  {
1094  input = 0,
1098  output = 1
1099  };
1100 
1105  FileName(const FileType type = input);
1106 
1111  virtual bool
1112  match(const std::string &test_string) const override;
1113 
1118  virtual std::string
1119  description(const OutputStyle style = Machine) const override;
1120 
1126  virtual std::unique_ptr<PatternBase>
1127  clone() const override;
1128 
1133 
1139  static std::unique_ptr<FileName>
1140  create(const std::string &description);
1141 
1142  private:
1146  static const char *description_init;
1147  };
1148 
1149 
1163  {
1164  public:
1168  DirectoryName() = default;
1169 
1174  virtual bool
1175  match(const std::string &test_string) const override;
1176 
1181  virtual std::string
1182  description(const OutputStyle style = Machine) const override;
1183 
1189  virtual std::unique_ptr<PatternBase>
1190  clone() const override;
1191 
1197  static std::unique_ptr<DirectoryName>
1198  create(const std::string &description);
1199 
1200  private:
1204  static const char *description_init;
1205  };
1206 
1207 
1286  namespace Tools
1287  {
1297  template <class T, class Enable = void>
1298  struct Convert
1299  {
1309  static std::unique_ptr<Patterns::PatternBase>
1310  to_pattern() = delete;
1311 
1322  static std::string
1323  to_string(const T &s,
1325  delete;
1326 
1336  static T
1337  to_value(const std::string &s,
1339  delete;
1340  };
1341 
1360  template <typename T>
1361  std::string
1362  to_string(const T &t);
1363 
1389  template <typename T>
1390  void
1391  to_value(const std::string &s, T &t);
1392 
1402  std::string,
1403  std::string,
1404  << "The string \"" << arg1
1405  << "\" does not match the pattern \"" << arg2 << "\"");
1407  } // namespace Tools
1408 } // namespace Patterns
1409 
1410 
1411 // ---------------------- inline and template functions --------------------
1412 namespace Patterns
1413 {
1414  template <class... PatternTypes>
1415  Tuple::Tuple(const char *separator, const PatternTypes &...ps)
1416  : // forward to the version with std::string argument
1417  Tuple(std::string(separator), ps...)
1418  {}
1419 
1420 
1421 
1422  template <class... PatternTypes>
1423  Tuple::Tuple(const std::string &separator, const PatternTypes &...ps)
1424  : separator(separator)
1425  {
1427  "Not all of the input arguments of this function "
1428  "are derived from PatternBase");
1429  static_assert(sizeof...(ps) > 0,
1430  "The number of PatternTypes must be greater than zero!");
1431  const auto pattern_pointers = {(static_cast<const PatternBase *>(&ps))...};
1432  for (const auto p : pattern_pointers)
1433  patterns.push_back(p->clone());
1434  }
1435 
1436 
1437 
1438  template <class... PatternTypes>
1439  Tuple::Tuple(const PatternTypes &...ps)
1440  : // forward to the version with the separator argument
1441  Tuple(std::string(":"), ps...)
1442  {}
1443 
1444 
1445 
1446  namespace Tools
1447  {
1448  namespace internal
1449  {
1474  template <class T, class Enable = void>
1475  struct RankInfo
1476  {
1477  static constexpr int list_rank = 0;
1478  static constexpr int map_rank = 0;
1479  };
1480  } // namespace internal
1481 
1482  // Arithmetic types
1483  template <class T>
1484  struct Convert<T, std::enable_if_t<std::is_arithmetic_v<T>>>
1485  {
1486  template <typename Dummy = T>
1487  static std::enable_if_t<std::is_same_v<Dummy, T> &&
1488  std::is_same_v<T, bool>,
1489  std::unique_ptr<Patterns::PatternBase>>
1491  {
1492  return std::make_unique<Patterns::Bool>();
1493  }
1494 
1495  template <typename Dummy = T>
1496  static std::enable_if_t<std::is_same_v<Dummy, T> &&
1497  !std::is_same_v<T, bool> &&
1498  std::is_integral_v<T>,
1499  std::unique_ptr<Patterns::PatternBase>>
1501  {
1502  return std::make_unique<Patterns::Integer>(
1503  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1504  }
1505 
1506  template <typename Dummy = T>
1507  static std::enable_if_t<std::is_same_v<Dummy, T> &&
1508  !std::is_same_v<T, bool> &&
1509  std::is_floating_point_v<T>,
1510  std::unique_ptr<Patterns::PatternBase>>
1512  {
1513  return std::make_unique<Patterns::Double>(
1514  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1515  }
1516 
1517  static std::string
1518  to_string(const T &value,
1520  {
1521  std::stringstream str;
1522  if (std::is_same_v<T, unsigned char> ||
1523  std::is_same_v<T, signed char> || std::is_same_v<T, char>)
1524  str << static_cast<int>(value);
1525  else if (std::is_same_v<T, bool>)
1526  str << (static_cast<bool>(value) ? "true" : "false");
1527  else
1528  str << value;
1529  AssertThrow(p.match(str.str()), ExcNoMatch(str.str(), p.description()));
1530  return str.str();
1531  }
1532 
1533  static T
1534  to_value(const std::string &s,
1536  {
1537  AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
1538  T value;
1539  if (std::is_same_v<T, bool>)
1540  value = (s == "true");
1541  else
1542  {
1543  std::istringstream is(s);
1544  if (std::is_same_v<T, unsigned char> ||
1545  std::is_same_v<T, signed char> || std::is_same_v<T, char>)
1546  {
1547  int i;
1548  is >> i;
1549  value = i;
1550  }
1551  else
1552  is >> value;
1553 
1554  // If someone passes "123 abc" to the function, the method yields an
1555  // integer 123 alright, but the space terminates the read from the
1556  // string although there is more to come. This case, however, is
1557  // checked for in the call p->match(s) at the beginning of this
1558  // function, and would throw earlier. Here it is safe to assume that
1559  // if we didn't fail the conversion with the operator >>, then we
1560  // are good to go.
1561  AssertThrow(
1562  !is.fail(),
1563  ExcMessage("Failed to convert from \"" + s + "\" to the type \"" +
1564  boost::core::demangle(typeid(T).name()) + "\""));
1565  }
1566  return value;
1567  }
1568  };
1569 
1570  namespace internal
1571  {
1572  constexpr std::array<const char *, 4> default_list_separator{
1573  {",", ";", "|", "%"}};
1574  constexpr std::array<const char *, 4> default_map_separator{
1575  {":", "=", "@", "#"}};
1576 
1577  // specialize a type for all of the STL containers and maps
1578  template <typename T>
1579  struct is_list_compatible : std::false_type
1580  {};
1581  template <typename... Args>
1582  struct is_list_compatible<std::vector<Args...>> : std::true_type
1583  {};
1584  template <typename... Args>
1585  struct is_list_compatible<std::deque<Args...>> : std::true_type
1586  {};
1587  template <typename... Args>
1588  struct is_list_compatible<std::list<Args...>> : std::true_type
1589  {};
1590  template <typename... Args>
1591  struct is_list_compatible<std::set<Args...>> : std::true_type
1592  {};
1593  template <typename... Args>
1594  struct is_list_compatible<std::multiset<Args...>> : std::true_type
1595  {};
1596  template <typename... Args>
1597  struct is_list_compatible<std::unordered_set<Args...>> : std::true_type
1598  {};
1599  template <typename... Args>
1600  struct is_list_compatible<std::unordered_multiset<Args...>>
1601  : std::true_type
1602  {};
1603 
1604  template <typename T>
1605  struct is_map_compatible : std::false_type
1606  {};
1607  template <class Key, class T, class Compare, class Allocator>
1608  struct is_map_compatible<std::map<Key, T, Compare, Allocator>>
1609  : std::true_type
1610  {};
1611  template <class Key, class T, class Compare, class Allocator>
1612  struct is_map_compatible<std::multimap<Key, T, Compare, Allocator>>
1613  : std::true_type
1614  {};
1615  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1617  std::unordered_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type
1618  {};
1619  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1621  std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>>
1622  : std::true_type
1623  {};
1624  } // namespace internal
1625 
1626  // type trait to use the implementation type traits as well as decay the
1627  // type
1628  template <typename T>
1630  {
1631  static constexpr const bool value =
1633  };
1634 
1635  template <typename T>
1637  {
1638  static constexpr const bool value =
1640  };
1641 
1642  namespace internal
1643  {
1644  // Helper function for list_rank
1645  template <class T>
1646  constexpr int
1648  {
1649  return RankInfo<T>::list_rank;
1650  }
1651 
1652  template <class T1, class T2, class... Types>
1653  constexpr int
1655  {
1656  return std::max(RankInfo<T1>::list_rank, max_list_rank<T2, Types...>());
1657  }
1658 
1659  // Helper function for map_rank
1660  template <class T>
1661  constexpr int
1663  {
1664  return RankInfo<T>::map_rank;
1665  }
1666 
1667  template <class T1, class T2, class... Types>
1668  constexpr int
1670  {
1671  return std::max(RankInfo<T1>::map_rank, max_map_rank<T2, Types...>());
1672  }
1673 
1674  // Rank of vector types
1675  template <class T>
1676  struct RankInfo<T, std::enable_if_t<is_list_compatible<T>::value>>
1677  {
1678  static constexpr int list_rank =
1680  static constexpr int map_rank =
1682  };
1683 
1684  // Rank of map types
1685  template <class T>
1686  struct RankInfo<T, std::enable_if_t<is_map_compatible<T>::value>>
1687  {
1688  static constexpr int list_rank =
1689  max_list_rank<typename T::key_type, typename T::mapped_type>() + 1;
1690  static constexpr int map_rank =
1691  max_map_rank<typename T::key_type, typename T::mapped_type>() + 1;
1692  };
1693 
1694  // Rank of Tensor types
1695  template <int rank, int dim, class Number>
1696  struct RankInfo<Tensor<rank, dim, Number>>
1697  {
1698  static constexpr int list_rank = rank + RankInfo<Number>::list_rank;
1699  static constexpr int map_rank = RankInfo<Number>::map_rank;
1700  };
1701 
1702  template <int dim, class Number>
1703  struct RankInfo<Point<dim, Number>> : RankInfo<Tensor<1, dim, Number>>
1704  {};
1705 
1706  // Rank of complex types
1707  template <class Number>
1708  struct RankInfo<std::complex<Number>>
1709  {
1710  static constexpr int list_rank = RankInfo<Number>::list_rank + 1;
1711  static constexpr int map_rank = RankInfo<Number>::map_rank;
1712  };
1713 
1714  // Rank of FunctionParser
1715  template <int dim>
1716  struct RankInfo<std::unique_ptr<FunctionParser<dim>>>
1717  {
1718  static constexpr int list_rank = 1;
1719  static constexpr int map_rank = 0;
1720  };
1721 
1722  // Rank of ComponentMask
1723  template <>
1725  {
1726  static constexpr int list_rank = 1;
1727  static constexpr int map_rank = 0;
1728  };
1729 
1730  // Rank of std::pair
1731  template <class Key, class Value>
1732  struct RankInfo<std::pair<Key, Value>>
1733  {
1734  static constexpr int list_rank =
1736  static constexpr int map_rank =
1738  };
1739 
1740  // Rank of std::tuple types
1741  template <class... Types>
1742  struct RankInfo<std::tuple<Types...>>
1743  {
1744  static constexpr int list_rank = max_list_rank<Types...>();
1745  static constexpr int map_rank = max_map_rank<Types...>() + 1;
1746  };
1747 
1748  // Rank of std::array types
1749  template <class T, std::size_t N>
1750  struct RankInfo<std::array<T, N>>
1751  {
1752  static constexpr int list_rank = RankInfo<T>::list_rank + 1;
1753  static constexpr int map_rank = RankInfo<T>::map_rank;
1754  };
1755  } // namespace internal
1756 
1757  // stl containers
1758  template <class T>
1759  struct Convert<T, std::enable_if_t<is_list_compatible<T>::value>>
1760  {
1761  static std::unique_ptr<Patterns::PatternBase>
1763  {
1764  static_assert(internal::RankInfo<T>::list_rank > 0,
1765  "Cannot use this class for non List-compatible types.");
1766  return std::make_unique<Patterns::List>(
1768  0,
1771  1]);
1772  }
1773 
1774  static std::string
1776  const T &t,
1777  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1778  {
1779  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1780  AssertThrow(p,
1781  ExcMessage("I need a List pattern to convert a "
1782  "string to a List type."));
1783  auto base_p = p->get_base_pattern().clone();
1784  std::vector<std::string> vec(t.size());
1785 
1787  t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1788  return Convert<typename T::value_type>::to_string(entry, *base_p);
1789  });
1790 
1791  std::string s;
1792  if (vec.size() > 0)
1793  s = vec[0];
1794  for (unsigned int i = 1; i < vec.size(); ++i)
1795  s += p->get_separator() + " " + vec[i];
1796 
1797  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1798  return s;
1799  }
1800 
1801  static T
1802  to_value(const std::string &s,
1803  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1804  {
1805  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1806 
1807  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1808  AssertThrow(p,
1809  ExcMessage("I need a List pattern to convert a string "
1810  "to a List type."));
1811 
1812  auto base_p = p->get_base_pattern().clone();
1813  T t;
1814 
1815  auto v = Utilities::split_string_list(s, p->get_separator());
1816  for (const auto &str : v)
1817  t.insert(t.end(),
1819 
1820  return t;
1821  }
1822  };
1823 
1824  // stl maps
1825  template <class T>
1826  struct Convert<T, std::enable_if_t<is_map_compatible<T>::value>>
1827  {
1828  static std::unique_ptr<Patterns::PatternBase>
1830  {
1831  static_assert(internal::RankInfo<T>::list_rank > 0,
1832  "Cannot use this class for non List-compatible types.");
1833  static_assert(internal::RankInfo<T>::map_rank > 0,
1834  "Cannot use this class for non Map-compatible types.");
1835  return std::make_unique<Patterns::Map>(
1838  0,
1841  1],
1843  }
1844 
1845  static std::string
1847  const T &t,
1848  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1849  {
1850  const auto *p = dynamic_cast<const Patterns::Map *>(&pattern);
1851  AssertThrow(p,
1852  ExcMessage("I need a Map pattern to convert a string to "
1853  "a Map compatible type."));
1854  auto key_p = p->get_key_pattern().clone();
1855  auto val_p = p->get_value_pattern().clone();
1856  std::vector<std::string> vec(t.size());
1857 
1858  unsigned int i = 0;
1859  for (const auto &ti : t)
1860  vec[i++] =
1861  Convert<typename T::key_type>::to_string(ti.first, *key_p) +
1862  p->get_key_value_separator() +
1864 
1865  std::string s;
1866  if (vec.size() > 0)
1867  s = vec[0];
1868  for (unsigned int i = 1; i < vec.size(); ++i)
1869  s += p->get_separator() + " " + vec[i];
1870 
1871  AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
1872  return s;
1873  }
1874 
1875  static T
1876  to_value(const std::string &s,
1877  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1878  {
1879  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1880 
1881  const auto *p = dynamic_cast<const Patterns::Map *>(&pattern);
1882  AssertThrow(p,
1883  ExcMessage("I need a Map pattern to convert a "
1884  "string to a Map compatible type."));
1885 
1886  auto key_p = p->get_key_pattern().clone();
1887  auto val_p = p->get_value_pattern().clone();
1888  T t;
1889 
1890  auto v = Utilities::split_string_list(s, p->get_separator());
1891  for (const auto &str : v)
1892  {
1893  auto key_val =
1894  Utilities::split_string_list(str, p->get_key_value_separator());
1895  AssertDimension(key_val.size(), 2);
1896  t.insert(std::make_pair(
1897  Convert<typename T::key_type>::to_value(key_val[0], *key_p),
1898  Convert<typename T::mapped_type>::to_value(key_val[1], *val_p)));
1899  }
1900 
1901  return t;
1902  }
1903  };
1904 
1905  // std::array
1906  template <typename ValueType, std::size_t N>
1907  struct Convert<std::array<ValueType, N>>
1908  {
1909  using T = std::array<ValueType, N>;
1910 
1911  static std::unique_ptr<Patterns::PatternBase>
1913  {
1914  static_assert(internal::RankInfo<T>::list_rank > 0,
1915  "Cannot use this class for non List-compatible types.");
1916  return std::make_unique<Patterns::List>(
1918  N,
1919  N,
1921  1]);
1922  }
1923 
1924  static std::string
1926  const T &t,
1927  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1928  {
1929  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1930  AssertThrow(p,
1931  ExcMessage("I need a List pattern to convert a "
1932  "string to a std::array."));
1933  auto base_p = p->get_base_pattern().clone();
1934  std::vector<std::string> vec(t.size());
1935 
1937  t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1938  return Convert<typename T::value_type>::to_string(entry, *base_p);
1939  });
1940 
1941  std::string s;
1942  if (vec.size() > 0)
1943  s = vec[0];
1944  for (unsigned int i = 1; i < vec.size(); ++i)
1945  s += p->get_separator() + " " + vec[i];
1946 
1947  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1948  return s;
1949  }
1950 
1951  static T
1952  to_value(const std::string &s,
1953  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1954  {
1955  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1956 
1957  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1958  AssertThrow(p,
1959  ExcMessage("I need a List pattern to convert a string "
1960  "to a std::array."));
1961 
1962  auto base_p = p->get_base_pattern().clone();
1963  T t;
1964 
1965  auto v = Utilities::split_string_list(s, p->get_separator());
1966  AssertDimension(v.size(), N);
1967  for (unsigned int i = 0; i < N; ++i)
1968  t[i] = Convert<typename T::value_type>::to_value(v[i], *base_p);
1969  return t;
1970  }
1971  };
1972 
1973  // Tensors
1974  template <int rank, int dim, class Number>
1975  struct Convert<Tensor<rank, dim, Number>>
1976  {
1978  static std::unique_ptr<Patterns::PatternBase>
1980  {
1981  static_assert(internal::RankInfo<T>::list_rank > 0,
1982  "Cannot use this class for non List-compatible types.");
1983  return std::make_unique<Patterns::List>(
1985  dim,
1986  dim,
1988  1]);
1989  }
1990 
1991  static std::string
1993  const T &t,
1994  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
1995  {
1996  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1997  AssertThrow(p,
1998  ExcMessage("I need a List pattern to convert a string "
1999  "to a List compatible type."));
2000  auto base_p = p->get_base_pattern().clone();
2001  std::vector<std::string> vec(dim);
2002 
2003  for (unsigned int i = 0; i < dim; ++i)
2004  vec[i] = Convert<typename T::value_type>::to_string(t[i], *base_p);
2005 
2006  std::string s;
2007  if (vec.size() > 0)
2008  s = vec[0];
2009  for (unsigned int i = 1; i < vec.size(); ++i)
2010  s += p->get_separator() + " " + vec[i];
2011 
2012  AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
2013  return s;
2014  }
2015 
2016  static T
2017  to_value(const std::string &s,
2018  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2019  {
2020  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2021 
2022  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2023  AssertThrow(p,
2024  ExcMessage("I need a List pattern to convert a string "
2025  "to a List compatible type."));
2026 
2027  auto base_p = p->get_base_pattern().clone();
2028  T t;
2029 
2030  auto v = Utilities::split_string_list(s, p->get_separator());
2031  unsigned int i = 0;
2032  for (const auto &str : v)
2033  t[i++] = Convert<typename T::value_type>::to_value(str, *base_p);
2034 
2035  return t;
2036  }
2037  };
2038 
2039  // Points
2040  template <int dim, class Number>
2041  struct Convert<Point<dim, Number>>
2042  {
2044 
2045  static std::unique_ptr<Patterns::PatternBase>
2047  {
2049  }
2050 
2051  static std::string
2053  const T &t,
2054  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2055  {
2057  Tensor<1, dim, Number>(t), pattern);
2058  }
2059 
2060  static T
2061  to_value(const std::string &s,
2062  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2063  {
2064  return T(Convert<Tensor<1, dim, Number>>::to_value(s, pattern));
2065  }
2066  };
2067 
2068  // Functions::FunctionParser
2069  template <int dim>
2070  struct Convert<std::unique_ptr<FunctionParser<dim>>>
2071  {
2072  using T = std::unique_ptr<FunctionParser<dim>>;
2073 
2074  static std::unique_ptr<Patterns::PatternBase>
2076  {
2077  static_assert(internal::RankInfo<T>::list_rank > 0,
2078  "Cannot use this class for non List-compatible types.");
2079 
2080  return std::make_unique<Patterns::List>(
2082  1,
2085  1]);
2086  }
2087 
2088  static std::string
2090  const T &t,
2091  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2092  {
2093  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2094  AssertThrow(p,
2095  ExcMessage("I need a List pattern to convert a string "
2096  "to a List compatible type."));
2097 
2098  const auto &expressions = t->get_expressions();
2099  if (expressions.empty())
2100  return std::string();
2101 
2102  std::string s = expressions[0];
2103  for (unsigned int i = 1; i < expressions.size(); ++i)
2104  s = s + p->get_separator() + expressions[i];
2105 
2106  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2107  return s;
2108  }
2109 
2110  static T
2111  to_value(const std::string &s,
2112  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2113  {
2114  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2115 
2116  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2117  AssertThrow(p,
2118  ExcMessage("I need a List pattern to convert a string "
2119  "to a List compatible type."));
2120 
2121  const auto expressions =
2122  Utilities::split_string_list(s, p->get_separator());
2123 
2124  T t = std::make_unique<FunctionParser<dim>>(expressions.size());
2125  const std::string var =
2127  const typename FunctionParser<dim>::ConstMap constants;
2128  t->initialize(var, expressions, constants, true);
2129  return t;
2130  }
2131  };
2132 
2133  // ComponentMask
2134  template <>
2136  {
2137  using T = ComponentMask;
2138 
2139  static std::unique_ptr<Patterns::PatternBase>
2141  {
2143  }
2144 
2145  static std::string
2147  const T &t,
2148  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2149  {
2150  std::vector<bool> mask(t.size());
2151  for (unsigned int i = 0; i < t.size(); ++i)
2152  mask[i] = t[i];
2153 
2154  return Convert<std::vector<bool>>::to_string(mask, pattern);
2155  }
2156 
2157  static T
2158  to_value(const std::string &s,
2159  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2160  {
2161  const auto mask = Convert<std::vector<bool>>::to_value(s, pattern);
2162  return ComponentMask(mask);
2163  }
2164  };
2165 
2166  // Complex numbers
2167  template <class Number>
2168  struct Convert<std::complex<Number>>
2169  {
2170  using T = std::complex<Number>;
2171 
2172  static std::unique_ptr<Patterns::PatternBase>
2174  {
2175  static_assert(internal::RankInfo<T>::list_rank > 0,
2176  "Cannot use this class for non List-compatible types.");
2177  return std::make_unique<Patterns::List>(
2179  2,
2180  2,
2182  1]);
2183  }
2184 
2185  static std::string
2187  const T &t,
2188  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2189  {
2190  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2191  AssertThrow(p,
2192  ExcMessage("I need a List pattern to convert a string "
2193  "to a List compatible type."));
2194 
2195  auto base_p = p->get_base_pattern().clone();
2196  std::string s =
2197  Convert<typename T::value_type>::to_string(t.real(), *base_p) +
2198  p->get_separator() + " " +
2199  Convert<typename T::value_type>::to_string(t.imag(), *base_p);
2200 
2201  AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2202  return s;
2203  }
2204 
2208  static T
2209  to_value(const std::string &s,
2210  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2211  {
2212  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2213 
2214  const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2215  AssertThrow(p,
2216  ExcMessage("I need a List pattern to convert a string "
2217  "to a List compatible type."));
2218 
2219  auto base_p = p->get_base_pattern().clone();
2220 
2221  auto v = Utilities::split_string_list(s, p->get_separator());
2222  AssertDimension(v.size(), 2);
2225  return t;
2226  }
2227  };
2228 
2229  // Strings
2230  template <>
2231  struct Convert<std::string>
2232  {
2233  using T = std::string;
2234 
2235  static std::unique_ptr<Patterns::PatternBase>
2237  {
2238  return std::make_unique<Patterns::Anything>();
2239  }
2240 
2241  static std::string
2243  const T &t,
2244  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2245  {
2246  AssertThrow(pattern.match(t), ExcNoMatch(t, pattern.description()));
2247  return t;
2248  }
2249 
2250  static T
2251  to_value(const std::string &s,
2252  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2253  {
2254  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2255  return s;
2256  }
2257  };
2258 
2259  // Pairs
2260  template <class Key, class Value>
2261  struct Convert<std::pair<Key, Value>>
2262  {
2263  using T = std::pair<Key, Value>;
2264 
2265  static std::unique_ptr<Patterns::PatternBase>
2267  {
2268  static_assert(internal::RankInfo<T>::map_rank > 0,
2269  "Cannot use this class for non Map-compatible types.");
2270  return std::make_unique<Patterns::Tuple>(
2274  }
2275 
2276  static std::string
2278  const T &t,
2279  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2280  {
2281  std::tuple<Key, Value> m(t);
2282  std::string s = Convert<decltype(m)>::to_string(m, pattern);
2283  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2284  return s;
2285  }
2286 
2287  static T
2288  to_value(const std::string &s,
2289  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2290  {
2291  std::tuple<Key, Value> m;
2292  m = Convert<decltype(m)>::to_value(s, pattern);
2293  return std::make_pair(std::get<0>(m), std::get<1>(m));
2294  }
2295  };
2296 
2297  // Tuples
2298  template <class... Args>
2299  struct Convert<std::tuple<Args...>>
2300  {
2301  using T = std::tuple<Args...>;
2302 
2303  static std::unique_ptr<Patterns::PatternBase>
2305  {
2306  static_assert(internal::RankInfo<T>::map_rank > 0,
2307  "Cannot use this class for non tuple-compatible types.");
2308  return std::make_unique<Patterns::Tuple>(
2311  }
2312 
2313  static std::string
2315  const T &t,
2316  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2317  {
2318  const auto *p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2319  AssertThrow(p,
2320  ExcMessage("I need a Tuple pattern to convert a tuple "
2321  "to a string."));
2322 
2323  const auto string_array = Convert<T>::to_string_internal_2(t, *p);
2324  std::string str;
2325  for (unsigned int i = 0; i < string_array.size(); ++i)
2326  str +=
2327  (i != 0u ? " " + p->get_separator() + " " : "") + string_array[i];
2328  AssertThrow(p->match(str), ExcNoMatch(str, p->description()));
2329  return str;
2330  }
2331 
2332  static T
2333  to_value(const std::string &s,
2334  const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
2335  {
2336  AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2337 
2338  const auto *p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2339  AssertThrow(p,
2340  ExcMessage("I need a Tuple pattern to convert a string "
2341  "to a tuple type."));
2342 
2343  auto v = Utilities::split_string_list(s, p->get_separator());
2344 
2345  return Convert<T>::to_value_internal_2(v, *p);
2346  }
2347 
2348  private:
2349  template <std::size_t... U>
2350  static std::array<std::string, std::tuple_size<T>::value>
2352  const Patterns::Tuple &pattern,
2353  std::index_sequence<U...>)
2354  {
2355  std::array<std::string, std::tuple_size<T>::value> a = {
2357  std::get<U>(t), pattern.get_pattern(U))...}};
2358  return a;
2359  }
2360 
2361  static std::array<std::string, std::tuple_size<T>::value>
2362  to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
2363  {
2365  t, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2366  }
2367 
2368  template <std::size_t... U>
2369  static T
2370  to_value_internal_1(const std::vector<std::string> &s,
2371  const Patterns::Tuple &pattern,
2372  std::index_sequence<U...>)
2373  {
2374  return std::make_tuple(
2375  Convert<typename std::tuple_element<U, T>::type>::to_value(
2376  s[U], pattern.get_pattern(U))...);
2377  }
2378 
2379  static T
2380  to_value_internal_2(const std::vector<std::string> &s,
2381  const Patterns::Tuple &pattern)
2382  {
2384  s, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2385  }
2386  };
2387 
2388  // Utility function with default Pattern
2389  template <typename T>
2390  std::string
2391  to_string(const T &t)
2392  {
2393  return Convert<T>::to_string(t);
2394  }
2395 
2396  // Utility function with default Pattern
2397  template <typename T>
2398  void
2399  to_value(const std::string &s, T &t)
2400  {
2401  t = Convert<T>::to_value(s);
2402  }
2403  } // namespace Tools
2404 } // namespace Patterns
2405 
2406 
2408 
2409 #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:1511
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1467
static const char * description_init
Definition: patterns.h:1064
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1475
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1503
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1414
static const char * description_init
Definition: patterns.h:1015
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1442
static std::unique_ptr< Bool > create(const std::string &description)
Definition: patterns.cc:1450
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1653
static const char * description_init
Definition: patterns.h:1204
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1625
static std::unique_ptr< DirectoryName > create(const std::string &description)
Definition: patterns.cc:1661
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1617
static std::unique_ptr< Double > create(const std::string &description)
Definition: patterns.cc:489
static const char * description_init
Definition: patterns.h:369
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:481
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
Definition: patterns.cc:350
const double lower_bound
Definition: patterns.h:356
const double upper_bound
Definition: patterns.h:364
static const double max_double_value
Definition: patterns.h:304
static const double min_double_value
Definition: patterns.h:298
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:381
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:358
FileType file_type
Definition: patterns.h:1132
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1533
FileName(const FileType type=input)
Definition: patterns.cc:1526
static const char * description_init
Definition: patterns.h:1146
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1577
static std::unique_ptr< FileName > create(const std::string &description)
Definition: patterns.cc:1585
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1541
static std::unique_ptr< Integer > create(const std::string &description)
Definition: patterns.cc:310
static const char * description_init
Definition: patterns.h:271
const int upper_bound
Definition: patterns.h:266
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:302
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
Definition: patterns.cc:211
const int lower_bound
Definition: patterns.h:258
static const int min_int_value
Definition: patterns.h:196
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:241
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:219
static const int max_int_value
Definition: patterns.h:203
const unsigned int max_elements
Definition: patterns.h:555
static const char * description_init
Definition: patterns.h:565
const unsigned int min_elements
Definition: patterns.h:550
std::unique_ptr< PatternBase > pattern
Definition: patterns.h:545
const std::string separator
Definition: patterns.h:560
std::size_t memory_consumption() const override
Definition: patterns.cc:766
static std::unique_ptr< List > create(const std::string &description)
Definition: patterns.cc:775
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:714
const PatternBase & get_base_pattern() const
Definition: patterns.cc:686
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:694
const std::string & get_separator() const
Definition: patterns.cc:678
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:652
static const unsigned int max_int_value
Definition: patterns.h:457
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:758
static std::unique_ptr< Map > create(const std::string &description)
Definition: patterns.cc:984
std::unique_ptr< PatternBase > value_pattern
Definition: patterns.h:694
const unsigned int min_elements
Definition: patterns.h:699
const PatternBase & get_key_pattern() const
Definition: patterns.cc:1039
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:880
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:840
const unsigned int max_elements
Definition: patterns.h:704
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:960
const PatternBase & get_value_pattern() const
Definition: patterns.cc:1047
const std::string & get_separator() const
Definition: patterns.cc:1055
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:910
static const unsigned int max_int_value
Definition: patterns.h:591
std::unique_ptr< PatternBase > key_pattern
Definition: patterns.h:693
const std::string separator
Definition: patterns.h:709
std::size_t memory_consumption() const override
Definition: patterns.cc:972
static const char * description_init
Definition: patterns.h:720
const std::string & get_key_value_separator() const
Definition: patterns.cc:1062
const std::string key_value_separator
Definition: patterns.h:715
MultipleSelection(const std::string &seq)
Definition: patterns.cc:1256
static std::unique_ptr< MultipleSelection > create(const std::string &description)
Definition: patterns.cc:1385
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1271
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1369
static const char * description_init
Definition: patterns.h:973
std::size_t memory_consumption() const override
Definition: patterns.cc:1376
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1334
virtual std::size_t memory_consumption() const
Definition: patterns.cc:190
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:438
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:576
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:611
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:544
static std::unique_ptr< Selection > create(const std::string &description)
Definition: patterns.cc:627
std::size_t memory_consumption() const override
Definition: patterns.cc:618
Selection(const std::string &seq)
Definition: patterns.cc:532
std::string sequence
Definition: patterns.h:433
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1105
Tuple(const std::vector< std::unique_ptr< PatternBase >> &patterns, const std::string &separator=":")
Definition: patterns.cc:1072
std::size_t memory_consumption() const override
Definition: patterns.cc:1181
static std::unique_ptr< Tuple > create(const std::string &description)
Definition: patterns.cc:1190
std::vector< std::unique_ptr< PatternBase > > patterns
Definition: patterns.h:879
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1174
Tuple(const Patterns &...patterns)
const std::string separator
Definition: patterns.h:884
static const char * description_init
Definition: patterns.h:889
const std::string & get_separator() const
Definition: patterns.cc:1246
const PatternBase & get_pattern(const unsigned int i) const
Definition: patterns.cc:1238
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1124
Definition: point.h:112
Definition: tensor.h:516
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
__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:535
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1789
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:512
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1705
static const char U
static const char T
static const char N
constexpr std::array< const char *, 4 > default_map_separator
Definition: patterns.h:1574
constexpr int max_map_rank()
Definition: patterns.h:1662
constexpr int max_list_rank()
Definition: patterns.h:1647
constexpr std::array< const char *, 4 > default_list_separator
Definition: patterns.h:1572
void to_value(const std::string &s, T &t)
Definition: patterns.h:2399
std::string to_string(const T &t)
Definition: patterns.h:2391
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
Definition: patterns.cc:53
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
Definition: patterns.cc:138
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition: utilities.cc:702
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Function &function, const unsigned int grainsize)
Definition: parallel.h:166
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2158
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2146
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2140
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2046
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2052
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2061
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1762
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1802
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1775
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1846
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1829
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1876
static std::enable_if_t< std::is_same_v< Dummy, T > &&!std::is_same_v< T, bool > &&std::is_integral_v< T >, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1500
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition: patterns.h:1534
static std::enable_if_t< std::is_same_v< Dummy, T > &&std::is_same_v< T, bool >, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1490
static std::enable_if_t< std::is_same_v< Dummy, T > &&!std::is_same_v< T, bool > &&std::is_floating_point_v< T >, std::unique_ptr< Patterns::PatternBase > > to_pattern()
Definition: patterns.h:1511
static std::string to_string(const T &value, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition: patterns.h:1518
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2017
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1979
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1992
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1952
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:1925
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:1912
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2173
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2209
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2186
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2266
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2288
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2277
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2251
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2236
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2242
static T to_value_internal_2(const std::vector< std::string > &s, const Patterns::Tuple &pattern)
Definition: patterns.h:2380
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2333
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2304
static std::array< std::string, std::tuple_size< T >::value > to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
Definition: patterns.h:2362
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:2351
static T to_value_internal_1(const std::vector< std::string > &s, const Patterns::Tuple &pattern, std::index_sequence< U... >)
Definition: patterns.h:2370
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2314
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2111
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition: patterns.h:2075
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition: patterns.h:2089
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:1477
static constexpr int map_rank
Definition: patterns.h:1478
static constexpr const bool value
Definition: patterns.h:1631
static constexpr const bool value
Definition: patterns.h:1638