dune-typetree  2.4-dev
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 
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(s,t);
35  }
36 
37  static transformed_type transform(std::shared_ptr<const SourceNode> s, const Transformation& t)
38  {
39  return transformed_type(s,t);
40  }
41 
42  static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
43  {
44  return std::make_shared<transformed_type>(s,t);
45  }
46 
47  };
48 
49 
50  template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
52  {
53 
54  static const bool recursive = true;
55 
56  template<typename TC>
57  struct result
58  {
59  typedef typename TransformedNodeTemplate<TC>::type type;
60  typedef std::shared_ptr<type> storage_type;
61  };
62 
63  template<typename TC>
64  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
65  {
66  return typename result<TC>::type(s,t,children);
67  }
68 
69  template<typename TC>
70  static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
71  {
72  return typename result<TC>::type(s,t,children);
73  }
74 
75  template<typename TC>
76  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>::type::CHILDREN>& children)
77  {
78  return std::make_shared<typename result<TC>::type>(s,t,children);
79  }
80 
81  };
82 
83 
84  template<typename SourceNode, typename Transformation, template<typename,typename,std::size_t> class TransformedNode>
87  Transformation,
88  GenericPowerNodeTransformationTemplate<SourceNode,
89  Transformation,
90  TransformedNode>::template result
91  >
92  {};
93 
94 
95  template<typename SourceNode, typename Transformation, template<typename...> class TransformedNodeTemplate>
97  {
98 
99  static const bool recursive = true;
100 
101  template<typename... TC>
102  struct result
103  {
104  typedef typename TransformedNodeTemplate<TC...>::type type;
105  typedef std::shared_ptr<type> storage_type;
106  };
107 
108  template<typename... TC>
109  static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
110  {
111  return typename result<TC...>::type(s,t,children...);
112  }
113 
114  template<typename... TC>
115  static typename result<TC...>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
116  {
117  return typename result<TC...>::type(s,t,children...);
118  }
119 
120  template<typename... TC>
121  static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
122  {
123  return std::make_shared<typename result<TC...>::type>(s,t,children...);
124  }
125 
126  };
127 
128 
129  template<typename SourceNode, typename Transformation, template<typename,typename...> class TransformedNode>
132  Transformation,
133  GenericCompositeNodeTransformationTemplate<SourceNode,
134  Transformation,
135  TransformedNode>::template result
136  >
137  {};
138 
140 
141  } // namespace TypeTree
142 } //namespace Dune
143 
144 #endif // DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
Definition: generictransformationdescriptors.hh:24
static result< TC...>::type transform(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:115
Definition: accumulate_static.hh:12
static result< TC >::type transform(std::shared_ptr< const SourceNode > s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:70
Definition: generictransformationdescriptors.hh:96
Definition: generictransformationdescriptors.hh:102
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:64
TransformedNodeTemplate< TC...>::type type
Definition: generictransformationdescriptors.hh:104
Definition: generictransformationdescriptors.hh:51
static transformed_type transform(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:37
std::shared_ptr< transformed_type > transformed_storage_type
Definition: generictransformationdescriptors.hh:30
static transformed_storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:42
static result< TC...>::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:121
Definition: generictransformationdescriptors.hh:130
TransformedNode transformed_type
Definition: generictransformationdescriptors.hh:29
static const bool recursive
Definition: generictransformationdescriptors.hh:99
static const bool recursive
Definition: generictransformationdescriptors.hh:27
static result< TC...>::type transform(const SourceNode &s, const Transformation &t, std::shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:109
Definition: generictransformationdescriptors.hh:85
static const result_type result
Definition: accumulate_static.hh:109
Definition: generictransformationdescriptors.hh:57
std::shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:60
std::shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:105
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition: generictransformationdescriptors.hh:32
TransformedNodeTemplate< TC >::type type
Definition: generictransformationdescriptors.hh:59
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 >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:76
static const bool recursive
Definition: generictransformationdescriptors.hh:54