test_depend.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>
18 
19 using namespace std;
20 using namespace dynamicgraph;
21 
22 template <class Res = double>
23 class DummyClass {
24  public:
25  std::string proname;
26  list<SignalTimeDependent<double, int> *> inputsig;
27  list<SignalTimeDependent<dynamicgraph::Vector, int> *> inputsigV;
28 
29  public:
30  DummyClass(const std::string &n) : proname(n), res(), appel(0), timedata(0) {}
31 
32  Res &fun(Res &res, int t) {
33  appel++;
34  timedata = t;
35 
36  cout << "Inside " << proname << " -> " << this << endl;
37  for (list<SignalTimeDependent<double, int> *>::iterator it =
38  inputsig.begin();
39  it != inputsig.end(); ++it) {
40  cout << *(*it) << endl;
41  (*it)->access(timedata);
42  }
43  for (list<SignalTimeDependent<dynamicgraph::Vector, int> *>::iterator it =
44  inputsigV.begin();
45  it != inputsigV.end(); ++it) {
46  cout << *(*it) << endl;
47  (*it)->access(timedata);
48  }
49 
50  return res = (*this)();
51  }
52 
53  void add(SignalTimeDependent<double, int> &sig) { inputsig.push_back(&sig); }
55  inputsigV.push_back(&sig);
56  }
57 
58  Res operator()(void);
59 
60  Res res;
61  int appel;
62  int timedata;
63 };
64 
65 template <class Res>
67  return this->res;
68 }
69 
70 template <>
71 double DummyClass<double>::operator()(void) {
72  res = appel * timedata;
73  return res;
74 }
75 template <>
77  res.resize(3);
78  res.fill(appel * timedata);
79  return res;
80 }
81 
82 int main(void) {
83  DummyClass<double> pro1("pro1"), pro3("pro3"), pro5("pro5");
84  DummyClass<dynamicgraph::Vector> pro2("pro2"), pro4("pro4"), pro6("pro6");
85 
88 
91  sig4 << sig4 << sig4 << sig6, "Sig2");
92  SignalTimeDependent<double, int> sig3(sig2 << sig5 << sig6, "Sig3");
94  boost::bind(&DummyClass<double>::fun, &pro1, _1, _2), sig2 << sig3,
95  "Sig1");
96 
97  // cout << "--- Test Array ------ "<<endl;
98  // SignalArray<int> tarr(12);
99  // tarr<<sig3<<sig2;//+sig2+sig3;
100  // dispArray(sig4<<sig2<<sig3);
101  // dispArray(tarr);
102 
103  sig2.setFunction(
104  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro2, _1, _2));
105  sig3.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
106  sig4.setFunction(
107  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro4, _1, _2));
108  sig5.setFunction(boost::bind(&DummyClass<double>::fun, &pro5, _1, _2));
109  sig6.setFunction(
110  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro6, _1, _2));
111 
112  pro1.add(sig2);
113  pro1.add(sig3);
114  pro2.add(sig4);
115  pro2.add(sig4);
116  pro2.add(sig4);
117  pro3.add(sig2);
118  pro4.add(sig5);
119  pro2.add(sig6);
120  pro3.add(sig5);
121  pro3.add(sig6);
122 
125 
126  sig6.setReady();
127 
128  sig1.displayDependencies(cout) << endl;
129 
130  cout << "Needs update?" << endl << sig1.needUpdate(2) << endl;
131  dgDEBUG(1) << "Access sig1(2) " << endl;
132  sig1.access(2);
133  sig1.displayDependencies(cout) << endl;
134  dgDEBUG(1) << "Access sig2(4) " << endl;
135  sig2.access(4);
136  sig1.displayDependencies(cout) << endl;
137  dgDEBUG(1) << "Access sig1(4) " << endl;
138  sig1.access(4);
139  sig1.displayDependencies(cout) << endl;
140 
141  sig1.needUpdate(6);
142  sig1.needUpdate(6);
143 
144  return 0;
145 }
const T & access(const Time &t1)
Eigen::VectorXd Vector
Vec3f n
Signal< dynamicgraph::Matrix, int > sig("matrix")
void setDependencyType(DependencyType dep)
#define dgDEBUG(level)
T operator()()
Definition: test_dep.cpp:62
res
Transform3f t
int main(void)
Definition: test_depend.cpp:82
void setReady(const bool sready=true)
dynamicgraph::Vector & fun(dynamicgraph::Vector &res, double)
Definition: test_signal.cpp:33
virtual bool needUpdate(const Time &t) const
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
std::ostream & displayDependencies(std::ostream &os, const int depth=-1, std::string space="", std::string next1="", std::string next2="") const


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