dune-typetree  2.4-dev
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 
10 #include <dune/common/exceptions.hh>
11 #include <dune/common/shared_ptr.hh>
12 #include <dune/common/tuples.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 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(shared_ptr<const SourceNode> s, const Transformation& t)
38  {
39  return 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, SourceNode::CHILDREN> type;
55  typedef shared_ptr<type> storage_type;
56  };
57 
58  template<typename TC>
59  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
60  {
61  return typename result<TC>::type(children);
62  }
63 
64  template<typename TC>
65  static typename result<TC>::storage_type transform_storage(shared_ptr<const SourceNode> s, const Transformation& t, const std::array<shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
66  {
67  return make_shared<typename result<TC>::type>(children);
68  }
69 
70  };
71 
72 
73  template<typename SourceNode, typename Transformation, template<typename...> class TransformedNode>
75  {
76 
77  static const bool recursive = true;
78 
79  template<typename... TC>
80  struct result
81  {
82  typedef TransformedNode<TC...> type;
83  typedef shared_ptr<type> storage_type;
84  };
85 
86  template<typename... TC>
87  static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, shared_ptr<TC>... children)
88  {
89  return typename result<TC...>::type(children...);
90  }
91 
92  template<typename... TC>
93  static typename result<TC...>::storage_type transform_storage(shared_ptr<const SourceNode> s, const Transformation& t, shared_ptr<TC>... children)
94  {
95  return make_shared<typename result<TC...>::type>(children...);
96  }
97 
98  };
99 
101 
102  } // namespace TypeTree
103 } //namespace Dune
104 
105 #endif // DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
Definition: simpletransformationdescriptors.hh:24
static transformed_storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t)
Definition: simpletransformationdescriptors.hh:37
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: simpletransformationdescriptors.hh:59
static const bool recursive
Definition: simpletransformationdescriptors.hh:49
shared_ptr< type > storage_type
Definition: simpletransformationdescriptors.hh:55
Definition: accumulate_static.hh:12
TransformedNode< TC, SourceNode::CHILDREN > type
Definition: simpletransformationdescriptors.hh:54
TransformedNode transformed_type
Definition: simpletransformationdescriptors.hh:29
Definition: simpletransformationdescriptors.hh:74
shared_ptr< transformed_type > transformed_storage_type
Definition: simpletransformationdescriptors.hh:30
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition: simpletransformationdescriptors.hh:32
static result< TC...>::storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t, shared_ptr< TC >...children)
Definition: simpletransformationdescriptors.hh:93
Definition: simpletransformationdescriptors.hh:52
static result< TC >::storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t, const std::array< shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: simpletransformationdescriptors.hh:65
static const bool recursive
Definition: simpletransformationdescriptors.hh:77
Definition: simpletransformationdescriptors.hh:46
TransformedNode< TC...> type
Definition: simpletransformationdescriptors.hh:82
shared_ptr< type > storage_type
Definition: simpletransformationdescriptors.hh:83
static const bool recursive
Definition: simpletransformationdescriptors.hh:27
static result< TC...>::type transform(const SourceNode &s, const Transformation &t, shared_ptr< TC >...children)
Definition: simpletransformationdescriptors.hh:87
Definition: simpletransformationdescriptors.hh:80