time-dependency.h 2.2 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//

#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H
# define DYNAMIC_GRAPH_TIME_DEPENDENCY_H
# include <list>

# include <dynamic-graph/fwd.hh>
# include <dynamic-graph/signal-base.h>
# include <dynamic-graph/signal-array.h>

namespace dynamicgraph
15
{
Thomas Moulard's avatar
Thomas Moulard committed
16
17
18
19
20
21
22
23
24
25
26
27
28
  /** \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
      };
29

Thomas Moulard's avatar
Thomas Moulard committed
30
    mutable Time lastAskForUpdate;
31

Thomas Moulard's avatar
Thomas Moulard committed
32
  public:
33

Thomas Moulard's avatar
Thomas Moulard committed
34
    SignalBase< Time >& leader;
35

Thomas Moulard's avatar
Thomas Moulard committed
36
37
    typedef std::list< const SignalBase<Time> * > Dependencies;
    static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT;
38

Thomas Moulard's avatar
Thomas Moulard committed
39
40
41
    Dependencies dependencies;
    bool updateFromAllChildren;
    static const bool ALL_READY_DEFAULT = false;
42

Thomas Moulard's avatar
Thomas Moulard committed
43
    DependencyType dependencyType;
44

Thomas Moulard's avatar
Thomas Moulard committed
45
46
    Time periodTime;
    static const Time PERIOD_TIME_DEFAULT = 1;
47

Thomas Moulard's avatar
Thomas Moulard committed
48
  public:
49

Thomas Moulard's avatar
Thomas Moulard committed
50
51
52
53
54
    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 );
55
    virtual ~TimeDependency  () {}
56

Thomas Moulard's avatar
Thomas Moulard committed
57
58
59
    void addDependency( const SignalBase<Time>& sig );
    void removeDependency( const SignalBase<Time>& sig );
    void clearDependency  ();
Thomas Moulard's avatar
Thomas Moulard committed
60

61

Thomas Moulard's avatar
Thomas Moulard committed
62
63
64
65
    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;
Thomas Moulard's avatar
Thomas Moulard committed
66

Thomas Moulard's avatar
Thomas Moulard committed
67
    bool needUpdate( const Time& t1 ) const;
68

Thomas Moulard's avatar
Thomas Moulard committed
69
    void setDependencyType( DependencyType dep ) { dependencyType = dep; }
Thomas Moulard's avatar
Thomas Moulard committed
70

Thomas Moulard's avatar
Thomas Moulard committed
71
72
    void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; }
    bool getNeedUpdateFromAllChildren  () const { return updateFromAllChildren; }
73

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

Thomas Moulard's avatar
Thomas Moulard committed
77
  };
78

Thomas Moulard's avatar
Thomas Moulard committed
79
} // end of namespace dynamicgraph
80

Thomas Moulard's avatar
Thomas Moulard committed
81
82
# include <dynamic-graph/time-dependency.t.cpp>
#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_H