Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
patterns.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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 
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/point.h>
24 #include <deal.II/base/std_cxx14/algorithm.h>
25 #include <deal.II/base/std_cxx14/memory.h>
26 #include <deal.II/base/std_cxx14/utility.h>
27 #include <deal.II/base/subscriptor.h>
28 #include <deal.II/base/template_constraints.h>
29 #include <deal.II/base/utilities.h>
30 
31 #include <deal.II/fe/component_mask.h>
32 
33 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
34 #include <boost/archive/basic_archive.hpp>
35 #include <boost/core/demangle.hpp>
36 #include <boost/property_tree/ptree_fwd.hpp>
37 #include <boost/property_tree/ptree_serialization.hpp>
38 #include <boost/serialization/split_member.hpp>
39 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
40 
41 #include <array>
42 #include <deque>
43 #include <list>
44 #include <map>
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 
54 DEAL_II_NAMESPACE_OPEN
55 
56 // forward declarations for interfaces and friendship
57 class LogStream;
59 template <int dim>
60 class FunctionParser;
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  {
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 
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,
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 
1289  namespace Tools
1290  {
1302  template <class T, class Enable = void>
1303  struct Convert
1304  {
1314  static std::unique_ptr<Patterns::PatternBase>
1315  to_pattern() = delete;
1316 
1327  static std::string
1328  to_string(const T & s,
1329  const std::unique_ptr<Patterns::PatternBase> &p =
1330  Convert<T>::to_pattern()) = delete;
1331 
1341  static T
1342  to_value(const std::string & s,
1343  const std::unique_ptr<Patterns::PatternBase> &p =
1344  Convert<T>::to_pattern()) = delete;
1345  };
1346 
1367  template <typename T>
1368  std::string
1369  to_string(const T &t);
1370 
1398  template <typename T>
1399  void
1400  to_value(const std::string &s, T &t);
1401 
1411  std::string,
1412  const Patterns::PatternBase *,
1413  << "The string " << arg1 << " does not match the pattern \""
1414  << arg2->description() << "\"");
1416  } // namespace Tools
1417 } // namespace Patterns
1418 
1419 
1420 // ---------------------- inline and template functions --------------------
1421 namespace Patterns
1422 {
1423  template <class... PatternTypes>
1424  Tuple::Tuple(const char *separator, const PatternTypes &... ps)
1425  : // forward to the version with std::string argument
1426  Tuple(std::string(separator), ps...)
1427  {}
1428 
1429 
1430 
1431  template <class... PatternTypes>
1432  Tuple::Tuple(const std::string &separator, const PatternTypes &... ps)
1433  : separator(separator)
1434  {
1436  "Not all of the input arguments of this function "
1437  "are derived from PatternBase");
1438  static_assert(sizeof...(ps) > 0,
1439  "The number of PatternTypes must be greater than zero!");
1440  auto pattern_pointers = {(static_cast<const PatternBase *>(&ps))...};
1441  for (const auto p : pattern_pointers)
1442  patterns.push_back(p->clone());
1443  }
1444 
1445 
1446 
1447  template <class... PatternTypes>
1448  Tuple::Tuple(const PatternTypes &... ps)
1449  : // forward to the version with the separator argument
1450  Tuple(std::string(":"), ps...)
1451  {}
1452 
1453 
1454 
1455  namespace Tools
1456  {
1457  namespace internal
1458  {
1485  template <class T, class Enable = void>
1486  struct RankInfo
1487  {
1488  static constexpr int list_rank = 0;
1489  static constexpr int map_rank = 0;
1490  };
1491  } // namespace internal
1492 
1493  // Arithmetic types
1494  template <class T>
1495  struct Convert<T,
1496  typename std::enable_if<std::is_arithmetic<T>::value>::type>
1497  {
1498  template <typename Dummy = T>
1499  static
1500  typename std::enable_if<std::is_same<Dummy, T>::value &&
1501  std::is_same<T, bool>::value,
1502  std::unique_ptr<Patterns::PatternBase>>::type
1503  to_pattern()
1504  {
1505  return std_cxx14::make_unique<Patterns::Bool>();
1506  }
1507 
1508  template <typename Dummy = T>
1509  static
1510  typename std::enable_if<std::is_same<Dummy, T>::value &&
1511  !std::is_same<T, bool>::value &&
1512  std::is_integral<T>::value,
1513  std::unique_ptr<Patterns::PatternBase>>::type
1514  to_pattern()
1515  {
1516  return std_cxx14::make_unique<Patterns::Integer>(
1517  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1518  }
1519 
1520  template <typename Dummy = T>
1521  static
1522  typename std::enable_if<std::is_same<Dummy, T>::value &&
1523  !std::is_same<T, bool>::value &&
1524  std::is_floating_point<T>::value,
1525  std::unique_ptr<Patterns::PatternBase>>::type
1526  to_pattern()
1527  {
1528  return std_cxx14::make_unique<Patterns::Double>(
1529  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1530  }
1531 
1532  static std::string
1533  to_string(const T & value,
1534  const std::unique_ptr<Patterns::PatternBase> &p =
1536  {
1537  std::stringstream str;
1538  if (std::is_same<T, unsigned char>::value ||
1539  std::is_same<T, signed char>::value || std::is_same<T, char>::value)
1540  str << static_cast<int>(value);
1541  else if (std::is_same<T, bool>::value)
1542  str << (static_cast<bool>(value) ? "true" : "false");
1543  else
1544  str << value;
1545  AssertThrow(p->match(str.str()), ExcNoMatch(str.str(), p.get()));
1546  return str.str();
1547  }
1548 
1549  static T
1550  to_value(const std::string & s,
1551  const std::unique_ptr<Patterns::PatternBase> &p =
1553  {
1554  AssertThrow(p->match(s), ExcNoMatch(s, p.get()));
1555  T value;
1556  if (std::is_same<T, bool>::value)
1557  value = (s == "true");
1558  else
1559  {
1560  std::istringstream is(s);
1561  if (std::is_same<T, unsigned char>::value ||
1562  std::is_same<T, signed char>::value ||
1563  std::is_same<T, char>::value)
1564  {
1565  int i;
1566  is >> i;
1567  value = i;
1568  }
1569  else
1570  is >> value;
1571 
1572  // If someone passes "123 abc" to the function, the method yields an
1573  // integer 123 alright, but the space terminates the read from the
1574  // string although there is more to come. This case, however, is
1575  // checked for in the call p->match(s) at the beginning of this
1576  // function, and would throw earlier. Here it is safe to assume that
1577  // if we didn't fail the conversion with the operator >>, then we
1578  // are good to go.
1579  AssertThrow(
1580  !is.fail(),
1581  ExcMessage("Failed to convert from \"" + s + "\" to the type \"" +
1582  boost::core::demangle(typeid(T).name()) + "\""));
1583  }
1584  return value;
1585  }
1586  };
1587 
1588  namespace internal
1589  {
1590  constexpr std::array<const char *, 4> default_list_separator{
1591  {",", ";", "|", "%"}};
1592  constexpr std::array<const char *, 4> default_map_separator{
1593  {":", "=", "@", "#"}};
1594 
1595  // specialize a type for all of the STL containers and maps
1596  template <typename T>
1597  struct is_list_compatible : std::false_type
1598  {};
1599  template <typename T, std::size_t N>
1600  struct is_list_compatible<std::array<T, N>> : std::true_type
1601  {};
1602  template <typename... Args>
1603  struct is_list_compatible<std::vector<Args...>> : std::true_type
1604  {};
1605  template <typename... Args>
1606  struct is_list_compatible<std::deque<Args...>> : std::true_type
1607  {};
1608  template <typename... Args>
1609  struct is_list_compatible<std::list<Args...>> : std::true_type
1610  {};
1611  template <typename... Args>
1612  struct is_list_compatible<std::set<Args...>> : std::true_type
1613  {};
1614  template <typename... Args>
1615  struct is_list_compatible<std::multiset<Args...>> : std::true_type
1616  {};
1617  template <typename... Args>
1618  struct is_list_compatible<std::unordered_set<Args...>> : std::true_type
1619  {};
1620  template <typename... Args>
1621  struct is_list_compatible<std::unordered_multiset<Args...>>
1622  : std::true_type
1623  {};
1624 
1625  template <typename T>
1626  struct is_map_compatible : std::false_type
1627  {};
1628  template <class Key, class T, class Compare, class Allocator>
1629  struct is_map_compatible<std::map<Key, T, Compare, Allocator>>
1630  : std::true_type
1631  {};
1632  template <class Key, class T, class Compare, class Allocator>
1633  struct is_map_compatible<std::multimap<Key, T, Compare, Allocator>>
1634  : std::true_type
1635  {};
1636  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1637  struct is_map_compatible<
1638  std::unordered_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type
1639  {};
1640  template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1641  struct is_map_compatible<
1642  std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>>
1643  : std::true_type
1644  {};
1645  } // namespace internal
1646 
1647  // type trait to use the implementation type traits as well as decay the
1648  // type
1649  template <typename T>
1650  struct is_list_compatible
1651  {
1652  static constexpr bool const value =
1653  internal::is_list_compatible<typename std::decay<T>::type>::value;
1654  };
1655 
1656  template <typename T>
1657  struct is_map_compatible
1658  {
1659  static constexpr bool const value =
1660  internal::is_map_compatible<typename std::decay<T>::type>::value;
1661  };
1662 
1663  namespace internal
1664  {
1665  // Helper function for list_rank
1666  template <class T>
1667  constexpr int
1668  max_list_rank()
1669  {
1670  return RankInfo<T>::list_rank;
1671  }
1672 
1673  template <class T1, class T2, class... Types>
1674  constexpr int
1675  max_list_rank()
1676  {
1677  return std_cxx14::max(RankInfo<T1>::list_rank,
1678  max_list_rank<T2, Types...>());
1679  }
1680 
1681  // Helper function for map_rank
1682  template <class T>
1683  constexpr int
1684  max_map_rank()
1685  {
1686  return RankInfo<T>::map_rank;
1687  }
1688 
1689  template <class T1, class T2, class... Types>
1690  constexpr int
1691  max_map_rank()
1692  {
1693  return std_cxx14::max(RankInfo<T1>::map_rank,
1694  max_map_rank<T2, Types...>());
1695  }
1696 
1697  // Rank of vector types
1698  template <class T>
1699  struct RankInfo<
1700  T,
1701  typename std::enable_if<is_list_compatible<T>::value>::type>
1702  {
1703  static constexpr int list_rank =
1704  RankInfo<typename T::value_type>::list_rank + 1;
1705  static constexpr int map_rank =
1706  RankInfo<typename T::value_type>::map_rank;
1707  };
1708 
1709  // Rank of map types
1710  template <class T>
1711  struct RankInfo<
1712  T,
1713  typename std::enable_if<is_map_compatible<T>::value>::type>
1714  {
1715  static constexpr int list_rank =
1716  max_list_rank<typename T::key_type, typename T::mapped_type>() + 1;
1717  static constexpr int map_rank =
1718  max_map_rank<typename T::key_type, typename T::mapped_type>() + 1;
1719  };
1720 
1721  // Rank of Tensor types
1722  template <int rank, int dim, class Number>
1723  struct RankInfo<Tensor<rank, dim, Number>>
1724  {
1725  static constexpr int list_rank = rank + RankInfo<Number>::list_rank;
1726  static constexpr int map_rank = RankInfo<Number>::map_rank;
1727  };
1728 
1729  template <int dim, class Number>
1730  struct RankInfo<Point<dim, Number>> : RankInfo<Tensor<1, dim, Number>>
1731  {};
1732 
1733  // Rank of complex types
1734  template <class Number>
1735  struct RankInfo<std::complex<Number>>
1736  {
1737  static constexpr int list_rank = RankInfo<Number>::list_rank + 1;
1738  static constexpr int map_rank = RankInfo<Number>::map_rank;
1739  };
1740 
1741  // Rank of FunctionParser
1742  template <int dim>
1743  struct RankInfo<std::unique_ptr<FunctionParser<dim>>>
1744  {
1745  static constexpr int list_rank = 1;
1746  static constexpr int map_rank = 0;
1747  };
1748 
1749  // Rank of ComponentMask
1750  template <>
1751  struct RankInfo<ComponentMask>
1752  {
1753  static constexpr int list_rank = 1;
1754  static constexpr int map_rank = 0;
1755  };
1756 
1757  // Rank of std::pair
1758  template <class Key, class Value>
1759  struct RankInfo<std::pair<Key, Value>>
1760  {
1761  static constexpr int list_rank =
1762  std_cxx14::max(RankInfo<Key>::list_rank, RankInfo<Value>::list_rank);
1763  static constexpr int map_rank =
1764  std_cxx14::max(RankInfo<Key>::map_rank, RankInfo<Value>::map_rank) +
1765  1;
1766  };
1767 
1768 
1769  template <class... Types>
1770  struct RankInfo<std::tuple<Types...>>
1771  {
1772  static constexpr int list_rank = max_list_rank<Types...>();
1773  static constexpr int map_rank = max_map_rank<Types...>() + 1;
1774  };
1775  } // namespace internal
1776 
1777  // stl containers
1778  template <class T>
1779  struct Convert<T,
1780  typename std::enable_if<is_list_compatible<T>::value>::type>
1781  {
1782  static std::unique_ptr<Patterns::PatternBase>
1783  to_pattern()
1784  {
1785  static_assert(internal::RankInfo<T>::list_rank > 0,
1786  "Cannot use this class for non List-compatible types.");
1787  return std_cxx14::make_unique<Patterns::List>(
1789  0,
1790  std::numeric_limits<unsigned int>::max(),
1791  internal::default_list_separator[internal::RankInfo<T>::list_rank -
1792  1]);
1793  }
1794 
1795  static std::string
1796  to_string(const T & t,
1797  const std::unique_ptr<Patterns::PatternBase> &pattern =
1799  {
1800  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
1801  AssertThrow(p,
1802  ExcMessage("I need a List pattern to convert a "
1803  "string to a List type."));
1804  auto base_p = p->get_base_pattern().clone();
1805  std::vector<std::string> vec(t.size());
1806 
1807  unsigned int i = 0;
1808  for (const auto &entry : t)
1809  vec[i++] = Convert<typename T::value_type>::to_string(entry, base_p);
1810 
1811  std::string s;
1812  if (vec.size() > 0)
1813  s = vec[0];
1814  for (unsigned int i = 1; i < vec.size(); ++i)
1815  s += p->get_separator() + " " + vec[i];
1816 
1817  AssertThrow(pattern->match(s), ExcNoMatch(s, p));
1818  return s;
1819  }
1820 
1821  static T
1822  to_value(const std::string & s,
1823  const std::unique_ptr<Patterns::PatternBase> &pattern =
1825  {
1826  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
1827 
1828  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
1829  AssertThrow(p,
1830  ExcMessage("I need a List pattern to convert a string "
1831  "to a List type."));
1832 
1833  auto base_p = p->get_base_pattern().clone();
1834  T t;
1835 
1836  auto v = Utilities::split_string_list(s, p->get_separator());
1837  for (const auto &str : v)
1838  t.insert(t.end(),
1840 
1841  return t;
1842  }
1843  };
1844 
1845  // stl maps
1846  template <class T>
1847  struct Convert<T,
1848  typename std::enable_if<is_map_compatible<T>::value>::type>
1849  {
1850  static std::unique_ptr<Patterns::PatternBase>
1851  to_pattern()
1852  {
1853  static_assert(internal::RankInfo<T>::list_rank > 0,
1854  "Cannot use this class for non List-compatible types.");
1855  static_assert(internal::RankInfo<T>::map_rank > 0,
1856  "Cannot use this class for non Map-compatible types.");
1857  return std_cxx14::make_unique<Patterns::Map>(
1860  0,
1861  std::numeric_limits<unsigned int>::max(),
1862  internal::default_list_separator[internal::RankInfo<T>::list_rank -
1863  1],
1864  internal::default_map_separator[internal::RankInfo<T>::map_rank - 1]);
1865  }
1866 
1867  static std::string
1868  to_string(const T & t,
1869  const std::unique_ptr<Patterns::PatternBase> &pattern =
1871  {
1872  auto p = dynamic_cast<const Patterns::Map *>(pattern.get());
1873  AssertThrow(p,
1874  ExcMessage("I need a Map pattern to convert a string to "
1875  "a Map compatible type."));
1876  auto key_p = p->get_key_pattern().clone();
1877  auto val_p = p->get_value_pattern().clone();
1878  std::vector<std::string> vec(t.size());
1879 
1880  unsigned int i = 0;
1881  for (const auto &ti : t)
1882  vec[i++] =
1883  Convert<typename T::key_type>::to_string(ti.first, key_p) +
1884  p->get_key_value_separator() +
1886 
1887  std::string s;
1888  if (vec.size() > 0)
1889  s = vec[0];
1890  for (unsigned int i = 1; i < vec.size(); ++i)
1891  s += p->get_separator() + " " + vec[i];
1892 
1893  AssertThrow(p->match(s), ExcNoMatch(s, p));
1894  return s;
1895  }
1896 
1897  static T
1898  to_value(const std::string & s,
1899  const std::unique_ptr<Patterns::PatternBase> &pattern =
1901  {
1902  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
1903 
1904  auto p = dynamic_cast<const Patterns::Map *>(pattern.get());
1905  AssertThrow(p,
1906  ExcMessage("I need a Map pattern to convert a "
1907  "string to a Map compatible type."));
1908 
1909  auto key_p = p->get_key_pattern().clone();
1910  auto val_p = p->get_value_pattern().clone();
1911  T t;
1912 
1913  auto v = Utilities::split_string_list(s, p->get_separator());
1914  for (const auto &str : v)
1915  {
1916  auto key_val =
1917  Utilities::split_string_list(str, p->get_key_value_separator());
1918  AssertDimension(key_val.size(), 2);
1919  t.insert(std::make_pair(
1920  Convert<typename T::key_type>::to_value(key_val[0], key_p),
1922  }
1923 
1924  return t;
1925  }
1926  };
1927 
1928  // Tensors
1929  template <int rank, int dim, class Number>
1930  struct Convert<Tensor<rank, dim, Number>>
1931  {
1932  using T = Tensor<rank, dim, Number>;
1933  static std::unique_ptr<Patterns::PatternBase>
1934  to_pattern()
1935  {
1936  static_assert(internal::RankInfo<T>::list_rank > 0,
1937  "Cannot use this class for non List-compatible types.");
1938  return std_cxx14::make_unique<Patterns::List>(
1940  dim,
1941  dim,
1942  internal::default_list_separator[internal::RankInfo<T>::list_rank -
1943  1]);
1944  }
1945 
1946  static std::string
1947  to_string(const T & t,
1948  const std::unique_ptr<Patterns::PatternBase> &pattern =
1950  {
1951  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
1952  AssertThrow(p,
1953  ExcMessage("I need a List pattern to convert a string "
1954  "to a List compatible type."));
1955  auto base_p = p->get_base_pattern().clone();
1956  std::vector<std::string> vec(dim);
1957 
1958  for (unsigned int i = 0; i < dim; ++i)
1959  vec[i] = Convert<typename T::value_type>::to_string(t[i], base_p);
1960 
1961  std::string s;
1962  if (vec.size() > 0)
1963  s = vec[0];
1964  for (unsigned int i = 1; i < vec.size(); ++i)
1965  s += p->get_separator() + " " + vec[i];
1966 
1967  AssertThrow(p->match(s), ExcNoMatch(s, p));
1968  return s;
1969  }
1970 
1971  static T
1972  to_value(const std::string & s,
1973  const std::unique_ptr<Patterns::PatternBase> &pattern =
1975  {
1976  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
1977 
1978  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
1979  AssertThrow(p,
1980  ExcMessage("I need a List pattern to convert a string "
1981  "to a List compatible type."));
1982 
1983  auto base_p = p->get_base_pattern().clone();
1984  T t;
1985 
1986  auto v = Utilities::split_string_list(s, p->get_separator());
1987  unsigned int i = 0;
1988  for (const auto &str : v)
1989  t[i++] = Convert<typename T::value_type>::to_value(str, base_p);
1990 
1991  return t;
1992  }
1993  };
1994 
1995  // Points
1996  template <int dim, class Number>
1997  struct Convert<Point<dim, Number>>
1998  {
1999  using T = Point<dim, Number>;
2000 
2001  static std::unique_ptr<Patterns::PatternBase>
2002  to_pattern()
2003  {
2004  return Convert<Tensor<1, dim, Number>>::to_pattern();
2005  }
2006 
2007  static std::string
2008  to_string(const T & t,
2009  const std::unique_ptr<Patterns::PatternBase> &pattern =
2011  {
2012  return Convert<Tensor<1, dim, Number>>::to_string(
2013  Tensor<1, dim, Number>(t), pattern);
2014  }
2015 
2016  static T
2017  to_value(const std::string & s,
2018  const std::unique_ptr<Patterns::PatternBase> &pattern =
2020  {
2021  return T(Convert<Tensor<1, dim, Number>>::to_value(s, pattern));
2022  }
2023  };
2024 
2025  // Functions::FunctionParser
2026  template <int dim>
2027  struct Convert<std::unique_ptr<FunctionParser<dim>>>
2028  {
2029  using T = std::unique_ptr<FunctionParser<dim>>;
2030 
2031  static std::unique_ptr<Patterns::PatternBase>
2032  to_pattern()
2033  {
2034  static_assert(internal::RankInfo<T>::list_rank > 0,
2035  "Cannot use this class for non List-compatible types.");
2036 
2037  return std_cxx14::make_unique<Patterns::List>(
2039  1,
2041  internal::default_list_separator[internal::RankInfo<T>::list_rank -
2042  1]);
2043  }
2044 
2045  static std::string
2046  to_string(const T & t,
2047  const std::unique_ptr<Patterns::PatternBase> &pattern =
2049  {
2050  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
2051  AssertThrow(p,
2052  ExcMessage("I need a List pattern to convert a string "
2053  "to a List compatible type."));
2054 
2055  const auto &expressions = t->get_expressions();
2056  if (expressions.size() == 0)
2057  return std::string();
2058 
2059  std::string s = expressions[0];
2060  for (unsigned int i = 1; i < expressions.size(); ++i)
2061  s = s + p->get_separator() + expressions[i];
2062 
2063  AssertThrow(pattern->match(s), ExcNoMatch(s, p));
2064  return s;
2065  }
2066 
2067  static T
2068  to_value(const std::string & s,
2069  const std::unique_ptr<Patterns::PatternBase> &pattern =
2071  {
2072  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
2073 
2074  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
2075  AssertThrow(p,
2076  ExcMessage("I need a List pattern to convert a string "
2077  "to a List compatible type."));
2078 
2079  const auto expressions =
2080  Utilities::split_string_list(s, p->get_separator());
2081 
2082  T t = std_cxx14::make_unique<FunctionParser<dim>>(expressions.size());
2083  const std::string var =
2085  const typename FunctionParser<dim>::ConstMap constants;
2086  t->initialize(var, expressions, constants, true);
2087  return t;
2088  }
2089  };
2090 
2091  // ComponentMask
2092  template <>
2093  struct Convert<ComponentMask>
2094  {
2095  using T = ComponentMask;
2096 
2097  static std::unique_ptr<Patterns::PatternBase>
2098  to_pattern()
2099  {
2100  return Convert<std::vector<bool>>::to_pattern();
2101  }
2102 
2103  static std::string
2104  to_string(const T & t,
2105  const std::unique_ptr<Patterns::PatternBase> &pattern =
2107  {
2108  std::vector<bool> mask(t.size());
2109  for (unsigned int i = 0; i < t.size(); ++i)
2110  mask[i] = t[i];
2111 
2112  return Convert<std::vector<bool>>::to_string(mask, pattern);
2113  }
2114 
2115  static T
2116  to_value(const std::string & s,
2117  const std::unique_ptr<Patterns::PatternBase> &pattern =
2119  {
2120  const auto mask = Convert<std::vector<bool>>::to_value(s, pattern);
2121  return ComponentMask(mask);
2122  }
2123  };
2124 
2125  // Complex numbers
2126  template <class Number>
2127  struct Convert<std::complex<Number>>
2128  {
2129  using T = std::complex<Number>;
2130 
2131  static std::unique_ptr<Patterns::PatternBase>
2132  to_pattern()
2133  {
2134  static_assert(internal::RankInfo<T>::list_rank > 0,
2135  "Cannot use this class for non List-compatible types.");
2136  return std_cxx14::make_unique<Patterns::List>(
2138  2,
2139  2,
2140  internal::default_list_separator[internal::RankInfo<T>::list_rank -
2141  1]);
2142  }
2143 
2144  static std::string
2145  to_string(const T & t,
2146  const std::unique_ptr<Patterns::PatternBase> &pattern =
2148  {
2149  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
2150  AssertThrow(p,
2151  ExcMessage("I need a List pattern to convert a string "
2152  "to a List compatible type."));
2153 
2154  auto base_p = p->get_base_pattern().clone();
2155  std::string s =
2156  Convert<typename T::value_type>::to_string(t.real(), base_p) +
2157  p->get_separator() + " " +
2159 
2160  AssertThrow(pattern->match(s), ExcNoMatch(s, p));
2161  return s;
2162  }
2163 
2167  static T
2168  to_value(const std::string & s,
2169  const std::unique_ptr<Patterns::PatternBase> &pattern =
2171  {
2172  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
2173 
2174  auto p = dynamic_cast<const Patterns::List *>(pattern.get());
2175  AssertThrow(p,
2176  ExcMessage("I need a List pattern to convert a string "
2177  "to a List compatible type."));
2178 
2179  auto base_p = p->get_base_pattern().clone();
2180 
2181  auto v = Utilities::split_string_list(s, p->get_separator());
2182  AssertDimension(v.size(), 2);
2185  return t;
2186  }
2187  };
2188 
2189  // Strings
2190  template <>
2191  struct Convert<std::string>
2192  {
2193  using T = std::string;
2194 
2195  static std::unique_ptr<Patterns::PatternBase>
2196  to_pattern()
2197  {
2198  return std_cxx14::make_unique<Patterns::Anything>();
2199  }
2200 
2201  static std::string
2202  to_string(const T & t,
2203  const std::unique_ptr<Patterns::PatternBase> &pattern =
2205  {
2206  AssertThrow(pattern->match(t), ExcNoMatch(t, pattern.get()));
2207  return t;
2208  }
2209 
2210  static T
2211  to_value(const std::string & s,
2212  const std::unique_ptr<Patterns::PatternBase> &pattern =
2214  {
2215  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
2216  return s;
2217  }
2218  };
2219 
2220  // Pairs
2221  template <class Key, class Value>
2222  struct Convert<std::pair<Key, Value>>
2223  {
2224  using T = std::pair<Key, Value>;
2225 
2226  static std::unique_ptr<Patterns::PatternBase>
2227  to_pattern()
2228  {
2229  static_assert(internal::RankInfo<T>::map_rank > 0,
2230  "Cannot use this class for non Map-compatible types.");
2231  return std_cxx14::make_unique<Patterns::Map>(
2234  1,
2235  1,
2236  // We keep the same list separator of the previous level, as this is
2237  // a map with only 1 possible entry
2238  internal::default_list_separator[internal::RankInfo<T>::list_rank],
2239  internal::default_map_separator[internal::RankInfo<T>::map_rank - 1]);
2240  }
2241 
2242  static std::string
2243  to_string(const T & t,
2244  const std::unique_ptr<Patterns::PatternBase> &pattern =
2246  {
2247  std::unordered_map<Key, Value> m;
2248  m.insert(t);
2249  std::string s = Convert<decltype(m)>::to_string(m, pattern);
2250  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
2251  return s;
2252  }
2253 
2254  static T
2255  to_value(const std::string & s,
2256  const std::unique_ptr<Patterns::PatternBase> &pattern =
2258  {
2259  std::unordered_map<Key, Value> m;
2260  m = Convert<decltype(m)>::to_value(s, pattern);
2261  return *m.begin();
2262  }
2263  };
2264 
2265  // Tuples
2266  template <class... Args>
2267  struct Convert<std::tuple<Args...>>
2268  {
2269  using T = std::tuple<Args...>;
2270 
2271  static std::unique_ptr<Patterns::PatternBase>
2272  to_pattern()
2273  {
2274  static_assert(internal::RankInfo<T>::map_rank > 0,
2275  "Cannot use this class for non tuple-compatible types.");
2276  return std_cxx14::make_unique<Patterns::Tuple>(
2277  internal::default_map_separator[internal::RankInfo<T>::map_rank - 1],
2279  }
2280 
2281  static std::string
2282  to_string(const T & t,
2283  const std::unique_ptr<Patterns::PatternBase> &pattern =
2285  {
2286  auto p = dynamic_cast<const Patterns::Tuple *>(pattern.get());
2287  AssertThrow(p,
2288  ExcMessage("I need a Tuple pattern to convert a tuple "
2289  "to a string."));
2290 
2291  const auto string_array = Convert<T>::to_string_internal_2(t, *p);
2292  std::string str;
2293  for (unsigned int i = 0; i < string_array.size(); ++i)
2294  str += (i ? " " + p->get_separator() + " " : "") + string_array[i];
2295  AssertThrow(p->match(str), ExcNoMatch(str, p));
2296  return str;
2297  }
2298 
2299  static T
2300  to_value(const std::string & s,
2301  const std::unique_ptr<Patterns::PatternBase> &pattern =
2303  {
2304  AssertThrow(pattern->match(s), ExcNoMatch(s, pattern.get()));
2305 
2306  auto p = dynamic_cast<const Patterns::Tuple *>(pattern.get());
2307  AssertThrow(p,
2308  ExcMessage("I need a Tuple pattern to convert a string "
2309  "to a tuple type."));
2310 
2311  auto v = Utilities::split_string_list(s, p->get_separator());
2312 
2313  return Convert<T>::to_value_internal_2(v, *p);
2314  }
2315 
2316  private:
2317  template <std::size_t... U>
2318  static std::array<std::string, std::tuple_size<T>::value>
2319  to_string_internal_1(const T & t,
2320  const Patterns::Tuple &pattern,
2321  std_cxx14::index_sequence<U...>)
2322  {
2323  std::array<std::string, std::tuple_size<T>::value> a = {
2324  {Convert<typename std::tuple_element<U, T>::type>::to_string(
2325  std::get<U>(t), pattern.get_pattern(U).clone())...}};
2326  return a;
2327  }
2328 
2329  static std::array<std::string, std::tuple_size<T>::value>
2330  to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
2331  {
2332  return Convert<T>::to_string_internal_1(
2333  t,
2334  pattern,
2335  std_cxx14::make_index_sequence<std::tuple_size<T>::value>{});
2336  }
2337 
2338  template <std::size_t... U>
2339  static T
2340  to_value_internal_1(const std::vector<std::string> &s,
2341  const Patterns::Tuple & pattern,
2342  std_cxx14::index_sequence<U...>)
2343  {
2344  return std::make_tuple(
2345  Convert<typename std::tuple_element<U, T>::type>::to_value(
2346  s[U], pattern.get_pattern(U).clone())...);
2347  }
2348 
2349  static T
2350  to_value_internal_2(const std::vector<std::string> &s,
2351  const Patterns::Tuple & pattern)
2352  {
2353  return Convert<T>::to_value_internal_1(
2354  s,
2355  pattern,
2356  std_cxx14::make_index_sequence<std::tuple_size<T>::value>{});
2357  }
2358  };
2359 
2360  // Utility function with default Pattern
2361  template <typename T>
2362  std::string
2363  to_string(const T &t)
2364  {
2365  return Convert<T>::to_string(t);
2366  }
2367 
2368  // Utility function with default Pattern
2369  template <typename T>
2370  void
2371  to_value(const std::string &s, T &t)
2372  {
2373  t = Convert<T>::to_value(s);
2374  }
2375  } // namespace Tools
2376 } // namespace Patterns
2377 
2378 
2379 DEAL_II_NAMESPACE_CLOSE
2380 
2381 #endif
const std::string & get_separator() const
Definition: patterns.cc:676
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition: utilities.cc:566
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:379
const std::string & get_separator() const
Definition: patterns.cc:1227
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1567
void to_value(const std::string &s, T &t)
Definition: patterns.h:2371
static std::unique_ptr< FileName > create(const std::string &description)
Definition: patterns.cc:1569
std::string sequence
Definition: patterns.h:433
const double upper_bound
Definition: patterns.h:364
static const char * description_init
Definition: patterns.h:369
static const char * description_init
Definition: patterns.h:1148
static std::unique_ptr< Tuple > create(const std::string &description)
Definition: patterns.cc:1171
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1601
const PatternBase & get_pattern(const unsigned int i) const
Definition: patterns.cc:1219
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1426
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:941
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1155
const PatternBase & get_value_pattern() const
Definition: patterns.cc:1028
const std::string separator
Definition: patterns.h:886
static T to_value(const std::string &s, const std::unique_ptr< Patterns::PatternBase > &p=Convert< T >::to_pattern())=delete
const std::string separator
Definition: patterns.h:709
static std::unique_ptr< List > create(const std::string &description)
Definition: patterns.cc:773
std::unique_ptr< PatternBase > pattern
Definition: patterns.h:545
static std::unique_ptr< Patterns::PatternBase > to_pattern()=delete
static const unsigned int max_int_value
Definition: patterns.h:591
virtual std::unique_ptr< PatternBase > clone() const =0
static const char * description_init
Definition: patterns.h:720
std::size_t memory_consumption() const override
Definition: patterns.cc:1360
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1353
STL namespace.
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1451
static const int max_int_value
Definition: patterns.h:203
#define AssertThrow(cond, exc)
Definition: exceptions.h:1519
const std::string & get_separator() const
Definition: patterns.cc:1036
const unsigned int max_elements
Definition: patterns.h:704
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
static const char * description_init
Definition: patterns.h:975
Definition: point.h:110
FileType file_type
Definition: patterns.h:1134
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:239
static std::unique_ptr< Anything > create(const std::string &description)
Definition: patterns.cc:1495
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:479
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:861
static const int min_int_value
Definition: patterns.h:196
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:609
static std::string default_variable_names()
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
const double lower_bound
Definition: patterns.h:356
FileName(const FileType type=input)
Definition: patterns.cc:1510
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:217
static const char * description_init
Definition: patterns.h:565
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:356
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:300
static const char * description_init
Definition: patterns.h:1017
static std::unique_ptr< DirectoryName > create(const std::string &description)
Definition: patterns.cc:1645
std::size_t memory_consumption() const override
Definition: patterns.cc:953
static const char * description_init
Definition: patterns.h:438
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
std::vector< std::unique_ptr< PatternBase > > patterns
Definition: patterns.h:881
const PatternBase & get_key_pattern() const
Definition: patterns.cc:1020
Double(const double lower_bound=min_double_value, const double upper_bound=max_double_value)
Definition: patterns.cc:348
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:650
MultipleSelection(const std::string &seq)
Definition: patterns.cc:1237
virtual std::size_t memory_consumption() const
Definition: patterns.cc:188
static const char * description_init
Definition: patterns.h:271
static std::unique_ptr< Map > create(const std::string &description)
Definition: patterns.cc:965
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:692
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
static const char * description_init
Definition: patterns.h:891
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1252
std::unique_ptr< PatternBase > key_pattern
Definition: patterns.h:693
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1398
const PatternBase & get_base_pattern() const
Definition: patterns.cc:684
std::size_t memory_consumption() const override
Definition: patterns.cc:1162
static std::unique_ptr< Double > create(const std::string &description)
Definition: patterns.cc:487
virtual ~PatternBase()=default
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1318
std::string to_string(const T &t)
Definition: patterns.h:2363
static const double min_double_value
Definition: patterns.h:298
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1086
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
Definition: patterns.cc:136
std::size_t memory_consumption() const override
Definition: patterns.cc:616
static const char * description_init
Definition: patterns.h:1206
const std::string & get_key_value_separator() const
Definition: patterns.cc:1043
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:1517
virtual bool match(const std::string &test_string) const =0
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1561
std::size_t memory_consumption() const override
Definition: patterns.cc:764
static const char * description_init
Definition: patterns.h:1066
__global__ void set(Number *val, const Number s, const size_type N)
static const double max_double_value
Definition: patterns.h:304
static ::ExceptionBase & ExcNoMatch(std::string arg1, const Patterns::PatternBase *arg2)
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1637
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:574
virtual std::string description(const OutputStyle style=Machine) const =0
Definition: mpi.h:90
static std::unique_ptr< MultipleSelection > create(const std::string &description)
Definition: patterns.cc:1369
virtual bool match(const std::string &test_string) const override
Definition: patterns.cc:542
Integer(const int lower_bound=min_int_value, const int upper_bound=max_int_value)
Definition: patterns.cc:209
static std::unique_ptr< Bool > create(const std::string &description)
Definition: patterns.cc:1434
static std::unique_ptr< Selection > create(const std::string &description)
Definition: patterns.cc:625
std::map< std::string, double > ConstMap
const int upper_bound
Definition: patterns.h:266
Selection(const std::string &seq)
Definition: patterns.cc:530
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:821
Tuple(const std::vector< std::unique_ptr< PatternBase >> &patterns, const std::string &separator=":")
Definition: patterns.cc:1053
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:891
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1609
const unsigned int min_elements
Definition: patterns.h:699
static const unsigned int max_int_value
Definition: patterns.h:457
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1525
const int lower_bound
Definition: patterns.h:258
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:712
const std::string separator
Definition: patterns.h:560
const std::string key_value_separator
Definition: patterns.h:715
const unsigned int max_elements
Definition: patterns.h:555
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1105
virtual std::string description(const OutputStyle style=Machine) const override
Definition: patterns.cc:1459
const unsigned int min_elements
Definition: patterns.h:550
static std::unique_ptr< Integer > create(const std::string &description)
Definition: patterns.cc:308
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:1487
virtual std::unique_ptr< PatternBase > clone() const override
Definition: patterns.cc:756
static std::string to_string(const T &s, const std::unique_ptr< Patterns::PatternBase > &p=Convert< T >::to_pattern())=delete