test_ptr.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* -------------------------------------------------------------------------- */
11 /* --- INCLUDES ------------------------------------------------------------- */
12 /* -------------------------------------------------------------------------- */
15 
16 #include <iostream>
17 #include <sot/core/debug.hh>
20 
21 using namespace std;
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24 
25 template <class Res = double>
26 class DummyClass {
27  public:
28  DummyClass(void) : res(), appel(0), timedata(0) {}
29 
30  Res &fun(Res &res, int t) {
31  appel++;
32  timedata = t;
33 
34  sotDEBUG(5) << "Inside " << typeid(Res).name() << endl;
35  for (list<SignalTimeDependent<double, int> *>::iterator it =
36  inputsig.begin();
37  it != inputsig.end(); ++it) {
38  sotDEBUG(5) << *(*it) << endl;
39  (*it)->access(timedata);
40  }
41  for (list<SignalTimeDependent<dynamicgraph::Vector, int> *>::iterator it =
42  inputsigV.begin();
43  it != inputsigV.end(); ++it) {
44  sotDEBUG(5) << *(*it) << endl;
45  (*it)->access(timedata);
46  }
47 
48  return res = (*this)();
49  }
50 
51  list<SignalTimeDependent<double, int> *> inputsig;
52  list<SignalTimeDependent<dynamicgraph::Vector, int> *> inputsigV;
53 
54  void add(SignalTimeDependent<double, int> &sig) { inputsig.push_back(&sig); }
56  inputsigV.push_back(&sig);
57  }
58 
59  Res operator()(void);
60 
61  Res res;
62  int appel;
63  int timedata;
64 };
65 
66 template <class Res>
68  return this->res;
69 }
70 
71 template <>
72 double DummyClass<double>::operator()(void) {
73  res = appel * timedata;
74  return res;
75 }
76 template <>
78  res.resize(3);
79  res.fill(appel * timedata);
80  return res;
81 }
82 template <>
84  res.angle() = 0.26;
85  res.axis() = Eigen::Vector3d::UnitX();
86  return res;
87 }
88 
89 // void dispArray( const SignalArray<int> &ar )
90 // {
91 // for( unsigned int i=0;i<ar.rank;++i ) sotDEBUG(5)<<*ar.array[i]<<endl;
92 // }
93 
94 void funtest(dynamicgraph::Vector & /*v*/) {}
95 
96 #include <vector>
97 int main(void) {
100  SignalPtr<Eigen::AngleAxisd, int> sigTo3(NULL, "SigTo3");
102  VectorUTheta v3;
103  funtest(v);
104 
105  sig3.setFunction(boost::bind(&DummyClass<VectorUTheta>::fun, pro3, _1, _2));
106  try {
107  sigTo3.plug(&sig3);
108  } catch (sot::ExceptionAbstract &e) {
109  cout << "Plugin error " << e << endl;
110  exit(1);
111  }
112  sig3.access(1);
113  sig3.setReady();
114  sigTo3.access(2);
115  cout << sigTo3.access(2);
116 
117  return 0;
118 }
const T & access(const Time &t1)
Eigen::VectorXd Vector
Signal< dynamicgraph::Matrix, int > sig("matrix")
virtual void plug(SignalBase< Time > *ref)
virtual const T & access(const Time &t)
T operator()()
Definition: test_dep.cpp:62
#define sotDEBUG(level)
Definition: debug.hh:165
Eigen::AngleAxis< double > VectorUTheta
void funtest(dynamicgraph::Vector &)
Definition: test_ptr.cpp:94
res
int main(void)
Definition: test_ptr.cpp:97
DYNAMIC_GRAPH_DLLAPI SignalArray< int > sotNOSIGNAL
Transform3f t
v
void setReady(const bool sready=true)
dynamicgraph::Vector & fun(dynamicgraph::Vector &res, double)
Definition: test_signal.cpp:33
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26