6 #ifndef DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H 7 #define DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H 8 #include <dynamic-graph/signal.h> 9 #include <dynamic-graph/time-dependency.h> 62 template <
class T,
class Time>
63 class SignalTimeDependent :
public virtual Signal<T, Time>,
64 public TimeDependency<Time> {
68 SignalTimeDependent(std::string name =
"");
69 SignalTimeDependent(
const SignalArray_const<Time> &arr,
70 std::string name =
"");
71 SignalTimeDependent(boost::function2<T &, T &, Time> t,
72 const SignalArray_const<Time> &sig,
73 std::string name =
"");
75 virtual ~SignalTimeDependent() {}
77 inline const T &operator()(
const Time &t1) {
return access(t1); }
78 const T &access(
const Time &t1);
80 virtual void addDependency(
const SignalBase<Time> &signal);
81 virtual void removeDependency(
const SignalBase<Time> &signal);
82 virtual void clearDependencies();
84 std::ostream &writeGraph(std::ostream &os)
const {
return os; }
86 std::ostream &displayDependencies(std::ostream &os,
const int depth = -1,
87 std::string space =
"",
88 std::string next1 =
"",
89 std::string next2 =
"")
const {
90 return TimeDependency<Time>::displayDependencies(os, depth, space, next1,
94 virtual bool needUpdate(
const Time &t)
const;
95 virtual void setPeriodTime(
const Time &p);
96 virtual Time getPeriodTime()
const;
101 template <
class T,
class Time>
102 SignalTimeDependent<T, Time>::SignalTimeDependent(std::string name)
103 : Signal<T, Time>(name), TimeDependency<Time>(this) {}
105 template <
class T,
class Time>
106 SignalTimeDependent<T, Time>::SignalTimeDependent(
107 const SignalArray_const<Time> &arr, std::string name)
108 : Signal<T, Time>(name), TimeDependency<Time>(this, arr) {}
110 template <
class T,
class Time>
111 SignalTimeDependent<T, Time>::SignalTimeDependent(
112 boost::function2<T &, T &, Time> t,
const SignalArray_const<Time> &sig,
114 : Signal<T, Time>(name), TimeDependency<Time>(this, sig) {
115 this->setFunction(t);
118 template <
class T,
class Time>
119 const T &SignalTimeDependent<T, Time>::access(
const Time &t1) {
120 const bool up = TimeDependency<Time>::needUpdate(t1);
126 TimeDependency<Time>::lastAskForUpdate =
false;
127 const T &Tres = Signal<T, Time>::access(t1);
128 SignalBase<Time>::setReady(
false);
131 return Signal<T, Time>::accessCopy();
135 template <
class T,
class Time>
136 void SignalTimeDependent<T, Time>::addDependency(
137 const SignalBase<Time> &signal) {
138 TimeDependency<Time>::addDependency(signal);
141 template <
class T,
class Time>
142 void SignalTimeDependent<T, Time>::removeDependency(
143 const SignalBase<Time> &signal) {
144 TimeDependency<Time>::removeDependency(signal);
147 template <
class T,
class Time>
148 void SignalTimeDependent<T, Time>::clearDependencies() {
149 TimeDependency<Time>::clearDependency();
152 template <
class T,
class Time>
153 bool SignalTimeDependent<T, Time>::needUpdate(
const Time &t)
const {
154 return TimeDependency<Time>::needUpdate(t);
157 template <
class T,
class Time>
158 void SignalTimeDependent<T, Time>::setPeriodTime(
const Time &p) {
159 TimeDependency<Time>::setPeriodTime(p);
161 template <
class T,
class Time>
162 Time SignalTimeDependent<T, Time>::getPeriodTime()
const {
163 return TimeDependency<Time>::getPeriodTime();