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);
53 void TimeDependency<Time>::clearDependency() {
58 bool TimeDependency<Time>::needUpdate(
const Time &t1)
const {
59 dgTDEBUG(15) <<
"# In {" << leader.getName() <<
" : (" << leader.getReady()
60 <<
") " << t1 <<
" >? " << leader.getTime() << std::endl;
62 if (leader.getReady()) {
66 if (lastAskForUpdate) {
71 switch (dependencyType) {
78 case TIME_DEPENDENT: {
79 if (t1 < leader.getTime() + periodTime) {
87 bool res = updateFromAllChildren;
88 const typename Dependencies::const_iterator itend = dependencies.end();
89 for (
typename Dependencies::const_iterator it = dependencies.begin();
91 const SignalBase<Time> &sig = **it;
92 dgTDEBUG(15) <<
"Ask update for " << sig << std::endl;
94 if ((sig.getTime() > leader.getTime()) || (sig.needUpdate(t1))) {
95 if (updateFromAllChildren)
102 if (updateFromAllChildren) {
109 lastAskForUpdate = res;
115 template <
class Time>
116 std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os)
const {
120 template <
class Time>
121 std::ostream &TimeDependency<Time>::displayDependencies(
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)
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