time-dependency.h 2.26 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
6
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//

#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H
Bergé's avatar
Bergé committed
7
8
#define DYNAMIC_GRAPH_TIME_DEPENDENCY_H
#include <list>
Thomas Moulard's avatar
Thomas Moulard committed
9

Bergé's avatar
Bergé committed
10
11
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/signal-array.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <dynamic-graph/signal-base.h>

namespace dynamicgraph {
/** \brief A helper class for setting and specifying dependencies
    between signals.
*/
template <class Time> class TimeDependency {
public:
  enum DependencyType { TIME_DEPENDENT, BOOL_DEPENDENT, ALWAYS_READY };

  mutable Time lastAskForUpdate;

public:
  SignalBase<Time> &leader;

  typedef std::list<const SignalBase<Time> *> Dependencies;
  static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT;

  Dependencies dependencies;
  bool updateFromAllChildren;
  static const bool ALL_READY_DEFAULT = false;

  DependencyType dependencyType;

  Time periodTime;
  static const Time PERIOD_TIME_DEFAULT = 1;

public:
  TimeDependency(SignalBase<Time> *sig,
                 const DependencyType dep = DEPENDENCY_TYPE_DEFAULT);
  TimeDependency(SignalBase<Time> *sig, const SignalArray_const<Time> &arr,
                 const DependencyType dep = DEPENDENCY_TYPE_DEFAULT);
  virtual ~TimeDependency() {}

46
  void addDependencies(const SignalArray_const<Time> &arr);
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  void addDependency(const SignalBase<Time> &sig);
  void removeDependency(const SignalBase<Time> &sig);
  void clearDependency();

  virtual std::ostream &writeGraph(std::ostream &os) const;
  std::ostream &displayDependencies(std::ostream &os, const int depth = -1,
                                    std::string space = "",
                                    std::string next1 = "",
                                    std::string next2 = "") const;

  bool needUpdate(const Time &t1) const;

  void setDependencyType(DependencyType dep) { dependencyType = dep; }

  void setNeedUpdateFromAllChildren(const bool b = true) {
    updateFromAllChildren = b;
  }
  bool getNeedUpdateFromAllChildren() const { return updateFromAllChildren; }

  void setPeriodTime(const Time &p) { periodTime = p; }
  Time getPeriodTime() const { return periodTime; }
};
Thomas Moulard's avatar
Thomas Moulard committed
69

70
} // end of namespace dynamicgraph
Thomas Moulard's avatar
Thomas Moulard committed
71

Bergé's avatar
Bergé committed
72
#include <dynamic-graph/time-dependency.t.cpp>
73
#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_H