fusion.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 
19 #define BOOST_FUSION_INVOKE_MAX_ARITY 10
20 
21 
22 // #include "pinocchio/spatial/fwd.hpp"
23 // #include "pinocchio/spatial/se3.hpp"
24 // #include "pinocchio/multibody/joint.hpp"
25 // #include "pinocchio/multibody/model.hpp"
26 
27 #include <iostream>
28 
29 #include "pinocchio/tools/timer.hpp"
30 #include <Eigen/Core>
31 
32 #include <boost/test/unit_test.hpp>
33 #include <boost/utility/binary.hpp>
34 
35 struct TestObj
36 {
37  int i;
38  TestObj() : i(0) { std::cout << "Test()" << std::endl; }
39  TestObj(int i) : i(i) { std::cout << "Test(int)" << std::endl; }
40  TestObj(const TestObj& clone) : i(clone.i) { std::cout << "Test(clone)" << std::endl; }
41 };
42 
43 
44 template<typename D>
45 struct CRTPBase
46 {
47  D& derived() { return static_cast<D&> (*this); }
48  const D& derived() const { return static_cast<const D&> (*this); }
49 
50  void f() { static_cast<D*>(this)->f(); }
51  int g() { return static_cast<D*>(this)->g(); }
52  int h(const double & x) { return static_cast<D*>(this)->h(x); }
53  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); }
54 };
55 
56 struct CRTPDerived : public CRTPBase<CRTPDerived>
57 {
58  void f() { std::cout << "f()" << std::endl; }
59  int g() { std::cout << "g()" << std::endl; return 1; }
60  int h(const double & x) { std::cout << "h(" << x << ")" << std::endl; return 2; }
61  int hh(const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & )
62  { std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl; return 3; }
63 };
64 
65 struct CRTPDerived2 : public CRTPBase<CRTPDerived2>
66 {
67  void f() { std::cout << "f()" << std::endl; }
68  int g() { std::cout << "g()" << std::endl; return 1; }
69  int h(const double & x) { std::cout << "h(" << x << ")" << std::endl; return 2; }
70  int hh(const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & )
71  { std::cout << "hh(" << x << "," << y << "," << z << ",a)" << std::endl; return 3; }
72 };
73 
74 // template<typedef Launcher>
75 // struct LauncherBase : public boost::static_visitor<Launcher::ReturnType>
76 // {
77 // typedef typename Launcher::ReturnType ReturnType;
78 
79 // template<typename D>
80 // ReturnType operator()( const CRTP<D> & crtp ) const
81 // {
82 // return static_cast<D*>(this)->algo(crtp,
83 // static_cast<D*>(this)->args);
84 // }
85 
86 // static
87 // };
88 
89 #include <boost/variant.hpp>
90 typedef boost::variant<CRTPDerived,CRTPDerived2> CRTPVariant;
91 
92 #include <boost/fusion/include/sequence.hpp>
93 #include <boost/fusion/include/make_vector.hpp>
94 #include <boost/fusion/include/next.hpp>
95 #include <boost/fusion/include/invoke.hpp>
96 #include <boost/fusion/view/joint_view.hpp>
97 #include <boost/fusion/include/joint_view.hpp>
98 #include <boost/fusion/algorithm.hpp>
99 #include <boost/fusion/container.hpp>
100 
101 
102 namespace bf = boost::fusion;
103 
104 struct Launcher : public boost::static_visitor<int>
105 {
106 
107  typedef bf::vector<const double &,const int &, const Eigen::MatrixXd &,
108  const Eigen::MatrixXd &,const Eigen::MatrixXd &,const TestObj &> Args;
109  Args args;
110 
111  Launcher(Args args) : args(args) {}
112 
113  template<typename D>
114  int operator() ( CRTPBase<D> & dref ) const
115  {
116  return bf::invoke(&Launcher::algo<D>,bf::push_front(args,boost::ref(dref)));
117  }
118 
119  static int run(CRTPVariant & crtp, Args args )
120  {
121  return boost::apply_visitor( Launcher(args),crtp );
122  }
123 
124  template<typename D>
125  static int algo(CRTPBase<D> & crtp, const double & x,const int & y, const Eigen::MatrixXd & z,
126  const Eigen::MatrixXd & ,const Eigen::MatrixXd & ,const TestObj & a)
127  {
128  return crtp.hh(x,y,z,a);
129  }
130 };
131 
132 namespace boost {
133  namespace fusion {
134  template<typename T,typename V>
136  append(T const& t,V const& v) { return push_front(v,t); }
137 
138  template<typename T1,typename T2,typename V>
140  append2(T1 const& t1,T2 const& t2,V const& v) { return push_front(push_front(v,t2),t1); }
141 
142 
143  // template<typename t1,typename t2,typename v>
144 
145 
146  // typename result_of::push_front<Sequence, T>::type
147 
148  // res append2(t1 a1,t2 a2,v a3) { return push_front(push_front(a3,a2),a1); }
149  }}
150 
151 
152 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
153 
154 BOOST_AUTO_TEST_CASE ( test_fusion )
155 {
156  CRTPDerived d;
157  //CRTPBase<CRTPDerived> & dref = d;
158  CRTPVariant v = d;
159 
160  //(CRTPBase<D> & crtp, const double & x,const int & y, const Eigen::MatrixXd & z,const TestObj & a)
161 
162 
163  //Args args(1.0,1,Eigen::MatrixXd::Zero(3,3),TestObj(1));
164  Launcher::run(v, Launcher::Args(1.0,1,Eigen::MatrixXd::Zero(3,3),Eigen::MatrixXd::Zero(3,3),
165  Eigen::MatrixXd::Zero(3,3),TestObj(1)) );
166 
167  int i,j; double k;
168  bf::vector<int&> arg = bf::make_vector(boost::ref(j));
169 
170  bf::vector<double &,int &> arg1 = bf::append(boost::ref(k),arg);
171  bf::vector<int &,double &,int &> arg11 = bf::append(boost::ref(i),arg1);
172 
173  bf::vector<int &,double &,int &> arg2 = bf::append2(boost::ref(i),boost::ref(k),arg);
174  //bf::push_front(bf::push_front(arg1,boost::ref(k)),boost::ref(j));
175 }
176 
177 BOOST_AUTO_TEST_SUITE_END ()
178 
V
boost::variant< CRTPDerived, CRTPDerived2 > CRTPVariant
Definition: fusion.cpp:90
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:60
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:61
D & derived()
Definition: fusion.cpp:47
int h(const double &x)
Definition: fusion.cpp:52
void f()
Definition: fusion.cpp:58
void f()
Definition: fusion.cpp:67
Launcher(Args args)
Definition: fusion.cpp:111
int h(const double &x)
Definition: fusion.cpp:69
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:125
TestObj(const TestObj &clone)
Definition: fusion.cpp:40
int g()
Definition: fusion.cpp:59
BOOST_AUTO_TEST_CASE(test_fusion)
Definition: fusion.cpp:154
static int run(CRTPVariant &crtp, Args args)
Definition: fusion.cpp:119
bf::vector< const double &, const int &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj & > Args
Definition: fusion.cpp:108
v
const D & derived() const
Definition: fusion.cpp:48
void f()
Definition: fusion.cpp:50
D
int g()
Definition: fusion.cpp:68
d
Definition: ur5x4.py:45
TestObj()
Definition: fusion.cpp:38
Args args
Definition: fusion.cpp:109
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &a)
Definition: fusion.cpp:53
int i
Definition: fusion.cpp:37
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:140
TestObj(int i)
Definition: fusion.cpp:39
int g()
Definition: fusion.cpp:51
x
— Training
Definition: continuous.py:157
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
Definition: fusion.cpp:70


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:03