time-dependency.h 2.39 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
12
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-array.h>
Thomas Moulard's avatar
Thomas Moulard committed
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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() {}
    
    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; }
  };
74

Bergé's avatar
Bergé committed
75
}  // end of namespace dynamicgraph
Thomas Moulard's avatar
Thomas Moulard committed
76

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