"Fossies" - the Fresh Open Source Software Archive 
Member "dune-typetree-2.8.0/test/testfilteredcompositenode.cc" (31 Aug 2021, 3475 Bytes) of package /linux/misc/dune/dune-typetree-2.8.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include "config.h"
2
3 #include "typetreetestswitch.hh"
4
5 #if TEST_TYPETREE_INVALID
6
7 int main()
8 {
9 return 0;
10 }
11
12 #else
13
14 #include <dune/typetree/filteredcompositenode.hh>
15
16 #include "typetreetestutility.hh"
17 #include "typetreetargetnodes.hh"
18
19 #include <type_traits>
20
21 struct LeafFilter
22 : public Dune::TypeTree::SimpleFilter
23 {
24 template<typename T, std::size_t new_k, std::size_t old_k>
25 struct apply
26 {
27 static const bool value = std::is_same<typename T::NodeTag,Dune::TypeTree::LeafNodeTag>::value;
28 };
29 };
30
31
32 template<typename Node, typename Filter>
33 class SimpleFilteredNode
34 : public Dune::TypeTree::FilteredCompositeNode<Node,Filter>
35 , public Counter
36 {
37
38 typedef Dune::TypeTree::FilteredCompositeNode<Node,Filter> BaseT;
39
40 public:
41
42 typedef SimpleCompositeTag ImplementationTag;
43
44 static const char* name()
45 {
46 return "SimpleFilteredNode";
47 }
48
49 SimpleFilteredNode(Node& node)
50 : BaseT(node)
51 {}
52
53 };
54
55
56 template<typename Node, typename Filter>
57 void testFilteredCompositeNode(Node& node, Filter filter)
58 {
59 namespace Info = Dune::TypeTree::Experimental::Info;
60 typedef SimpleFilteredNode<Node,Filter> FN;
61 FN filteredNode(node);
62 Dune::TypeTree::applyToTree(filteredNode,TreePrinter());
63 std::cout << "depth: " << Info::depth(filteredNode) << std::endl
64 << "nodes: " << Info::nodeCount(filteredNode) << std::endl
65 << "leafs: " << Info::leafCount(filteredNode) << std::endl;
66
67 typedef Dune::TypeTree::TransformTree<FN,TestTransformation> Transformation;
68
69 typedef typename Transformation::Type TFN;
70
71 TFN tfn = Transformation::transform(filteredNode);
72
73 static_assert(decltype(Info::depth(filteredNode)){} == decltype(Info::depth(tfn)){}, "error in transformation with filtered node");
74 static_assert(decltype(Info::nodeCount(filteredNode)){} == decltype(Info::nodeCount(tfn)){}, "error in transformation with filtered node");
75 static_assert(decltype(Info::leafCount(filteredNode)){} == decltype(Info::leafCount(tfn)){}, "error in transformation with filtered node");
76
77 Dune::TypeTree::applyToTree(tfn,TreePrinter());
78 }
79
80
81 int main(int argc, char** argv)
82 {
83
84 SimpleLeaf sl1;
85
86 typedef SimplePower<SimpleLeaf,3> SP1;
87 SP1 sp1_1;
88 sp1_1.setChild(0,sl1);
89 sp1_1.setChild(1,sl1);
90 sp1_1.setChild(2,sl1);
91
92 SimpleLeaf sl2;
93 SP1 sp1_2(sl2,false);
94
95 typedef SimpleComposite<SimpleLeaf,SP1,SimpleLeaf> SC1;
96 SC1 sc1_1(sl1,sp1_2,sl2);
97
98 typedef SimpleComposite<SimpleLeaf,SimpleLeaf,SimpleLeaf> SC2;
99 SC2 sc2(sl1,sl1,sl1);
100
101 typedef SimpleComposite<SimpleLeaf,SP1,SimpleLeaf,SC1> SVC1;
102 SVC1 svc1_1(sl1,sp1_1,sl2,sc1_1);
103
104 SP1 sp1_3(SimpleLeaf(),SimpleLeaf(),sl1);
105
106 SVC1 svc1_2(SimpleLeaf(),SP1(sp1_2),sl2,const_cast<const SC1&>(sc1_1));
107
108 typedef SimpleComposite<SimpleLeaf,SVC1,SimpleLeaf,SP1,SC1> SVC2;
109 SVC2 svc2_1(sl1,svc1_2,sl2,sp1_3,sc1_1);
110
111 testFilteredCompositeNode(svc2_1,LeafFilter());
112 testFilteredCompositeNode<const SVC2>(svc2_1,LeafFilter());
113
114 testFilteredCompositeNode(svc2_1,Dune::TypeTree::IndexFilter<1,3,2>());
115 testFilteredCompositeNode<const SVC2>(svc2_1,Dune::TypeTree::IndexFilter<1,3,2>());
116
117 typedef Dune::TypeTree::IndexFilter<3,1,0,4,1,2,1,0,2,1> IndexFilter1;
118 testFilteredCompositeNode(svc2_1,IndexFilter1());
119 testFilteredCompositeNode<const SVC2>(svc2_1,IndexFilter1());
120
121 typedef SimpleFilteredNode<SVC2,IndexFilter1> SFN;
122 SFN sfn(svc2_1);
123
124 testFilteredCompositeNode(sfn,IndexFilter1());
125 testFilteredCompositeNode<const SFN>(sfn,IndexFilter1());
126
127 return 0;
128 }
129
130 #endif