fusion.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 CNRS
3 //
4 
5 #define BOOST_FUSION_INVOKE_MAX_ARITY 10
6 
7 // #include "pinocchio/spatial/fwd.hpp"
8 // #include "pinocchio/spatial/se3.hpp"
9 // #include "pinocchio/multibody/joint.hpp"
10 // #include "pinocchio/multibody/model.hpp"
11 
12 #include <iostream>
13 
14 #include "pinocchio/tools/timer.hpp"
15 #include <Eigen/Core>
16 
17 #include <boost/test/unit_test.hpp>
18 #include <boost/utility/binary.hpp>
19 
20 struct TestObj
21 {
22  int i;
24  : i(0)
25  {
26  std::cout << "Test()" << std::endl;
27  }
28  TestObj(int i)
29  : i(i)
30  {
31  std::cout << "Test(int)" << std::endl;
32  }
34  : i(clone.i)
35  {
36  std::cout << "Test(clone)" << std::endl;
37  }
38 };
39 
40 template<typename D>
41 struct CRTPBase
42 {
43  D & derived()
44  {
45  return static_cast<D &>(*this);
46  }
47  const D & derived() const
48  {
49  return static_cast<const D &>(*this);
50  }
51 
52  void f()
53  {
54  static_cast<D *>(this)->f();
55  }
56  int g()
57  {
58  return static_cast<D *>(this)->g();
59  }
60  int h(const double & x)
61  {
62  return static_cast<D *>(this)->h(x);
63  }
64  int hh(const double & x, const int & y, const Eigen::MatrixXd & z, const TestObj & a)
65  {
66  return static_cast<D *>(this)->hh(x, y, z, a);
67  }
68 };
69 
70 struct CRTPDerived : public CRTPBase<CRTPDerived>
71 {
72  void f()
73  {
74  std::cout << "f()" << std::endl;
75  }
76  int g()
77  {
78  std::cout << "g()" << std::endl;
79  return 1;
80  }
81  int h(const double & x)
82  {
83  std::cout << "h(" << x << ")" << std::endl;
84  return 2;
85  }
86  int hh(const double & x, const int & y, const Eigen::MatrixXd & z, const TestObj &)
87  {
88  std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl;
89  return 3;
90  }
91 };
92 
93 struct CRTPDerived2 : public CRTPBase<CRTPDerived2>
94 {
95  void f()
96  {
97  std::cout << "f()" << std::endl;
98  }
99  int g()
100  {
101  std::cout << "g()" << std::endl;
102  return 1;
103  }
104  int h(const double & x)
105  {
106  std::cout << "h(" << x << ")" << std::endl;
107  return 2;
108  }
109  int hh(const double & x, const int & y, const Eigen::MatrixXd & z, const TestObj &)
110  {
111  std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl;
112  return 3;
113  }
114 };
115 
116 // template<typedef Launcher>
117 // struct LauncherBase : public boost::static_visitor<Launcher::ReturnType>
118 // {
119 // typedef typename Launcher::ReturnType ReturnType;
120 
121 // template<typename D>
122 // ReturnType operator()( const CRTP<D> & crtp ) const
123 // {
124 // return static_cast<D*>(this)->algo(crtp,
125 // static_cast<D*>(this)->args);
126 // }
127 
128 // static
129 // };
130 
131 #include <boost/variant.hpp>
132 typedef boost::variant<CRTPDerived, CRTPDerived2> CRTPVariant;
133 
134 #include <boost/fusion/include/sequence.hpp>
135 #include <boost/fusion/include/make_vector.hpp>
136 #include <boost/fusion/include/next.hpp>
137 #include <boost/fusion/include/invoke.hpp>
138 #include <boost/fusion/view/joint_view.hpp>
139 #include <boost/fusion/include/joint_view.hpp>
140 #include <boost/fusion/algorithm.hpp>
141 #include <boost/fusion/container.hpp>
142 
143 namespace bf = boost::fusion;
144 
145 struct Launcher : public boost::static_visitor<int>
146 {
147 
148  typedef bf::vector<
149  const double &,
150  const int &,
151  const Eigen::MatrixXd &,
152  const Eigen::MatrixXd &,
153  const Eigen::MatrixXd &,
154  const TestObj &>
157 
159  : args(args)
160  {
161  }
162 
163  template<typename D>
164  int operator()(CRTPBase<D> & dref) const
165  {
166  return bf::invoke(&Launcher::algo<D>, bf::push_front(args, boost::ref(dref)));
167  }
168 
169  static int run(CRTPVariant & crtp, Args args)
170  {
171  return boost::apply_visitor(Launcher(args), crtp);
172  }
173 
174  template<typename D>
175  static int algo(
176  CRTPBase<D> & crtp,
177  const double & x,
178  const int & y,
179  const Eigen::MatrixXd & z,
180  const Eigen::MatrixXd &,
181  const Eigen::MatrixXd &,
182  const TestObj & a)
183  {
184  return crtp.hh(x, y, z, a);
185  }
186 };
187 
188 namespace boost
189 {
190  namespace fusion
191  {
192  template<typename T, typename V>
193  typename result_of::push_front<V const, T>::type append(T const & t, V const & v)
194  {
195  return push_front(v, t);
196  }
197 
198  template<typename T1, typename T2, typename V>
200  type
201  append2(T1 const & t1, T2 const & t2, V const & v)
202  {
203  return push_front(push_front(v, t2), t1);
204  }
205 
206  // template<typename t1,typename t2,typename v>
207 
208  // typename result_of::push_front<Sequence, T>::type
209 
210  // res append2(t1 a1,t2 a2,v a3) { return push_front(push_front(a3,a2),a1); }
211  } // namespace fusion
212 } // namespace boost
213 
214 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
215 
217 {
218  CRTPDerived d;
219  // CRTPBase<CRTPDerived> & dref = d;
220  CRTPVariant v = d;
221 
222  //(CRTPBase<D> & crtp, const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj &
223  // a)
224 
225  // Args args(1.0,1,Eigen::MatrixXd::Zero(3,3),TestObj(1));
227  v, Launcher::Args(
228  1.0, 1, Eigen::MatrixXd::Zero(3, 3), Eigen::MatrixXd::Zero(3, 3),
229  Eigen::MatrixXd::Zero(3, 3), TestObj(1)));
230 
231  int i, j;
232  double k;
233  bf::vector<int &> arg = bf::make_vector(boost::ref(j));
234 
235  bf::vector<double &, int &> arg1 = bf::append(boost::ref(k), arg);
236  bf::vector<int &, double &, int &> arg11 = bf::append(boost::ref(i), arg1);
237 
238  bf::vector<int &, double &, int &> arg2 = bf::append2(boost::ref(i), boost::ref(k), arg);
239  // bf::push_front(bf::push_front(arg1,boost::ref(k)),boost::ref(j));
240 }
241 
242 BOOST_AUTO_TEST_SUITE_END()
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:94
TestObj::TestObj
TestObj(int i)
Definition: fusion.cpp:28
CRTPBase::g
int g()
Definition: fusion.cpp:56
CRTPDerived2
Definition: fusion.cpp:93
TestObj::i
int i
Definition: fusion.cpp:22
CRTPBase::f
void f()
Definition: fusion.cpp:52
TestObj::TestObj
TestObj()
Definition: fusion.cpp:23
y
y
CRTPDerived::f
void f()
Definition: fusion.cpp:72
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:20
boost::fusion::append2
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:201
boost
CRTPDerived2::g
int g()
Definition: fusion.cpp:99
Launcher::Launcher
Launcher(Args args)
Definition: fusion.cpp:158
CRTPBase::h
int h(const double &x)
Definition: fusion.cpp:60
CRTPDerived2::h
int h(const double &x)
Definition: fusion.cpp:104
simulation-pendulum.type
type
Definition: simulation-pendulum.py:18
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_fusion)
Definition: fusion.cpp:216
Launcher::Args
bf::vector< const double &, const int &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj & > Args
Definition: fusion.cpp:155
CRTPBase::hh
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &a)
Definition: fusion.cpp:64
Launcher::run
static int run(CRTPVariant &crtp, Args args)
Definition: fusion.cpp:169
autodiff-rnea.v
v
Definition: autodiff-rnea.py:15
CRTPDerived
Definition: fusion.cpp:70
D
D
x
x
CRTPDerived::g
int g()
Definition: fusion.cpp:76
CRTPBase
Definition: fusion.cpp:41
a
Vec3f a
clone
virtual CollisionGeometry * clone() const=0
Launcher::algo
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:175
CRTPDerived::h
int h(const double &x)
Definition: fusion.cpp:81
TestObj::TestObj
TestObj(const TestObj &clone)
Definition: fusion.cpp:33
CRTPDerived2::f
void f()
Definition: fusion.cpp:95
boost::fusion
Definition: fusion.hpp:27
boost::fusion::append
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:32
Launcher
Definition: fusion.cpp:145
CRTPDerived::hh
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:86
t
Transform3f t
CRTPBase::derived
D & derived()
Definition: fusion.cpp:43
TestObj
Definition: fusion.cpp:20
Launcher::args
Args args
Definition: fusion.cpp:156
CRTPBase::derived
const D & derived() const
Definition: fusion.cpp:47
CRTPDerived2::hh
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:109
CRTPVariant
boost::variant< CRTPDerived, CRTPDerived2 > CRTPVariant
Definition: fusion.cpp:132
d
FCL_REAL d
Launcher::operator()
int operator()(CRTPBase< D > &dref) const
Definition: fusion.cpp:164


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:46