deal.II version GIT relicensing-1989-gd7a2c90e4e 2024-10-14 01:50:00+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\}}\)
Loading...
Searching...
No Matches
patterns.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_patterns_h
16#define dealii_patterns_h
17
18
19#include <deal.II/base/config.h>
20
23#include <deal.II/base/point.h>
26
28
29#include <boost/archive/basic_archive.hpp>
30#include <boost/core/demangle.hpp>
31#include <boost/property_tree/ptree_fwd.hpp>
32#include <boost/property_tree/ptree_serialization.hpp>
33#include <boost/serialization/split_member.hpp>
34
35#include <algorithm>
36#include <array>
37#include <deque>
38#include <limits>
39#include <list>
40#include <map>
41#include <memory>
42#include <set>
43#include <sstream>
44#include <string>
45#include <type_traits>
46#include <unordered_map>
47#include <unordered_set>
48#include <utility>
49#include <vector>
50
51#ifdef DEAL_II_WITH_MAGIC_ENUM
52# include <magic_enum.hpp>
53#endif
54
56
57// forward declarations for interfaces and friendship
58#ifndef DOXYGEN
59class LogStream;
61template <int dim>
62class FunctionParser;
63#endif
64
73namespace Patterns
74{
82 {
83 public:
87 virtual ~PatternBase() = default;
88
92 virtual bool
93 match(const std::string &test_string) const = 0;
94
119
123 virtual std::string
124 description(const OutputStyle style = Machine) const = 0;
125
135 virtual std::unique_ptr<PatternBase>
136 clone() const = 0;
137
153 virtual std::size_t
154 memory_consumption() const;
155 };
156
160 std::unique_ptr<PatternBase>
161 pattern_factory(const std::string &description);
162
163 namespace internal
164 {
170 std::string
171 escape(const std::string &input, const PatternBase::OutputStyle style);
172
173 } // namespace internal
174
191 class Integer : public PatternBase
192 {
193 public:
199 static const int min_int_value;
200
206 static const int max_int_value;
207
221 const int upper_bound = max_int_value);
222
227 virtual bool
228 match(const std::string &test_string) const override;
229
235 virtual std::string
236 description(const OutputStyle style = Machine) const override;
237
243 virtual std::unique_ptr<PatternBase>
244 clone() const override;
245
251 static std::unique_ptr<Integer>
252 create(const std::string &description);
253
254 private:
261 const int lower_bound;
262
269 const int upper_bound;
270
274 static const char *description_init;
275 };
276
294 class Double : public PatternBase
295 {
296 public:
301 static const double min_double_value;
302
307 static const double max_double_value;
308
316 Double(const double lower_bound = min_double_value,
317 const double upper_bound = max_double_value);
318
323 virtual bool
324 match(const std::string &test_string) const override;
325
331 virtual std::string
332 description(const OutputStyle style = Machine) const override;
333
339 virtual std::unique_ptr<PatternBase>
340 clone() const override;
341
349 static std::unique_ptr<Double>
350 create(const std::string &description);
351
352 private:
359 const double lower_bound;
360
367 const double upper_bound;
368
372 static const char *description_init;
373 };
374
384 class Selection : public PatternBase
385 {
386 public:
391 Selection(const std::string &seq);
392
397 virtual bool
398 match(const std::string &test_string) const override;
399
405 virtual std::string
406 description(const OutputStyle style = Machine) const override;
407
413 virtual std::unique_ptr<PatternBase>
414 clone() const override;
415
420 std::size_t
421 memory_consumption() const override;
422
428 static std::unique_ptr<Selection>
429 create(const std::string &description);
430
431 private:
436 std::string sequence;
437
441 static const char *description_init;
442 };
443
444
452 class List : public PatternBase
453 {
454 public:
460 static const unsigned int max_int_value;
461
470 List(const PatternBase &base_pattern,
471 const unsigned int min_elements = 0,
472 const unsigned int max_elements = max_int_value,
473 const std::string &separator = ",");
474
475
479 const std::string &
480 get_separator() const;
481
485 const PatternBase &
486 get_base_pattern() const;
487
491 List(const List &other);
492
497 virtual bool
498 match(const std::string &test_string) const override;
499
504 virtual std::string
505 description(const OutputStyle style = Machine) const override;
506
512 virtual std::unique_ptr<PatternBase>
513 clone() const override;
514
520 static std::unique_ptr<List>
521 create(const std::string &description);
522
527 std::size_t
528 memory_consumption() const override;
529
539 int,
540 int,
541 << "The values " << arg1 << " and " << arg2
542 << " do not form a valid range.");
544 private:
548 std::unique_ptr<PatternBase> pattern;
549
553 const unsigned int min_elements;
554
558 const unsigned int max_elements;
559
563 const std::string separator;
564
568 static const char *description_init;
569 };
570
571
586 class Map : public PatternBase
587 {
588 public:
594 static const unsigned int max_int_value;
595
606 const unsigned int min_elements = 0,
607 const unsigned int max_elements = max_int_value,
608 const std::string &separator = ",",
609 const std::string &key_value_separator = ":");
610
614 Map(const Map &other);
615
620 virtual bool
621 match(const std::string &test_string) const override;
622
627 virtual std::string
628 description(const OutputStyle style = Machine) const override;
629
635 virtual std::unique_ptr<PatternBase>
636 clone() const override;
637
643 static std::unique_ptr<Map>
644 create(const std::string &description);
645
650 std::size_t
651 memory_consumption() const override;
652
656 const PatternBase &
657 get_key_pattern() const;
658
662 const PatternBase &
663 get_value_pattern() const;
664
668 const std::string &
669 get_separator() const;
670
674 const std::string &
676
686 int,
687 int,
688 << "The values " << arg1 << " and " << arg2
689 << " do not form a valid range.");
691 private:
696 std::unique_ptr<PatternBase> key_pattern;
697 std::unique_ptr<PatternBase> value_pattern;
698
702 const unsigned int min_elements;
703
707 const unsigned int max_elements;
708
712 const std::string separator;
713
714
718 const std::string key_value_separator;
719
723 static const char *description_init;
724 };
725
726
727
773 class Tuple : public PatternBase
774 {
775 public:
784 Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
785 const std::string &separator = ":");
786
792 Tuple(const std::vector<std::unique_ptr<PatternBase>> &patterns,
793 const char *separator);
794
795
803 template <class... PatternTypes>
804 Tuple(const std::string &separator, const PatternTypes &...patterns);
805
813 template <class... PatternTypes>
814 Tuple(const char *separator, const PatternTypes &...patterns);
815
821 template <typename... Patterns>
823
827 Tuple(const Tuple &other);
828
833 virtual bool
834 match(const std::string &test_string) const override;
835
840 virtual std::string
841 description(const OutputStyle style = Machine) const override;
842
848 virtual std::unique_ptr<PatternBase>
849 clone() const override;
850
856 static std::unique_ptr<Tuple>
857 create(const std::string &description);
858
863 std::size_t
864 memory_consumption() const override;
865
869 const PatternBase &
870 get_pattern(const unsigned int i) const;
871
875 const std::string &
876 get_separator() const;
877
878 private:
882 std::vector<std::unique_ptr<PatternBase>> patterns;
883
887 const std::string separator;
888
892 static const char *description_init;
893 };
894
895
907 {
908 public:
912 MultipleSelection(const std::string &seq);
913
918 virtual bool
919 match(const std::string &test_string) const override;
920
926 virtual std::string
927 description(const OutputStyle style = Machine) const override;
928
934 virtual std::unique_ptr<PatternBase>
935 clone() const override;
936
942 static std::unique_ptr<MultipleSelection>
943 create(const std::string &description);
944
949 std::size_t
950 memory_consumption() const override;
951
962 int,
963 << "A comma was found at position " << arg1
964 << " of your input string, but commas are not allowed here.");
966 private:
971 std::string sequence;
972
976 static const char *description_init;
977 };
978
983 class Bool : public Selection
984 {
985 public:
989 Bool();
990
995 virtual std::string
996 description(const OutputStyle style = Machine) const override;
997
1003 virtual std::unique_ptr<PatternBase>
1004 clone() const override;
1005
1011 static std::unique_ptr<Bool>
1012 create(const std::string &description);
1013
1014 private:
1018 static const char *description_init;
1019 };
1020
1024 class Anything : public PatternBase
1025 {
1026 public:
1031 Anything() = default;
1032
1037 virtual bool
1038 match(const std::string &test_string) const override;
1039
1044 virtual std::string
1045 description(const OutputStyle style = Machine) const override;
1046
1052 virtual std::unique_ptr<PatternBase>
1053 clone() const override;
1054
1060 static std::unique_ptr<Anything>
1061 create(const std::string &description);
1062
1063 private:
1067 static const char *description_init;
1068 };
1069
1070
1085 class FileName : public PatternBase
1086 {
1087 public:
1093 {
1101 output = 1
1103
1108 FileName(const FileType type = input);
1109
1114 virtual bool
1115 match(const std::string &test_string) const override;
1116
1121 virtual std::string
1122 description(const OutputStyle style = Machine) const override;
1123
1129 virtual std::unique_ptr<PatternBase>
1130 clone() const override;
1131
1136
1142 static std::unique_ptr<FileName>
1143 create(const std::string &description);
1144
1145 private:
1149 static const char *description_init;
1150 };
1151
1152
1166 {
1167 public:
1171 DirectoryName() = default;
1172
1177 virtual bool
1178 match(const std::string &test_string) const override;
1179
1184 virtual std::string
1185 description(const OutputStyle style = Machine) const override;
1186
1192 virtual std::unique_ptr<PatternBase>
1193 clone() const override;
1194
1200 static std::unique_ptr<DirectoryName>
1201 create(const std::string &description);
1202
1203 private:
1207 static const char *description_init;
1208 };
1209
1210
1289 namespace Tools
1290 {
1300 template <class T, class Enable = void>
1301 struct Convert
1302 {
1312 static std::unique_ptr<Patterns::PatternBase>
1313 to_pattern() = delete;
1314
1325 static std::string
1326 to_string(const T &s,
1328 delete;
1329
1339 static T
1340 to_value(const std::string &s,
1342 delete;
1343 };
1344
1363 template <typename T>
1364 std::string
1365 to_string(const T &t);
1366
1392 template <typename T>
1393 void
1394 to_value(const std::string &s, T &t);
1395
1405 std::string,
1406 std::string,
1407 << "The string \"" << arg1
1408 << "\" does not match the pattern \"" << arg2 << "\"");
1410 } // namespace Tools
1411} // namespace Patterns
1412
1413
1414// ---------------------- inline and template functions --------------------
1415namespace Patterns
1416{
1417 template <class... PatternTypes>
1418 Tuple::Tuple(const char *separator, const PatternTypes &...ps)
1419 : // forward to the version with std::string argument
1420 Tuple(std::string(separator), ps...)
1421 {}
1422
1423
1424
1425 template <class... PatternTypes>
1426 Tuple::Tuple(const std::string &separator, const PatternTypes &...ps)
1427 : separator(separator)
1428 {
1429 static_assert(is_base_of_all<PatternBase, PatternTypes...>::value,
1430 "Not all of the input arguments of this function "
1431 "are derived from PatternBase");
1432 static_assert(sizeof...(ps) > 0,
1433 "The number of PatternTypes must be greater than zero!");
1434 const auto pattern_pointers = {(static_cast<const PatternBase *>(&ps))...};
1435 for (const auto p : pattern_pointers)
1436 patterns.push_back(p->clone());
1437 }
1438
1439
1440
1441 template <class... PatternTypes>
1442 Tuple::Tuple(const PatternTypes &...ps)
1443 : // forward to the version with the separator argument
1444 Tuple(std::string(":"), ps...)
1445 {}
1446
1447
1448
1449 namespace Tools
1450 {
1451 namespace internal
1452 {
1477 template <class T, class Enable = void>
1479 {
1480 static constexpr int list_rank = 0;
1481 static constexpr int map_rank = 0;
1482 };
1483 } // namespace internal
1484
1485 // Arithmetic types
1486 template <class T>
1487 struct Convert<T, std::enable_if_t<std::is_arithmetic_v<T>>>
1488 {
1489 template <typename Dummy = T>
1490 static std::enable_if_t<std::is_same_v<Dummy, T> &&
1491 std::is_same_v<T, bool>,
1492 std::unique_ptr<Patterns::PatternBase>>
1494 {
1495 return std::make_unique<Patterns::Bool>();
1496 }
1497
1498 template <typename Dummy = T>
1499 static std::enable_if_t<std::is_same_v<Dummy, T> &&
1500 !std::is_same_v<T, bool> &&
1501 std::is_integral_v<T>,
1502 std::unique_ptr<Patterns::PatternBase>>
1504 {
1505 return std::make_unique<Patterns::Integer>(
1506 std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1507 }
1508
1509 template <typename Dummy = T>
1510 static std::enable_if_t<std::is_same_v<Dummy, T> &&
1511 !std::is_same_v<T, bool> &&
1512 std::is_floating_point_v<T>,
1513 std::unique_ptr<Patterns::PatternBase>>
1515 {
1516 return std::make_unique<Patterns::Double>(
1517 std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
1518 }
1519
1520 static std::string
1521 to_string(const T &value,
1523 {
1524 std::stringstream str;
1525 if (std::is_same_v<T, unsigned char> ||
1526 std::is_same_v<T, signed char> || std::is_same_v<T, char>)
1527 str << static_cast<int>(value);
1528 else if (std::is_same_v<T, bool>)
1529 str << (static_cast<bool>(value) ? "true" : "false");
1530 else
1531 str << value;
1532 AssertThrow(p.match(str.str()), ExcNoMatch(str.str(), p.description()));
1533 return str.str();
1534 }
1535
1536 static T
1537 to_value(const std::string &s,
1539 {
1540 AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
1541 T value;
1542 if (std::is_same_v<T, bool>)
1543 value = (s == "true");
1544 else
1545 {
1546 std::istringstream is(s);
1547 if (std::is_same_v<T, unsigned char> ||
1548 std::is_same_v<T, signed char> || std::is_same_v<T, char>)
1549 {
1550 int i;
1551 is >> i;
1552 value = i;
1553 }
1554 else
1555 is >> value;
1556
1557 // If someone passes "123 abc" to the function, the method yields an
1558 // integer 123 alright, but the space terminates the read from the
1559 // string although there is more to come. This case, however, is
1560 // checked for in the call p->match(s) at the beginning of this
1561 // function, and would throw earlier. Here it is safe to assume that
1562 // if we didn't fail the conversion with the operator >>, then we
1563 // are good to go.
1565 !is.fail(),
1566 ExcMessage("Failed to convert from \"" + s + "\" to the type \"" +
1567 boost::core::demangle(typeid(T).name()) + "\""));
1568 }
1569 return value;
1570 }
1571 };
1572
1573 namespace internal
1574 {
1575 constexpr std::array<const char *, 4> default_list_separator{
1576 {",", ";", "|", "%"}};
1577 constexpr std::array<const char *, 4> default_map_separator{
1578 {":", "=", "@", "#"}};
1579
1580 // specialize a type for all of the STL containers and maps
1581 template <typename T>
1582 struct is_list_compatible : std::false_type
1583 {};
1584 template <typename... Args>
1585 struct is_list_compatible<std::vector<Args...>> : std::true_type
1586 {};
1587 template <typename... Args>
1588 struct is_list_compatible<std::deque<Args...>> : std::true_type
1589 {};
1590 template <typename... Args>
1591 struct is_list_compatible<std::list<Args...>> : std::true_type
1592 {};
1593 template <typename... Args>
1594 struct is_list_compatible<std::set<Args...>> : std::true_type
1595 {};
1596 template <typename... Args>
1597 struct is_list_compatible<std::multiset<Args...>> : std::true_type
1598 {};
1599 template <typename... Args>
1600 struct is_list_compatible<std::unordered_set<Args...>> : std::true_type
1601 {};
1602 template <typename... Args>
1603 struct is_list_compatible<std::unordered_multiset<Args...>>
1604 : std::true_type
1605 {};
1606
1607 template <typename T>
1608 struct is_map_compatible : std::false_type
1609 {};
1610 template <class Key, class T, class Compare, class Allocator>
1611 struct is_map_compatible<std::map<Key, T, Compare, Allocator>>
1612 : std::true_type
1613 {};
1614 template <class Key, class T, class Compare, class Allocator>
1615 struct is_map_compatible<std::multimap<Key, T, Compare, Allocator>>
1616 : std::true_type
1617 {};
1618 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1620 std::unordered_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type
1621 {};
1622 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
1624 std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>>
1625 : std::true_type
1626 {};
1627 } // namespace internal
1628
1629 // type trait to use the implementation type traits as well as decay the
1630 // type
1631 template <typename T>
1633 {
1634 static constexpr const bool value =
1636 };
1637
1638 template <typename T>
1640 {
1641 static constexpr const bool value =
1643 };
1644
1645 namespace internal
1646 {
1647 // Helper function for list_rank
1648 template <class T>
1649 constexpr int
1651 {
1653 }
1654
1655 template <class T1, class T2, class... Types>
1656 constexpr int
1658 {
1659 return std::max(RankInfo<T1>::list_rank, max_list_rank<T2, Types...>());
1660 }
1661
1662 // Helper function for map_rank
1663 template <class T>
1664 constexpr int
1666 {
1667 return RankInfo<T>::map_rank;
1668 }
1669
1670 template <class T1, class T2, class... Types>
1671 constexpr int
1673 {
1674 return std::max(RankInfo<T1>::map_rank, max_map_rank<T2, Types...>());
1675 }
1676
1677 // Rank of vector types
1678 template <class T>
1679 struct RankInfo<T, std::enable_if_t<is_list_compatible<T>::value>>
1680 {
1681 static constexpr int list_rank =
1683 static constexpr int map_rank =
1685 };
1686
1687 // Rank of map types
1688 template <class T>
1689 struct RankInfo<T, std::enable_if_t<is_map_compatible<T>::value>>
1690 {
1691 static constexpr int list_rank =
1692 max_list_rank<typename T::key_type, typename T::mapped_type>() + 1;
1693 static constexpr int map_rank =
1694 max_map_rank<typename T::key_type, typename T::mapped_type>() + 1;
1695 };
1696
1697 // Rank of Tensor types
1698 template <int rank, int dim, class Number>
1699 struct RankInfo<Tensor<rank, dim, Number>>
1700 {
1701 static constexpr int list_rank = rank + RankInfo<Number>::list_rank;
1702 static constexpr int map_rank = RankInfo<Number>::map_rank;
1703 };
1704
1705 template <int dim, class Number>
1706 struct RankInfo<Point<dim, Number>> : RankInfo<Tensor<1, dim, Number>>
1707 {};
1708
1709 // Rank of complex types
1710 template <class Number>
1711 struct RankInfo<std::complex<Number>>
1712 {
1713 static constexpr int list_rank = RankInfo<Number>::list_rank + 1;
1714 static constexpr int map_rank = RankInfo<Number>::map_rank;
1715 };
1716
1717 // Rank of FunctionParser
1718 template <int dim>
1719 struct RankInfo<std::unique_ptr<FunctionParser<dim>>>
1720 {
1721 static constexpr int list_rank = 1;
1722 static constexpr int map_rank = 0;
1723 };
1724
1725 // Rank of ComponentMask
1726 template <>
1728 {
1729 static constexpr int list_rank = 1;
1730 static constexpr int map_rank = 0;
1731 };
1732
1733 // Rank of std::pair
1734 template <class Key, class Value>
1735 struct RankInfo<std::pair<Key, Value>>
1736 {
1737 static constexpr int list_rank =
1739 static constexpr int map_rank =
1741 };
1742
1743 // Rank of std::tuple types
1744 template <class... Types>
1745 struct RankInfo<std::tuple<Types...>>
1746 {
1747 static constexpr int list_rank = max_list_rank<Types...>();
1748 static constexpr int map_rank = max_map_rank<Types...>() + 1;
1749 };
1750
1751 // Rank of std::array types
1752 template <class T, std::size_t N>
1753 struct RankInfo<std::array<T, N>>
1754 {
1755 static constexpr int list_rank = RankInfo<T>::list_rank + 1;
1756 static constexpr int map_rank = RankInfo<T>::map_rank;
1757 };
1758 } // namespace internal
1759
1760 // stl containers
1761 template <class T>
1762 struct Convert<T, std::enable_if_t<is_list_compatible<T>::value>>
1763 {
1764 static std::unique_ptr<Patterns::PatternBase>
1766 {
1767 static_assert(internal::RankInfo<T>::list_rank > 0,
1768 "Cannot use this class for non List-compatible types.");
1769 return std::make_unique<Patterns::List>(
1771 0,
1772 std::numeric_limits<unsigned int>::max(),
1774 1]);
1775 }
1776
1777 static std::string
1779 const T &t,
1781 {
1782 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1783 AssertThrow(p,
1784 ExcMessage("I need a List pattern to convert a "
1785 "string to a List type."));
1786 auto base_p = p->get_base_pattern().clone();
1787 std::vector<std::string> vec(t.size());
1788
1789 std::transform(
1790 t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1791 return Convert<typename T::value_type>::to_string(entry, *base_p);
1792 });
1793
1794 std::string s;
1795 if (vec.size() > 0)
1796 s = vec[0];
1797 for (unsigned int i = 1; i < vec.size(); ++i)
1798 s += p->get_separator() + " " + vec[i];
1799
1800 AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1801 return s;
1802 }
1803
1804 static T
1805 to_value(const std::string &s,
1807 {
1808 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1809
1810 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1811 AssertThrow(p,
1812 ExcMessage("I need a List pattern to convert a string "
1813 "to a List type."));
1814
1815 auto base_p = p->get_base_pattern().clone();
1816 T t;
1817
1818 auto v = Utilities::split_string_list(s, p->get_separator());
1819 for (const auto &str : v)
1820 t.insert(t.end(),
1822
1823 return t;
1824 }
1825 };
1826
1827 // stl maps
1828 template <class T>
1829 struct Convert<T, std::enable_if_t<is_map_compatible<T>::value>>
1830 {
1831 static std::unique_ptr<Patterns::PatternBase>
1833 {
1834 static_assert(internal::RankInfo<T>::list_rank > 0,
1835 "Cannot use this class for non List-compatible types.");
1836 static_assert(internal::RankInfo<T>::map_rank > 0,
1837 "Cannot use this class for non Map-compatible types.");
1838 return std::make_unique<Patterns::Map>(
1841 0,
1842 std::numeric_limits<unsigned int>::max(),
1844 1],
1846 }
1847
1848 static std::string
1850 const T &t,
1852 {
1853 const auto *p = dynamic_cast<const Patterns::Map *>(&pattern);
1854 AssertThrow(p,
1855 ExcMessage("I need a Map pattern to convert a string to "
1856 "a Map compatible type."));
1857 auto key_p = p->get_key_pattern().clone();
1858 auto val_p = p->get_value_pattern().clone();
1859 std::vector<std::string> vec(t.size());
1860
1861 unsigned int i = 0;
1862 for (const auto &ti : t)
1863 vec[i++] =
1865 p->get_key_value_separator() +
1867
1868 std::string s;
1869 if (vec.size() > 0)
1870 s = vec[0];
1871 for (unsigned int i = 1; i < vec.size(); ++i)
1872 s += p->get_separator() + " " + vec[i];
1873
1874 AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
1875 return s;
1876 }
1877
1878 static T
1879 to_value(const std::string &s,
1881 {
1882 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1883
1884 const auto *p = dynamic_cast<const Patterns::Map *>(&pattern);
1885 AssertThrow(p,
1886 ExcMessage("I need a Map pattern to convert a "
1887 "string to a Map compatible type."));
1888
1889 auto key_p = p->get_key_pattern().clone();
1890 auto val_p = p->get_value_pattern().clone();
1891 T t;
1892
1893 auto v = Utilities::split_string_list(s, p->get_separator());
1894 for (const auto &str : v)
1895 {
1896 auto key_val =
1897 Utilities::split_string_list(str, p->get_key_value_separator());
1898 AssertDimension(key_val.size(), 2);
1899 t.insert(std::make_pair(
1900 Convert<typename T::key_type>::to_value(key_val[0], *key_p),
1901 Convert<typename T::mapped_type>::to_value(key_val[1], *val_p)));
1902 }
1903
1904 return t;
1905 }
1906 };
1907
1908 // std::array
1909 template <typename ValueType, std::size_t N>
1910 struct Convert<std::array<ValueType, N>>
1911 {
1912 using T = std::array<ValueType, N>;
1913
1914 static std::unique_ptr<Patterns::PatternBase>
1916 {
1917 static_assert(internal::RankInfo<T>::list_rank > 0,
1918 "Cannot use this class for non List-compatible types.");
1919 return std::make_unique<Patterns::List>(
1921 N,
1922 N,
1924 1]);
1925 }
1926
1927 static std::string
1929 const T &t,
1931 {
1932 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1933 AssertThrow(p,
1934 ExcMessage("I need a List pattern to convert a "
1935 "string to a std::array."));
1936 auto base_p = p->get_base_pattern().clone();
1937 std::vector<std::string> vec(t.size());
1938
1939 std::transform(
1940 t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
1941 return Convert<typename T::value_type>::to_string(entry, *base_p);
1942 });
1943
1944 std::string s;
1945 if (vec.size() > 0)
1946 s = vec[0];
1947 for (unsigned int i = 1; i < vec.size(); ++i)
1948 s += p->get_separator() + " " + vec[i];
1949
1950 AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
1951 return s;
1952 }
1953
1954 static T
1955 to_value(const std::string &s,
1957 {
1958 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
1959
1960 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
1961 AssertThrow(p,
1962 ExcMessage("I need a List pattern to convert a string "
1963 "to a std::array."));
1964
1965 auto base_p = p->get_base_pattern().clone();
1966 T t;
1967
1968 auto v = Utilities::split_string_list(s, p->get_separator());
1969 AssertDimension(v.size(), N);
1970 for (unsigned int i = 0; i < N; ++i)
1971 t[i] = Convert<typename T::value_type>::to_value(v[i], *base_p);
1972 return t;
1973 }
1974 };
1975
1976 // Tensors
1977 template <int rank, int dim, class Number>
1978 struct Convert<Tensor<rank, dim, Number>>
1979 {
1981 static std::unique_ptr<Patterns::PatternBase>
1983 {
1984 static_assert(internal::RankInfo<T>::list_rank > 0,
1985 "Cannot use this class for non List-compatible types.");
1986 return std::make_unique<Patterns::List>(
1988 dim,
1989 dim,
1991 1]);
1992 }
1993
1994 static std::string
1996 const T &t,
1998 {
1999 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2000 AssertThrow(p,
2001 ExcMessage("I need a List pattern to convert a string "
2002 "to a List compatible type."));
2003 auto base_p = p->get_base_pattern().clone();
2004 std::vector<std::string> vec(dim);
2005
2006 for (unsigned int i = 0; i < dim; ++i)
2007 vec[i] = Convert<typename T::value_type>::to_string(t[i], *base_p);
2008
2009 std::string s;
2010 if (vec.size() > 0)
2011 s = vec[0];
2012 for (unsigned int i = 1; i < vec.size(); ++i)
2013 s += p->get_separator() + " " + vec[i];
2014
2015 AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
2016 return s;
2017 }
2018
2019 static T
2020 to_value(const std::string &s,
2022 {
2023 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2024
2025 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2026 AssertThrow(p,
2027 ExcMessage("I need a List pattern to convert a string "
2028 "to a List compatible type."));
2029
2030 auto base_p = p->get_base_pattern().clone();
2031 T t;
2032
2033 auto v = Utilities::split_string_list(s, p->get_separator());
2034 unsigned int i = 0;
2035 for (const auto &str : v)
2036 t[i++] = Convert<typename T::value_type>::to_value(str, *base_p);
2037
2038 return t;
2039 }
2040 };
2041
2042 // Points
2043 template <int dim, class Number>
2044 struct Convert<Point<dim, Number>>
2045 {
2047
2048 static std::unique_ptr<Patterns::PatternBase>
2053
2054 static std::string
2056 const T &t,
2058 {
2060 Tensor<1, dim, Number>(t), pattern);
2061 }
2062
2063 static T
2064 to_value(const std::string &s,
2066 {
2067 return T(Convert<Tensor<1, dim, Number>>::to_value(s, pattern));
2068 }
2069 };
2070
2071 // Functions::FunctionParser
2072 template <int dim>
2073 struct Convert<std::unique_ptr<FunctionParser<dim>>>
2074 {
2075 using T = std::unique_ptr<FunctionParser<dim>>;
2076
2077 static std::unique_ptr<Patterns::PatternBase>
2079 {
2080 static_assert(internal::RankInfo<T>::list_rank > 0,
2081 "Cannot use this class for non List-compatible types.");
2082
2083 return std::make_unique<Patterns::List>(
2085 1,
2088 1]);
2089 }
2090
2091 static std::string
2093 const T &t,
2095 {
2096 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2097 AssertThrow(p,
2098 ExcMessage("I need a List pattern to convert a string "
2099 "to a List compatible type."));
2100
2101 const auto &expressions = t->get_expressions();
2102 if (expressions.empty())
2103 return std::string();
2104
2105 std::string s = expressions[0];
2106 for (unsigned int i = 1; i < expressions.size(); ++i)
2107 s = s + p->get_separator() + expressions[i];
2108
2109 AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2110 return s;
2111 }
2112
2113 static T
2114 to_value(const std::string &s,
2116 {
2117 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2118
2119 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2120 AssertThrow(p,
2121 ExcMessage("I need a List pattern to convert a string "
2122 "to a List compatible type."));
2123
2124 const auto expressions =
2125 Utilities::split_string_list(s, p->get_separator());
2126
2127 T t = std::make_unique<FunctionParser<dim>>(expressions.size());
2128 const std::string var =
2130 const typename FunctionParser<dim>::ConstMap constants;
2131 t->initialize(var, expressions, constants, true);
2132 return t;
2133 }
2134 };
2135
2136 // ComponentMask
2137 template <>
2139 {
2141
2142 static std::unique_ptr<Patterns::PatternBase>
2144 {
2146 }
2147
2148 static std::string
2150 const T &t,
2152 {
2153 std::vector<bool> mask(t.size());
2154 for (unsigned int i = 0; i < t.size(); ++i)
2155 mask[i] = t[i];
2156
2157 return Convert<std::vector<bool>>::to_string(mask, pattern);
2158 }
2159
2160 static T
2161 to_value(const std::string &s,
2163 {
2164 const auto mask = Convert<std::vector<bool>>::to_value(s, pattern);
2165 return ComponentMask(mask);
2166 }
2167 };
2168
2169 // Complex numbers
2170 template <class Number>
2171 struct Convert<std::complex<Number>>
2172 {
2173 using T = std::complex<Number>;
2174
2175 static std::unique_ptr<Patterns::PatternBase>
2177 {
2178 static_assert(internal::RankInfo<T>::list_rank > 0,
2179 "Cannot use this class for non List-compatible types.");
2180 return std::make_unique<Patterns::List>(
2182 2,
2183 2,
2185 1]);
2186 }
2187
2188 static std::string
2190 const T &t,
2192 {
2193 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2194 AssertThrow(p,
2195 ExcMessage("I need a List pattern to convert a string "
2196 "to a List compatible type."));
2197
2198 auto base_p = p->get_base_pattern().clone();
2199 std::string s =
2201 p->get_separator() + " " +
2203
2204 AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
2205 return s;
2206 }
2207
2211 static T
2212 to_value(const std::string &s,
2214 {
2215 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2216
2217 const auto *p = dynamic_cast<const Patterns::List *>(&pattern);
2218 AssertThrow(p,
2219 ExcMessage("I need a List pattern to convert a string "
2220 "to a List compatible type."));
2221
2222 auto base_p = p->get_base_pattern().clone();
2223
2224 auto v = Utilities::split_string_list(s, p->get_separator());
2225 AssertDimension(v.size(), 2);
2228 return t;
2229 }
2230 };
2231
2232 // Strings
2233 template <>
2234 struct Convert<std::string>
2235 {
2236 using T = std::string;
2237
2238 static std::unique_ptr<Patterns::PatternBase>
2240 {
2241 return std::make_unique<Patterns::Anything>();
2242 }
2243
2244 static std::string
2246 const T &t,
2248 {
2249 AssertThrow(pattern.match(t), ExcNoMatch(t, pattern.description()));
2250 return t;
2251 }
2252
2253 static T
2254 to_value(const std::string &s,
2256 {
2257 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2258 return s;
2259 }
2260 };
2261
2262 // Pairs
2263 template <class Key, class Value>
2264 struct Convert<std::pair<Key, Value>>
2265 {
2266 using T = std::pair<Key, Value>;
2267
2268 static std::unique_ptr<Patterns::PatternBase>
2270 {
2271 static_assert(internal::RankInfo<T>::map_rank > 0,
2272 "Cannot use this class for non Map-compatible types.");
2273 return std::make_unique<Patterns::Tuple>(
2277 }
2278
2279 static std::string
2281 const T &t,
2283 {
2284 std::tuple<Key, Value> m(t);
2285 std::string s = Convert<decltype(m)>::to_string(m, pattern);
2286 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2287 return s;
2288 }
2289
2290 static T
2291 to_value(const std::string &s,
2293 {
2294 std::tuple<Key, Value> m;
2295 m = Convert<decltype(m)>::to_value(s, pattern);
2296 return std::make_pair(std::get<0>(m), std::get<1>(m));
2297 }
2298 };
2299
2300 // Tuples
2301 template <class... Args>
2302 struct Convert<std::tuple<Args...>>
2303 {
2304 using T = std::tuple<Args...>;
2305
2306 static std::unique_ptr<Patterns::PatternBase>
2308 {
2309 static_assert(internal::RankInfo<T>::map_rank > 0,
2310 "Cannot use this class for non tuple-compatible types.");
2311 return std::make_unique<Patterns::Tuple>(
2314 }
2315
2316 static std::string
2318 const T &t,
2320 {
2321 const auto *p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2322 AssertThrow(p,
2323 ExcMessage("I need a Tuple pattern to convert a tuple "
2324 "to a string."));
2325
2326 const auto string_array = Convert<T>::to_string_internal_2(t, *p);
2327 std::string str;
2328 for (unsigned int i = 0; i < string_array.size(); ++i)
2329 str +=
2330 (i != 0u ? " " + p->get_separator() + " " : "") + string_array[i];
2331 AssertThrow(p->match(str), ExcNoMatch(str, p->description()));
2332 return str;
2333 }
2334
2335 static T
2336 to_value(const std::string &s,
2338 {
2339 AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
2340
2341 const auto *p = dynamic_cast<const Patterns::Tuple *>(&pattern);
2342 AssertThrow(p,
2343 ExcMessage("I need a Tuple pattern to convert a string "
2344 "to a tuple type."));
2345
2346 auto v = Utilities::split_string_list(s, p->get_separator());
2347
2348 return Convert<T>::to_value_internal_2(v, *p);
2349 }
2350
2351 private:
2352 template <std::size_t... U>
2353 static std::array<std::string, std::tuple_size<T>::value>
2355 const Patterns::Tuple &pattern,
2356 std::index_sequence<U...>)
2357 {
2358 std::array<std::string, std::tuple_size<T>::value> a = {
2360 std::get<U>(t), pattern.get_pattern(U))...}};
2361 return a;
2362 }
2363
2364 static std::array<std::string, std::tuple_size<T>::value>
2365 to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
2366 {
2368 t, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2369 }
2370
2371 template <std::size_t... U>
2372 static T
2373 to_value_internal_1(const std::vector<std::string> &s,
2374 const Patterns::Tuple &pattern,
2375 std::index_sequence<U...>)
2376 {
2377 return std::make_tuple(
2378 Convert<typename std::tuple_element<U, T>::type>::to_value(
2379 s[U], pattern.get_pattern(U))...);
2380 }
2381
2382 static T
2383 to_value_internal_2(const std::vector<std::string> &s,
2384 const Patterns::Tuple &pattern)
2385 {
2387 s, pattern, std::make_index_sequence<std::tuple_size<T>::value>{});
2388 }
2389 };
2390
2391#ifdef DEAL_II_WITH_MAGIC_ENUM
2392 // Enums
2393 template <class T>
2394 struct Convert<T, typename std::enable_if<std::is_enum<T>::value>::type>
2395 {
2396 static std::unique_ptr<Patterns::PatternBase>
2397 to_pattern()
2398 {
2399 const auto n = magic_enum::enum_names<T>();
2400 std::vector<std::string> names = {n.begin(), n.end()};
2401 const auto selection =
2402 Patterns::Tools::Convert<decltype(names)>::to_string(
2403 names,
2405 Patterns::Anything(), names.size(), names.size(), "|"));
2406 // Allow parsing a list of enums, and make bitwise or between them
2407 return Patterns::List(Patterns::Selection(selection),
2408 0,
2409 names.size(),
2410 "|")
2411 .clone();
2412 }
2413
2414 static std::string
2415 to_string(const T &value,
2417 {
2418 const auto values = magic_enum::enum_values<T>();
2419 std::vector<std::string> names;
2420 for (const auto &v : values)
2421 if (magic_enum::bitwise_operators::operator&(value, v) == v)
2422 names.push_back(std::string(magic_enum::enum_name(v)));
2423 return Patterns::Tools::Convert<decltype(names)>::to_string(names, p);
2424 }
2425
2426 static T
2427 to_value(const std::string &s,
2428 const ::Patterns::PatternBase &p = *to_pattern())
2429 {
2430 // Make sure we have a valid enum value, or empty value
2431 AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
2432 T value = T();
2433 std::vector<std::string> value_names;
2434 value_names =
2435 Patterns::Tools::Convert<decltype(value_names)>::to_value(s, p);
2436 for (const auto &name : value_names)
2437 {
2438 auto v = magic_enum::enum_cast<T>(name);
2439 if (v.has_value())
2440 value =
2441 magic_enum::bitwise_operators::operator|(value, v.value());
2442 }
2443 return value;
2444 }
2445 };
2446#endif
2447
2448 // Utility function with default Pattern
2449 template <typename T>
2450 std::string
2451 to_string(const T &t)
2452 {
2453 return Convert<T>::to_string(t);
2454 }
2455
2456 // Utility function with default Pattern
2457 template <typename T>
2458 void
2459 to_value(const std::string &s, T &t)
2460 {
2461 t = Convert<T>::to_value(s);
2462 }
2463 } // namespace Tools
2464} // namespace Patterns
2465
2466
2468
2469#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:1510
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:1466
static const char * description_init
Definition patterns.h:1067
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1474
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1502
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1413
static const char * description_init
Definition patterns.h:1018
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1441
static std::unique_ptr< Bool > create(const std::string &description)
Definition patterns.cc:1449
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1652
static const char * description_init
Definition patterns.h:1207
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1624
static std::unique_ptr< DirectoryName > create(const std::string &description)
Definition patterns.cc:1660
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:1616
static std::unique_ptr< Double > create(const std::string &description)
Definition patterns.cc:488
static const char * description_init
Definition patterns.h:372
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:480
const double lower_bound
Definition patterns.h:359
const double upper_bound
Definition patterns.h:367
static const double max_double_value
Definition patterns.h:307
static const double min_double_value
Definition patterns.h:301
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:380
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:357
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:1532
static const char * description_init
Definition patterns.h:1149
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1576
static std::unique_ptr< FileName > create(const std::string &description)
Definition patterns.cc:1584
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1540
static std::unique_ptr< Integer > create(const std::string &description)
Definition patterns.cc:309
static const char * description_init
Definition patterns.h:274
const int upper_bound
Definition patterns.h:269
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:301
const int lower_bound
Definition patterns.h:261
static const int min_int_value
Definition patterns.h:199
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:240
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:218
static const int max_int_value
Definition patterns.h:206
const unsigned int max_elements
Definition patterns.h:558
static const char * description_init
Definition patterns.h:568
const unsigned int min_elements
Definition patterns.h:553
std::unique_ptr< PatternBase > pattern
Definition patterns.h:548
const std::string separator
Definition patterns.h:563
std::size_t memory_consumption() const override
Definition patterns.cc:765
static std::unique_ptr< List > create(const std::string &description)
Definition patterns.cc:774
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:713
const PatternBase & get_base_pattern() const
Definition patterns.cc:685
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:693
const std::string & get_separator() const
Definition patterns.cc:677
static const unsigned int max_int_value
Definition patterns.h:460
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:757
static std::unique_ptr< Map > create(const std::string &description)
Definition patterns.cc:983
std::unique_ptr< PatternBase > value_pattern
Definition patterns.h:697
const unsigned int min_elements
Definition patterns.h:702
const PatternBase & get_key_pattern() const
Definition patterns.cc:1038
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:879
const unsigned int max_elements
Definition patterns.h:707
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:959
const PatternBase & get_value_pattern() const
Definition patterns.cc:1046
const std::string & get_separator() const
Definition patterns.cc:1054
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:909
static const unsigned int max_int_value
Definition patterns.h:594
std::unique_ptr< PatternBase > key_pattern
Definition patterns.h:696
const std::string separator
Definition patterns.h:712
std::size_t memory_consumption() const override
Definition patterns.cc:971
static const char * description_init
Definition patterns.h:723
const std::string & get_key_value_separator() const
Definition patterns.cc:1061
const std::string key_value_separator
Definition patterns.h:718
static std::unique_ptr< MultipleSelection > create(const std::string &description)
Definition patterns.cc:1384
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:1270
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1368
static const char * description_init
Definition patterns.h:976
std::size_t memory_consumption() const override
Definition patterns.cc:1375
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1333
virtual std::size_t memory_consumption() const
Definition patterns.cc:189
virtual std::unique_ptr< PatternBase > clone() const =0
virtual std::string description(const OutputStyle style=Machine) const =0
virtual bool match(const std::string &test_string) const =0
virtual ~PatternBase()=default
static const char * description_init
Definition patterns.h:441
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:575
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:610
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:543
static std::unique_ptr< Selection > create(const std::string &description)
Definition patterns.cc:626
std::size_t memory_consumption() const override
Definition patterns.cc:617
std::string sequence
Definition patterns.h:436
virtual bool match(const std::string &test_string) const override
Definition patterns.cc:1104
std::size_t memory_consumption() const override
Definition patterns.cc:1180
static std::unique_ptr< Tuple > create(const std::string &description)
Definition patterns.cc:1189
std::vector< std::unique_ptr< PatternBase > > patterns
Definition patterns.h:882
virtual std::unique_ptr< PatternBase > clone() const override
Definition patterns.cc:1173
Tuple(const Patterns &...patterns)
const std::string separator
Definition patterns.h:887
static const char * description_init
Definition patterns.h:892
Tuple(const std::vector< std::unique_ptr< PatternBase > > &patterns, const std::string &separator=":")
Definition patterns.cc:1071
const std::string & get_separator() const
Definition patterns.cc:1245
const PatternBase & get_pattern(const unsigned int i) const
Definition patterns.cc:1237
virtual std::string description(const OutputStyle style=Machine) const override
Definition patterns.cc:1123
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
static ::ExceptionBase & ExcInvalidRange(int arg1, int arg2)
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:534
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcCommasNotAllowed(int arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:511
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
constexpr std::array< const char *, 4 > default_map_separator
Definition patterns.h:1577
constexpr int max_map_rank()
Definition patterns.h:1665
constexpr int max_list_rank()
Definition patterns.h:1650
constexpr std::array< const char *, 4 > default_list_separator
Definition patterns.h:1575
void to_value(const std::string &s, T &t)
Definition patterns.h:2459
std::string to_string(const T &t)
Definition patterns.h:2451
std::string escape(const std::string &input, const PatternBase::OutputStyle style)
Definition patterns.cc:52
std::unique_ptr< PatternBase > pattern_factory(const std::string &description)
Definition patterns.cc:137
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition utilities.cc:701
STL namespace.
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2143
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2161
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2149
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2049
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2055
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2064
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1805
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1778
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1849
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1879
static std::enable_if_t< std::is_same_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:1514
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition patterns.h:1537
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:1503
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:1493
static std::string to_string(const T &value, const Patterns::PatternBase &p= *Convert< T >::to_pattern())
Definition patterns.h:1521
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:1982
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2020
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1995
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:1915
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1955
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:1928
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2176
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2212
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2189
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2269
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2291
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2280
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2239
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2254
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2245
static T to_value_internal_2(const std::vector< std::string > &s, const Patterns::Tuple &pattern)
Definition patterns.h:2383
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2336
static std::array< std::string, std::tuple_size< T >::value > to_string_internal_2(const T &t, const Patterns::Tuple &pattern)
Definition patterns.h:2365
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2307
static std::array< std::string, std::tuple_size< T >::value > to_string_internal_1(const T &t, const Patterns::Tuple &pattern, std::index_sequence< U... >)
Definition patterns.h:2354
static T to_value_internal_1(const std::vector< std::string > &s, const Patterns::Tuple &pattern, std::index_sequence< U... >)
Definition patterns.h:2373
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2317
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition patterns.h:2078
static T to_value(const std::string &s, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2114
static std::string to_string(const T &t, const Patterns::PatternBase &pattern= *Convert< T >::to_pattern())
Definition patterns.h:2092
static std::unique_ptr< Patterns::PatternBase > to_pattern()=delete
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
static std::string to_string(const T &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
static constexpr int list_rank
Definition patterns.h:1480
static constexpr int map_rank
Definition patterns.h:1481
static constexpr const bool value
Definition patterns.h:1634
static constexpr const bool value
Definition patterns.h:1641