dynamic-graph  4.1.0-8-gdab7-dirty
Dynamic graph library
time-dependency.h
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_H
7 #define DYNAMIC_GRAPH_TIME_DEPENDENCY_H
8 #include <list>
9 
10 #include <dynamic-graph/fwd.hh>
11 #include <dynamic-graph/signal-array.h>
12 #include <dynamic-graph/signal-base.h>
13 
14 namespace dynamicgraph {
18 template <class Time> class TimeDependency {
19 public:
20  enum DependencyType { TIME_DEPENDENT, BOOL_DEPENDENT, ALWAYS_READY };
21 
22  mutable Time lastAskForUpdate;
23 
24 public:
25  SignalBase<Time> &leader;
26 
27  typedef std::list<const SignalBase<Time> *> Dependencies;
28  static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT;
29 
30  Dependencies dependencies;
31  bool updateFromAllChildren;
32  static const bool ALL_READY_DEFAULT = false;
33 
34  DependencyType dependencyType;
35 
36  Time periodTime;
37  static const Time PERIOD_TIME_DEFAULT = 1;
38 
39 public:
40  TimeDependency(SignalBase<Time> *sig,
41  const DependencyType dep = DEPENDENCY_TYPE_DEFAULT);
42  TimeDependency(SignalBase<Time> *sig, const SignalArray_const<Time> &arr,
43  const DependencyType dep = DEPENDENCY_TYPE_DEFAULT);
44  virtual ~TimeDependency() {}
45 
46  void addDependencies(const SignalArray_const<Time> &arr);
47  void addDependency(const SignalBase<Time> &sig);
48  void removeDependency(const SignalBase<Time> &sig);
49  void clearDependency();
50 
51  virtual std::ostream &writeGraph(std::ostream &os) const;
52  std::ostream &displayDependencies(std::ostream &os, const int depth = -1,
53  std::string space = "",
54  std::string next1 = "",
55  std::string next2 = "") const;
56 
57  bool needUpdate(const Time &t1) const;
58 
59  void setDependencyType(DependencyType dep) { dependencyType = dep; }
60 
61  void setNeedUpdateFromAllChildren(const bool b = true) {
62  updateFromAllChildren = b;
63  }
64  bool getNeedUpdateFromAllChildren() const { return updateFromAllChildren; }
65 
66  void setPeriodTime(const Time &p) { periodTime = p; }
67  Time getPeriodTime() const { return periodTime; }
68 };
69 
70 } // end of namespace dynamicgraph
71 
72 #include <dynamic-graph/time-dependency.t.cpp>
73 #endif