6 #ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP 7 #define DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP 8 #include <dynamic-graph/time-dependency.h> 10 #undef VP_TEMPLATE_DEBUG_MODE 11 #define VP_TEMPLATE_DEBUG_MODE 0 12 #include <dynamic-graph/debug.h> 14 #define __TIME_DEPENDENCY_INIT(sig, dep) \ 15 leader(*sig), dependencies(), updateFromAllChildren(ALL_READY_DEFAULT), \ 16 dependencyType(dep), periodTime(PERIOD_TIME_DEFAULT) 20 TimeDependency<Time>::TimeDependency(SignalBase<Time> *sig,
21 const DependencyType dep)
22 : __TIME_DEPENDENCY_INIT(sig, dep) {}
25 TimeDependency<Time>::TimeDependency(SignalBase<Time> *sig,
26 const SignalArray_const<Time> &ar,
27 const DependencyType dep)
28 : __TIME_DEPENDENCY_INIT(sig, dep) {
36 void TimeDependency<Time>::addDependencies(
const SignalArray_const<Time> &ar) {
37 for (
unsigned int i = 0; i < ar.getSize(); ++i) {
43 void TimeDependency<Time>::addDependency(
const SignalBase<Time> &sig) {
44 dependencies.push_front(&sig);
48 void TimeDependency<Time>::removeDependency(
const SignalBase<Time> &sig) {
49 dependencies.remove(&sig);
52 template <
class Time>
void TimeDependency<Time>::clearDependency() {
57 bool TimeDependency<Time>::needUpdate(
const Time &t1)
const {
58 dgTDEBUG(15) <<
"# In {" << leader.getName() <<
" : (" << leader.getReady()
59 <<
") " << t1 <<
" >? " << leader.getTime() << std::endl;
61 if (leader.getReady()) {
65 if (lastAskForUpdate) {
70 switch (dependencyType) {
77 case TIME_DEPENDENT: {
78 if (t1 < leader.getTime() + periodTime) {
86 bool res = updateFromAllChildren;
87 const typename Dependencies::const_iterator itend = dependencies.end();
88 for (
typename Dependencies::const_iterator it = dependencies.begin();
90 const SignalBase<Time> &sig = **it;
91 dgTDEBUG(15) <<
"Ask update for " << sig << std::endl;
93 if ((sig.getTime() > leader.getTime()) || (sig.needUpdate(t1))) {
94 if (updateFromAllChildren)
101 if (updateFromAllChildren) {
108 lastAskForUpdate = res;
114 template <
class Time>
115 std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os)
const {
119 template <
class Time>
121 TimeDependency<Time>::displayDependencies(std::ostream &os,
const int depth,
122 std::string space, std::string next1,
123 std::string next2)
const {
124 leader.SignalBase<Time>::displayDependencies(os, depth, space, next1, next2)
126 switch (dependencyType) {
131 os <<
"ready=" << ((leader.getReady()) ?
"TRUE" :
"FALSE");
134 os <<
"t=" << leader.getTime() <<
" (/" << periodTime <<
") ";
139 const typename Dependencies::const_iterator itend = dependencies.end();
140 for (
typename Dependencies::const_iterator it = dependencies.begin();
144 std::string ajout =
"|";
145 std::string ajout2 =
"|";
146 typename Dependencies::const_iterator it2 = it;
148 if (it2 == dependencies.end()) {
152 (*it)->displayDependencies(os, depth - 1, space + next2 +
" ", ajout,
155 os << std::endl << space <<
" `-- ...";
164 #undef __TIME_DEPENDENCY_INIT