dune-typetree  2.8-git
simpletransformationdescriptors.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
5 #define DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
6 
7 #include <array>
8 #include <memory>
9 
12 #include <dune/common/exceptions.hh>
13 
14 
15 namespace Dune {
16  namespace TypeTree {
17 
23  template<typename SourceNode, typename Transformation, typename TransformedNode>
25  {
26 
27  static const bool recursive = false;
28 
29  typedef TransformedNode transformed_type;
30  typedef std::shared_ptr<transformed_type> transformed_storage_type;
31 
32  static transformed_type transform(const SourceNode& s, const Transformation& t)
33  {
34  return transformed_type();
35  }
36 
37  static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
38  {
39  return std::make_shared<transformed_type>();
40  }
41 
42  };
43 
44 
45  template<typename SourceNode, typename Transformation, template<typename Child, std::size_t> class TransformedNode>
47  {
48 
49  static const bool recursive = true;
50 
51  template<typename TC>
52  struct result
53  {
54  typedef TransformedNode<TC, StaticDegree<SourceNode>::value> type;
55  typedef std::shared_ptr<type> storage_type;
56  static const std::size_t degree = StaticDegree<type>::value;
57  };
58 
59  template<typename TC>
60  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
61  {
62  return typename result<TC>::type(children);
63  }
64 
65  template<typename TC>
66  static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
67  {
68  return std::make_shared<typename result<TC>::type>(children);
69  }
70 
71  };
72 
73 
74  template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNode>
76  {
77 
78  static const bool recursive = true;
79 
80  template<typename TC>
81  struct result
82  {
83  typedef TransformedNode<TC> type;
84  typedef std::shared_ptr<type> storage_type;
85  };
86 
87  template<typename TC>
88  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
89  {
90  return typename result<TC>::type(children);
91  }
92 
93  template<typename TC>
94  static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
95  {
96  return std::make_shared<typename result<TC>::type>(children);
97  }
98 
99  };
100 
101 
102  template<typename SourceNode, typename Transformation, template<typename...> class TransformedNode>
104  {
105 
106  static const bool recursive = true;
107 
108  template<typename... TC>
109  struct result
110  {
111  typedef TransformedNode<TC...> type;
112  typedef std::shared_ptr<type> storage_type;
113  };
114 
115  template<typename... TC>
116  static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
117  {
118  return typename result<TC...>::type(children...);
119  }
120 
121  template<typename... TC>
122  static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
123  {
124  return std::make_shared<typename result<TC...>::type>(children...);
125  }
126 
127  };
128 
130 
131  } // namespace TypeTree
132 } //namespace Dune
133 
134 #endif // DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
decltype(Node::degree()) StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:104
Definition: accumulate_static.hh:13
Definition: simpletransformationdescriptors.hh:25
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition: simpletransformationdescriptors.hh:32
static const bool recursive
Definition: simpletransformationdescriptors.hh:27
std::shared_ptr< transformed_type > transformed_storage_type
Definition: simpletransformationdescriptors.hh:30
static transformed_storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition: simpletransformationdescriptors.hh:37
TransformedNode transformed_type
Definition: simpletransformationdescriptors.hh:29
Definition: simpletransformationdescriptors.hh:47
static result< TC >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::degree > &children)
Definition: simpletransformationdescriptors.hh:66
static const bool recursive
Definition: simpletransformationdescriptors.hh:49
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::degree > &children)
Definition: simpletransformationdescriptors.hh:60
Definition: simpletransformationdescriptors.hh:53
TransformedNode< TC, StaticDegree< SourceNode >::value > type
Definition: simpletransformationdescriptors.hh:54
static const std::size_t degree
Definition: simpletransformationdescriptors.hh:56
std::shared_ptr< type > storage_type
Definition: simpletransformationdescriptors.hh:55
Definition: simpletransformationdescriptors.hh:76
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::vector< std::shared_ptr< TC >> &children)
Definition: simpletransformationdescriptors.hh:88
static result< TC >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, const std::vector< std::shared_ptr< TC >> &children)
Definition: simpletransformationdescriptors.hh:94
static const bool recursive
Definition: simpletransformationdescriptors.hh:78
Definition: simpletransformationdescriptors.hh:82
TransformedNode< TC > type
Definition: simpletransformationdescriptors.hh:83
std::shared_ptr< type > storage_type
Definition: simpletransformationdescriptors.hh:84
Definition: simpletransformationdescriptors.hh:104
static const bool recursive
Definition: simpletransformationdescriptors.hh:106
static result< TC... >::type transform(const SourceNode &s, const Transformation &t, std::shared_ptr< TC >... children)
Definition: simpletransformationdescriptors.hh:116
static result< TC... >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >... children)
Definition: simpletransformationdescriptors.hh:122
Definition: simpletransformationdescriptors.hh:110
std::shared_ptr< type > storage_type
Definition: simpletransformationdescriptors.hh:112
TransformedNode< TC... > type
Definition: simpletransformationdescriptors.hh:111