dune-typetree  2.7.1
generictransformationdescriptors.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_GENERICTRANSFORMATIONDESCRIPTORS_HH
5 #define DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
6 
7 #include <array>
8 #include <memory>
9 
13 #include <dune/common/exceptions.hh>
14 
15 
16 namespace Dune {
17  namespace TypeTree {
18 
24  template<typename SourceNode, typename Transformation, typename TransformedNode>
26  {
27 
28  static const bool recursive = false;
29 
30  typedef TransformedNode transformed_type;
31  typedef std::shared_ptr<transformed_type> transformed_storage_type;
32 
33  static transformed_type transform(const SourceNode& s, const Transformation& t)
34  {
35  return transformed_type(s,t);
36  }
37 
38  static transformed_type transform(std::shared_ptr<const SourceNode> s, const Transformation& t)
39  {
40  return transformed_type(s,t);
41  }
42 
43  static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
44  {
45  return std::make_shared<transformed_type>(s,t);
46  }
47 
48  };
49 
50 
51  template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
53  {
54 
55  static const bool recursive = true;
56 
57  template<typename TC>
58  struct result
59  {
60  typedef typename TransformedNodeTemplate<TC>::type type;
61  typedef std::shared_ptr<type> storage_type;
62  static const std::size_t degree = StaticDegree<type>::value;
63  };
64 
65  template<typename TC>
66  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
67  {
68  return typename result<TC>::type(s,t,children);
69  }
70 
71  template<typename TC>
72  static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
73  {
74  return typename result<TC>::type(s,t,children);
75  }
76 
77  template<typename TC>
78  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)
79  {
80  return std::make_shared<typename result<TC>::type>(s,t,children);
81  }
82 
83  };
84 
85 
86  template<typename SourceNode, typename Transformation, template<typename,typename,std::size_t> class TransformedNode>
89  Transformation,
90  GenericPowerNodeTransformationTemplate<SourceNode,
91  Transformation,
92  TransformedNode>::template result
93  >
94  {};
95 
96 
97  template<typename SourceNode, typename Transformation, template<typename...> class TransformedNodeTemplate>
99  {
100 
101  static const bool recursive = true;
102 
103  template<typename... TC>
104  struct result
105  {
106  typedef typename TransformedNodeTemplate<TC...>::type type;
107  typedef std::shared_ptr<type> storage_type;
108  };
109 
110  template<typename... TC>
111  static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
112  {
113  return typename result<TC...>::type(s,t,children...);
114  }
115 
116  template<typename... TC>
117  static typename result<TC...>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
118  {
119  return typename result<TC...>::type(s,t,children...);
120  }
121 
122  template<typename... TC>
123  static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
124  {
125  return std::make_shared<typename result<TC...>::type>(s,t,children...);
126  }
127 
128  };
129 
130 
131  template<typename SourceNode, typename Transformation, template<typename,typename...> class TransformedNode>
134  Transformation,
135  GenericCompositeNodeTransformationTemplate<SourceNode,
136  Transformation,
137  TransformedNode>::template result
138  >
139  {};
140 
142 
143  } // namespace TypeTree
144 } //namespace Dune
145 
146 #endif // DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
std::integral_constant< std::size_t, degree(static_cast< std::decay_t< Node > * >(nullptr), NodeTag< std::decay_t< Node > >()) > StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:105
Definition: accumulate_static.hh:13
Definition: generictransformationdescriptors.hh:26
TransformedNode transformed_type
Definition: generictransformationdescriptors.hh:30
std::shared_ptr< transformed_type > transformed_storage_type
Definition: generictransformationdescriptors.hh:31
static transformed_type transform(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:38
static const bool recursive
Definition: generictransformationdescriptors.hh:28
static transformed_storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:43
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition: generictransformationdescriptors.hh:33
Definition: generictransformationdescriptors.hh:53
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: generictransformationdescriptors.hh:78
static const bool recursive
Definition: generictransformationdescriptors.hh:55
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::degree > &children)
Definition: generictransformationdescriptors.hh:66
static result< TC >::type transform(std::shared_ptr< const SourceNode > s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::degree > &children)
Definition: generictransformationdescriptors.hh:72
Definition: generictransformationdescriptors.hh:59
TransformedNodeTemplate< TC >::type type
Definition: generictransformationdescriptors.hh:60
static const std::size_t degree
Definition: generictransformationdescriptors.hh:62
std::shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:61
Definition: generictransformationdescriptors.hh:94
Definition: generictransformationdescriptors.hh:99
static result< TC... >::type transform(const SourceNode &s, const Transformation &t, std::shared_ptr< TC >... children)
Definition: generictransformationdescriptors.hh:111
static result< TC... >::type transform(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >... children)
Definition: generictransformationdescriptors.hh:117
static result< TC... >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >... children)
Definition: generictransformationdescriptors.hh:123
static const bool recursive
Definition: generictransformationdescriptors.hh:101
Definition: generictransformationdescriptors.hh:105
TransformedNodeTemplate< TC... >::type type
Definition: generictransformationdescriptors.hh:106
std::shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:107
Definition: generictransformationdescriptors.hh:139