time-dependency.t.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3 // JRL, CNRS/AIST.
4 //
5 
6 #ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP
7 #define DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP
9 
10 #undef VP_TEMPLATE_DEBUG_MODE
11 #define VP_TEMPLATE_DEBUG_MODE 0
12 #include <dynamic-graph/debug.h>
13 
14 #define __TIME_DEPENDENCY_INIT(sig, dep) \
15  leader(*sig), dependencies(), updateFromAllChildren(ALL_READY_DEFAULT), \
16  dependencyType(dep), periodTime(PERIOD_TIME_DEFAULT)
17 
18 namespace dynamicgraph {
19 template <class Time>
21  const DependencyType dep)
22  : __TIME_DEPENDENCY_INIT(sig, dep) {}
23 
24 template <class Time>
26  const SignalArray_const<Time> &ar,
27  const DependencyType dep)
28  : __TIME_DEPENDENCY_INIT(sig, dep) {
29  addDependencies(ar);
30 
31  return;
32 }
33 
34 /* ------------------------------------------------------------------------ */
35 template <class Time>
37  for (unsigned int i = 0; i < ar.getSize(); ++i) {
38  addDependency(ar[i]);
39  }
40 }
41 
42 template <class Time>
44  dependencies.push_front(&sig);
45 }
46 
47 template <class Time>
49  dependencies.remove(&sig);
50 }
51 
52 template <class Time>
54  dependencies.clear();
55 }
56 
57 template <class Time>
58 bool TimeDependency<Time>::needUpdate(const Time &t1) const {
59  dgTDEBUG(15) << "# In {" << leader.getName() << " : (" << leader.getReady()
60  << ") " << t1 << " >? " << leader.getTime() << std::endl;
61 
62  if (leader.getReady()) {
63  dgTDEBUGOUT(15);
64  return true;
65  }
66  if (lastAskForUpdate) {
67  dgTDEBUGOUT(15);
68  return true;
69  }
70 
71  switch (dependencyType) {
72  case ALWAYS_READY: {
73  dgTDEBUGOUT(15);
74  return true;
75  }
76  case BOOL_DEPENDENT:
77  break;
78  case TIME_DEPENDENT: {
79  if (t1 < leader.getTime() + periodTime) {
80  dgTDEBUGOUT(15);
81  return false;
82  }
83  break;
84  }
85  };
86 
87  bool res = updateFromAllChildren;
88  const typename Dependencies::const_iterator itend = dependencies.end();
89  for (typename Dependencies::const_iterator it = dependencies.begin();
90  it != itend; ++it) {
91  const SignalBase<Time> &sig = **it;
92  dgTDEBUG(15) << "Ask update for " << sig << std::endl;
93 
94  if ((sig.getTime() > leader.getTime()) || (sig.needUpdate(t1))) {
95  if (updateFromAllChildren)
96  continue;
97  else {
98  res = true;
99  break;
100  }
101  } else {
102  if (updateFromAllChildren) {
103  res = false;
104  break;
105  } else
106  continue;
107  }
108  }
109  lastAskForUpdate = res;
110 
111  dgTDEBUGOUT(15);
112  return res;
113 }
114 
115 template <class Time>
116 std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os) const {
117  return os;
118 }
119 
120 template <class Time>
122  std::ostream &os, const int depth, std::string space, std::string next1,
123  std::string next2) const {
124  leader.SignalBase<Time>::displayDependencies(os, depth, space, next1, next2)
125  << " (";
126  switch (dependencyType) {
127  case ALWAYS_READY:
128  os << "A";
129  break;
130  case BOOL_DEPENDENT:
131  os << "ready=" << ((leader.getReady()) ? "TRUE" : "FALSE");
132  break;
133  case TIME_DEPENDENT:
134  os << "t=" << leader.getTime() << " (/" << periodTime << ") ";
135  break;
136  };
137  os << ")"; //<<std::endl;
138  {
139  const typename Dependencies::const_iterator itend = dependencies.end();
140  for (typename Dependencies::const_iterator it = dependencies.begin();
141  it != itend; ++it)
142  if (depth != 0) {
143  os << std::endl;
144  std::string ajout = "|";
145  std::string ajout2 = "|";
146  typename Dependencies::const_iterator it2 = it;
147  ++it2;
148  if (it2 == dependencies.end()) {
149  ajout = "`";
150  ajout2 = " ";
151  }
152  (*it)->displayDependencies(os, depth - 1, space + next2 + " ", ajout,
153  ajout2);
154  } else {
155  os << std::endl << space << " `-- ...";
156  break;
157  }
158  }
159  return os;
160 }
161 
162 } // end of namespace dynamicgraph
163 
164 #undef __TIME_DEPENDENCY_INIT
165 #endif
dynamicgraph::TimeDependency::writeGraph
virtual std::ostream & writeGraph(std::ostream &os) const
Definition: time-dependency.t.cpp:116
dynamicgraph::TimeDependency::needUpdate
bool needUpdate(const Time &t1) const
Definition: time-dependency.t.cpp:58
dynamicgraph::TimeDependency::clearDependency
void clearDependency()
Definition: time-dependency.t.cpp:53
dynamicgraph
dynamicgraph::TimeDependency::displayDependencies
std::ostream & displayDependencies(std::ostream &os, const int depth=-1, std::string space="", std::string next1="", std::string next2="") const
Definition: time-dependency.t.cpp:121
dynamicgraph::SignalArray_const
TODO.
Definition: fwd.hh:50
time-dependency.h
dynamicgraph::TimeDependency::TimeDependency
TimeDependency(SignalBase< Time > *sig, const DependencyType dep=DEPENDENCY_TYPE_DEFAULT)
Definition: time-dependency.t.cpp:20
dynamicgraph::TimeDependency::DependencyType
DependencyType
Definition: time-dependency.h:21
dynamicgraph::TimeDependency::removeDependency
void removeDependency(const SignalBase< Time > &sig)
Definition: time-dependency.t.cpp:48
sig
dynamicgraph::SignalArray_const< double > sig
Definition: signal-all.cpp:25
dynamicgraph::TimeDependency::addDependencies
void addDependencies(const SignalArray_const< Time > &arr)
Definition: time-dependency.t.cpp:36
__TIME_DEPENDENCY_INIT
#define __TIME_DEPENDENCY_INIT(sig, dep)
Definition: time-dependency.t.cpp:14
dynamicgraph::TimeDependency::addDependency
void addDependency(const SignalBase< Time > &sig)
Definition: time-dependency.t.cpp:43
dynamicgraph::SignalArray_const::getSize
virtual unsigned int getSize() const
Definition: signal-array.h:72
dgTDEBUG
#define dgTDEBUG(level)
Definition: debug.h:187
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
dgTDEBUGOUT
#define dgTDEBUGOUT(level)
Definition: debug.h:210
debug.h


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38