"Fossies" - the Fresh Open Source Software Archive

Member "dune-typetree-2.8.0/test/testproxynode.cc" (31 Aug 2021, 2118 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 <dune/typetree/proxynode.hh>
    4 
    5 
    6 #include "typetreetestutility.hh"
    7 
    8 template<typename Node>
    9 class SimpleProxy
   10   : public Dune::TypeTree::ProxyNode<Node>
   11 {
   12 
   13   typedef Dune::TypeTree::ProxyNode<Node> BaseT;
   14 
   15 public:
   16 
   17   static const char* name()
   18   {
   19     return "SimpleProxy";
   20   }
   21 
   22   int id() const
   23   {
   24     return this->proxiedNode().id();
   25   }
   26 
   27   SimpleProxy(Node& node)
   28     : BaseT(node)
   29   {}
   30 
   31 };
   32 
   33 template<typename Node>
   34 void testProxyNode(Node& node)
   35 {
   36   namespace Info = Dune::TypeTree::Experimental::Info;
   37   typedef SimpleProxy<Node> ProxyNode;
   38   ProxyNode proxyNode(node);
   39   Dune::TypeTree::applyToTree(proxyNode,TreePrinter());
   40   static_assert(decltype(Info::depth(node)){} == decltype(Info::depth(proxyNode)){}, "Proxy node has wrong depth");
   41   static_assert(decltype(Info::nodeCount(node)){} == decltype(Info::nodeCount(proxyNode)){}, "Proxy node has wrong node count");
   42   static_assert(decltype(Info::leafCount(node)){} == decltype(Info::leafCount(proxyNode)){}, "Proxy node has wrong leaf count");
   43 }
   44 
   45 
   46 int main(int argc, char** argv)
   47 {
   48 
   49   // basic tests
   50 
   51   // leaf node
   52   SimpleLeaf sl1;
   53 
   54   typedef SimplePower<SimpleLeaf,3> SP1;
   55   SP1 sp1_1;
   56   sp1_1.setChild(0,sl1);
   57   sp1_1.setChild(1,sl1);
   58   sp1_1.setChild(2,sl1);
   59 
   60   SimpleLeaf sl2;
   61   SP1 sp1_2(sl2,false);
   62 
   63   Dune::TypeTree::applyToTree(sp1_1,TreePrinter());
   64 
   65   typedef SimpleComposite<SimpleLeaf,SP1,SimpleLeaf> SC1;
   66   SC1 sc1_1(sl1,sp1_2,sl2);
   67 
   68   typedef SimpleComposite<SimpleLeaf,SimpleLeaf,SimpleLeaf> SC2;
   69   SC2 sc2(sl1,sl1,sl1);
   70 
   71   testProxyNode(sl1);
   72   testProxyNode(sp1_1);
   73   testProxyNode(sc1_1);
   74 
   75   testProxyNode<const SimpleLeaf>(sl1);
   76   testProxyNode<const SP1>(sp1_1);
   77   testProxyNode<const SC1>(sc1_1);
   78 
   79   typedef SimpleComposite<SimpleLeaf,SP1,SimpleLeaf,SC1> SVC1;
   80   SVC1 svc1_1(sl1,sp1_1,sl2,sc1_1);
   81 
   82   SP1 sp1_3(SimpleLeaf(),SimpleLeaf(),sl1);
   83 
   84   SVC1 svc1_2(SimpleLeaf(),SP1(sp1_2),sl2,const_cast<const SC1&>(sc1_1));
   85 
   86   typedef SimpleComposite<SimpleLeaf,SVC1,SimpleLeaf,SP1,SC1> SVC2;
   87   SVC2 svc2_1(sl1,svc1_2,sl2,sp1_3,sc1_1);
   88 
   89   testProxyNode(svc2_1);
   90   testProxyNode<const SVC2>(svc2_1);
   91 
   92   return 0;
   93 }