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, sigtime_t> *> inputsig;
27  list<SignalTimeDependent<dynamicgraph::Vector, sigtime_t> *> 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, sigtime_t> *>::iterator it =
38  inputsig.begin();
39  it != inputsig.end(); ++it) {
40  cout << *(*it) << endl;
41  (*it)->access(timedata);
42  }
44  it = inputsigV.begin();
45  it != inputsigV.end(); ++it) {
46  cout << *(*it) << endl;
47  (*it)->access(timedata);
48  }
49 
50  return res = (*this)();
51  }
52 
54  inputsig.push_back(&sig);
55  }
57  inputsigV.push_back(&sig);
58  }
59 
60  Res operator()(void);
61 
62  Res res;
63  int appel;
64  int timedata;
65 };
66 
67 template <class Res>
69  return this->res;
70 }
71 
72 template <>
73 double DummyClass<double>::operator()(void) {
74  res = appel * timedata;
75  return res;
76 }
77 template <>
79  res.resize(3);
80  res.fill(appel * timedata);
81  return res;
82 }
83 
84 int main(void) {
85  DummyClass<double> pro1("pro1"), pro3("pro3"), pro5("pro5");
86  DummyClass<dynamicgraph::Vector> pro2("pro2"), pro4("pro4"), pro6("pro6");
87 
90 
93  sig4 << sig4 << sig4 << sig6, "Sig2");
94  SignalTimeDependent<double, sigtime_t> sig3(sig2 << sig5 << sig6, "Sig3");
96  boost::bind(&DummyClass<double>::fun, &pro1, _1, _2), sig2 << sig3,
97  "Sig1");
98 
99  sig2.setFunction(
100  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro2, _1, _2));
101  sig3.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
102  sig4.setFunction(
103  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro4, _1, _2));
104  sig5.setFunction(boost::bind(&DummyClass<double>::fun, &pro5, _1, _2));
105  sig6.setFunction(
106  boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro6, _1, _2));
107 
108  pro1.add(sig2);
109  pro1.add(sig3);
110  pro2.add(sig4);
111  pro2.add(sig4);
112  pro2.add(sig4);
113  pro3.add(sig2);
114  pro4.add(sig5);
115  pro2.add(sig6);
116  pro3.add(sig5);
117  pro3.add(sig6);
118 
119  sig5.setDependencyType(TimeDependency<sigtime_t>::ALWAYS_READY);
120  sig6.setDependencyType(TimeDependency<sigtime_t>::BOOL_DEPENDENT);
121 
122  sig6.setReady();
123 
124  sig1.displayDependencies(cout) << endl;
125 
126  cout << "Needs update?" << endl << sig1.needUpdate(2) << endl;
127  dgDEBUG(1) << "Access sig1(2) " << endl;
128  sig1.access(2);
129  sig1.displayDependencies(cout) << endl;
130  dgDEBUG(1) << "Access sig2(4) " << endl;
131  sig2.access(4);
132  sig1.displayDependencies(cout) << endl;
133  dgDEBUG(1) << "Access sig1(4) " << endl;
134  sig1.access(4);
135  sig1.displayDependencies(cout) << endl;
136 
137  sig1.needUpdate(6);
138  sig1.needUpdate(6);
139 
140  return 0;
141 }
DummyClass
Definition: test_dep.cpp:21
dynamicgraph::SignalTimeDependent::displayDependencies
std::ostream & displayDependencies(std::ostream &os, const int depth=-1, std::string space="", std::string next1="", std::string next2="") const
dynamicgraph::TimeDependency
dynamicgraph::SignalTimeDependent::access
const T & access(const Time &t1)
dynamicgraph
dgDEBUG
#define dgDEBUG(level)
fun
dynamicgraph::Vector & fun(dynamicgraph::Vector &res, double)
Definition: test_signal.cpp:33
debug.hh
res
res
main
int main(void)
Definition: test_depend.cpp:84
all-signals.h
dynamicgraph::Vector
Eigen::VectorXd Vector
linear-algebra.h
dynamicgraph::SignalTimeDependent< double, sigtime_t >
t
Transform3f t
sig
Signal< dynamicgraph::Matrix, sigtime_t > sig("matrix")
dynamicgraph::SignalTimeDependent::needUpdate
virtual bool needUpdate(const Time &t) const
DummyClass::operator()
T operator()()
Definition: test_dep.cpp:64
n
Vec3f n


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32