fusion.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 CNRS
3 //
4 
5 
6 #define BOOST_FUSION_INVOKE_MAX_ARITY 10
7 
8 
9 // #include "pinocchio/spatial/fwd.hpp"
10 // #include "pinocchio/spatial/se3.hpp"
11 // #include "pinocchio/multibody/joint.hpp"
12 // #include "pinocchio/multibody/model.hpp"
13 
14 #include <iostream>
15 
16 #include "pinocchio/tools/timer.hpp"
17 #include <Eigen/Core>
18 
19 #include <boost/test/unit_test.hpp>
20 #include <boost/utility/binary.hpp>
21 
22 struct TestObj
23 {
24  int i;
25  TestObj() : i(0) { std::cout << "Test()" << std::endl; }
26  TestObj(int i) : i(i) { std::cout << "Test(int)" << std::endl; }
27  TestObj(const TestObj& clone) : i(clone.i) { std::cout << "Test(clone)" << std::endl; }
28 };
29 
30 
31 template<typename D>
32 struct CRTPBase
33 {
34  D& derived() { return static_cast<D&> (*this); }
35  const D& derived() const { return static_cast<const D&> (*this); }
36 
37  void f() { static_cast<D*>(this)->f(); }
38  int g() { return static_cast<D*>(this)->g(); }
39  int h(const double & x) { return static_cast<D*>(this)->h(x); }
40  int hh(const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & a) { return static_cast<D*>(this)->hh(x,y,z,a); }
41 };
42 
43 struct CRTPDerived : public CRTPBase<CRTPDerived>
44 {
45  void f() { std::cout << "f()" << std::endl; }
46  int g() { std::cout << "g()" << std::endl; return 1; }
47  int h(const double & x) { std::cout << "h(" << x << ")" << std::endl; return 2; }
48  int hh(const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & )
49  { std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl; return 3; }
50 };
51 
52 struct CRTPDerived2 : public CRTPBase<CRTPDerived2>
53 {
54  void f() { std::cout << "f()" << std::endl; }
55  int g() { std::cout << "g()" << std::endl; return 1; }
56  int h(const double & x) { std::cout << "h(" << x << ")" << std::endl; return 2; }
57  int hh(const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & )
58  { std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl; return 3; }
59 };
60 
61 // template<typedef Launcher>
62 // struct LauncherBase : public boost::static_visitor<Launcher::ReturnType>
63 // {
64 // typedef typename Launcher::ReturnType ReturnType;
65 
66 // template<typename D>
67 // ReturnType operator()( const CRTP<D> & crtp ) const
68 // {
69 // return static_cast<D*>(this)->algo(crtp,
70 // static_cast<D*>(this)->args);
71 // }
72 
73 // static
74 // };
75 
76 #include <boost/variant.hpp>
77 typedef boost::variant<CRTPDerived,CRTPDerived2> CRTPVariant;
78 
79 #include <boost/fusion/include/sequence.hpp>
80 #include <boost/fusion/include/make_vector.hpp>
81 #include <boost/fusion/include/next.hpp>
82 #include <boost/fusion/include/invoke.hpp>
83 #include <boost/fusion/view/joint_view.hpp>
84 #include <boost/fusion/include/joint_view.hpp>
85 #include <boost/fusion/algorithm.hpp>
86 #include <boost/fusion/container.hpp>
87 
88 
89 namespace bf = boost::fusion;
90 
91 struct Launcher : public boost::static_visitor<int>
92 {
93 
94  typedef bf::vector<const double &,const int &, const Eigen::MatrixXd &,
95  const Eigen::MatrixXd &,const Eigen::MatrixXd &,const TestObj &> Args;
96  Args args;
97 
98  Launcher(Args args) : args(args) {}
99 
100  template<typename D>
101  int operator() ( CRTPBase<D> & dref ) const
102  {
103  return bf::invoke(&Launcher::algo<D>,bf::push_front(args,boost::ref(dref)));
104  }
105 
106  static int run(CRTPVariant & crtp, Args args )
107  {
108  return boost::apply_visitor( Launcher(args),crtp );
109  }
110 
111  template<typename D>
112  static int algo(CRTPBase<D> & crtp, const double & x,const int & y, const Eigen::MatrixXd & z,
113  const Eigen::MatrixXd & ,const Eigen::MatrixXd & ,const TestObj & a)
114  {
115  return crtp.hh(x,y,z,a);
116  }
117 };
118 
119 namespace boost {
120  namespace fusion {
121  template<typename T,typename V>
123  append(T const& t,V const& v) { return push_front(v,t); }
124 
125  template<typename T1,typename T2,typename V>
127  append2(T1 const& t1,T2 const& t2,V const& v) { return push_front(push_front(v,t2),t1); }
128 
129 
130  // template<typename t1,typename t2,typename v>
131 
132 
133  // typename result_of::push_front<Sequence, T>::type
134 
135  // res append2(t1 a1,t2 a2,v a3) { return push_front(push_front(a3,a2),a1); }
136  }}
137 
138 
139 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
140 
141 BOOST_AUTO_TEST_CASE ( test_fusion )
142 {
143  CRTPDerived d;
144  //CRTPBase<CRTPDerived> & dref = d;
145  CRTPVariant v = d;
146 
147  //(CRTPBase<D> & crtp, const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & a)
148 
149 
150  //Args args(1.0,1,Eigen::MatrixXd::Zero(3,3),TestObj(1));
151  Launcher::run(v, Launcher::Args(1.0,1,Eigen::MatrixXd::Zero(3,3),Eigen::MatrixXd::Zero(3,3),
152  Eigen::MatrixXd::Zero(3,3),TestObj(1)) );
153 
154  int i,j; double k;
155  bf::vector<int&> arg = bf::make_vector(boost::ref(j));
156 
157  bf::vector<double &,int &> arg1 = bf::append(boost::ref(k),arg);
158  bf::vector<int &,double &,int &> arg11 = bf::append(boost::ref(i),arg1);
159 
160  bf::vector<int &,double &,int &> arg2 = bf::append2(boost::ref(i),boost::ref(k),arg);
161  //bf::push_front(bf::push_front(arg1,boost::ref(k)),boost::ref(j));
162 }
163 
164 BOOST_AUTO_TEST_SUITE_END ()
165 
V
boost::variant< CRTPDerived, CRTPDerived2 > CRTPVariant
Definition: fusion.cpp:77
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:24
int h(const double &x)
Definition: fusion.cpp:47
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:48
D & derived()
Definition: fusion.cpp:34
virtual CollisionGeometry * clone() const=0
int h(const double &x)
Definition: fusion.cpp:39
void f()
Definition: fusion.cpp:45
void f()
Definition: fusion.cpp:54
Launcher(Args args)
Definition: fusion.cpp:98
int h(const double &x)
Definition: fusion.cpp:56
static int algo(CRTPBase< D > &crtp, const double &x, const int &y, const Eigen::MatrixXd &z, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj &a)
Definition: fusion.cpp:112
TestObj(const TestObj &clone)
Definition: fusion.cpp:27
int g()
Definition: fusion.cpp:46
BOOST_AUTO_TEST_CASE(test_fusion)
Definition: fusion.cpp:141
static int run(CRTPVariant &crtp, Args args)
Definition: fusion.cpp:106
bf::vector< const double &, const int &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj & > Args
Definition: fusion.cpp:95
const D & derived() const
Definition: fusion.cpp:35
void f()
Definition: fusion.cpp:37
D
int g()
Definition: fusion.cpp:55
TestObj()
Definition: fusion.cpp:25
Args args
Definition: fusion.cpp:96
Vec3f a
#define BOOST_TEST_MODULE
FCL_REAL d
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &a)
Definition: fusion.cpp:40
int i
Definition: fusion.cpp:24
result_of::push_front< typename result_of::push_front< V const, T2 >::type const, T1 >::type append2(T1 const &t1, T2 const &t2, V const &v)
Definition: fusion.cpp:127
TestObj(int i)
Definition: fusion.cpp:26
Transform3f t
int g()
Definition: fusion.cpp:38
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:57


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:30