GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
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 |
||
8 |
#include <dynamic-graph/time-dependency.h> |
||
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> |
||
20 |
3 |
TimeDependency<Time>::TimeDependency(SignalBase<Time> *sig, |
|
21 |
const DependencyType dep) |
||
22 |
3 |
: __TIME_DEPENDENCY_INIT(sig, dep) {} |
|
23 |
|||
24 |
template <class Time> |
||
25 |
14 |
TimeDependency<Time>::TimeDependency(SignalBase<Time> *sig, |
|
26 |
const SignalArray_const<Time> &ar, |
||
27 |
const DependencyType dep) |
||
28 |
14 |
: __TIME_DEPENDENCY_INIT(sig, dep) { |
|
29 |
✓✗ | 14 |
addDependencies(ar); |
30 |
|||
31 |
14 |
return; |
|
32 |
} |
||
33 |
|||
34 |
/* ------------------------------------------------------------------------ */ |
||
35 |
template <class Time> |
||
36 |
14 |
void TimeDependency<Time>::addDependencies(const SignalArray_const<Time> &ar) { |
|
37 |
✓✗✓✓ |
32 |
for (unsigned int i = 0; i < ar.getSize(); ++i) { |
38 |
✓✗✓✗ |
18 |
addDependency(ar[i]); |
39 |
} |
||
40 |
14 |
} |
|
41 |
|||
42 |
template <class Time> |
||
43 |
22 |
void TimeDependency<Time>::addDependency(const SignalBase<Time> &sig) { |
|
44 |
✓✗ | 22 |
dependencies.push_front(&sig); |
45 |
22 |
} |
|
46 |
|||
47 |
template <class Time> |
||
48 |
1 |
void TimeDependency<Time>::removeDependency(const SignalBase<Time> &sig) { |
|
49 |
1 |
dependencies.remove(&sig); |
|
50 |
1 |
} |
|
51 |
|||
52 |
template <class Time> |
||
53 |
2 |
void TimeDependency<Time>::clearDependency() { |
|
54 |
2 |
dependencies.clear(); |
|
55 |
2 |
} |
|
56 |
|||
57 |
template <class Time> |
||
58 |
3047 |
bool TimeDependency<Time>::needUpdate(const Time &t1) const { |
|
59 |
dgTDEBUG(15) << "# In {" << leader.getName() << " : (" << leader.getReady() |
||
60 |
<< ") " << t1 << " >? " << leader.getTime() << std::endl; |
||
61 |
|||
62 |
✓✓ | 3047 |
if (leader.getReady()) { |
63 |
dgTDEBUGOUT(15); |
||
64 |
10 |
return true; |
|
65 |
} |
||
66 |
✓✓ | 3037 |
if (lastAskForUpdate) { |
67 |
dgTDEBUGOUT(15); |
||
68 |
6 |
return true; |
|
69 |
} |
||
70 |
|||
71 |
✓✓✓✗ |
3031 |
switch (dependencyType) { |
72 |
7 |
case ALWAYS_READY: { |
|
73 |
dgTDEBUGOUT(15); |
||
74 |
7 |
return true; |
|
75 |
} |
||
76 |
9 |
case BOOL_DEPENDENT: |
|
77 |
9 |
break; |
|
78 |
3015 |
case TIME_DEPENDENT: { |
|
79 |
✓✗✓✓ |
3015 |
if (t1 < leader.getTime() + periodTime) { |
80 |
dgTDEBUGOUT(15); |
||
81 |
10 |
return false; |
|
82 |
} |
||
83 |
3005 |
break; |
|
84 |
} |
||
85 |
}; |
||
86 |
|||
87 |
3014 |
bool res = updateFromAllChildren; |
|
88 |
3014 |
const typename Dependencies::const_iterator itend = dependencies.end(); |
|
89 |
3018 |
for (typename Dependencies::const_iterator it = dependencies.begin(); |
|
90 |
✓✓ | 3022 |
it != itend; ++it) { |
91 |
3009 |
const SignalBase<Time> &sig = **it; |
|
92 |
dgTDEBUG(15) << "Ask update for " << sig << std::endl; |
||
93 |
|||
94 |
✓✗✓✗ ✓✓✓✗ ✓✓✓✓ |
3009 |
if ((sig.getTime() > leader.getTime()) || (sig.needUpdate(t1))) { |
95 |
✗✓ | 3005 |
if (updateFromAllChildren) |
96 |
continue; |
||
97 |
else { |
||
98 |
3005 |
res = true; |
|
99 |
3005 |
break; |
|
100 |
} |
||
101 |
} else { |
||
102 |
✗✓ | 4 |
if (updateFromAllChildren) { |
103 |
res = false; |
||
104 |
break; |
||
105 |
} else |
||
106 |
4 |
continue; |
|
107 |
} |
||
108 |
} |
||
109 |
3014 |
lastAskForUpdate = res; |
|
110 |
|||
111 |
dgTDEBUGOUT(15); |
||
112 |
3014 |
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> |
||
121 |
80 |
std::ostream &TimeDependency<Time>::displayDependencies( |
|
122 |
std::ostream &os, const int depth, std::string space, std::string next1, |
||
123 |
std::string next2) const { |
||
124 |
80 |
leader.SignalBase<Time>::displayDependencies(os, depth, space, next1, next2) |
|
125 |
✓✗✓✗ ✓✗✓✗ |
80 |
<< " ("; |
126 |
✓✓✓✗ |
80 |
switch (dependencyType) { |
127 |
28 |
case ALWAYS_READY: |
|
128 |
28 |
os << "A"; |
|
129 |
28 |
break; |
|
130 |
12 |
case BOOL_DEPENDENT: |
|
131 |
✓✓ | 12 |
os << "ready=" << ((leader.getReady()) ? "TRUE" : "FALSE"); |
132 |
12 |
break; |
|
133 |
40 |
case TIME_DEPENDENT: |
|
134 |
40 |
os << "t=" << leader.getTime() << " (/" << periodTime << ") "; |
|
135 |
40 |
break; |
|
136 |
}; |
||
137 |
80 |
os << ")"; //<<std::endl; |
|
138 |
{ |
||
139 |
80 |
const typename Dependencies::const_iterator itend = dependencies.end(); |
|
140 |
156 |
for (typename Dependencies::const_iterator it = dependencies.begin(); |
|
141 |
✓✓ | 232 |
it != itend; ++it) |
142 |
✓✗ | 76 |
if (depth != 0) { |
143 |
✓✗ | 76 |
os << std::endl; |
144 |
✓✗ | 152 |
std::string ajout = "|"; |
145 |
✓✗ | 76 |
std::string ajout2 = "|"; |
146 |
76 |
typename Dependencies::const_iterator it2 = it; |
|
147 |
76 |
++it2; |
|
148 |
✓✓ | 76 |
if (it2 == dependencies.end()) { |
149 |
✓✗ | 40 |
ajout = "`"; |
150 |
✓✗ | 40 |
ajout2 = " "; |
151 |
} |
||
152 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
76 |
(*it)->displayDependencies(os, depth - 1, space + next2 + " ", ajout, |
153 |
ajout2); |
||
154 |
} else { |
||
155 |
os << std::endl << space << " `-- ..."; |
||
156 |
break; |
||
157 |
} |
||
158 |
} |
||
159 |
80 |
return os; |
|
160 |
} |
||
161 |
|||
162 |
} // end of namespace dynamicgraph |
||
163 |
|||
164 |
#undef __TIME_DEPENDENCY_INIT |
||
165 |
#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP |
Generated by: GCOVR (Version 4.2) |