time-dependency.h 2.9 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Lesser Public License for more details.  You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.

#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H
# define DYNAMIC_GRAPH_TIME_DEPENDENCY_H
# include <list>
# include <iostream>

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

namespace dynamicgraph
28
{
Thomas Moulard's avatar
Thomas Moulard committed
29
30
31
32
33
34
35
36
37
38
39
40
41
  /** \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
      };
42

Thomas Moulard's avatar
Thomas Moulard committed
43
    mutable Time lastAskForUpdate;
44

Thomas Moulard's avatar
Thomas Moulard committed
45
  public:
46

Thomas Moulard's avatar
Thomas Moulard committed
47
    SignalBase< Time >& leader;
48

Thomas Moulard's avatar
Thomas Moulard committed
49
50
    typedef std::list< const SignalBase<Time> * > Dependencies;
    static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT;
51

Thomas Moulard's avatar
Thomas Moulard committed
52
53
54
    Dependencies dependencies;
    bool updateFromAllChildren;
    static const bool ALL_READY_DEFAULT = false;
55

Thomas Moulard's avatar
Thomas Moulard committed
56
    DependencyType dependencyType;
57

Thomas Moulard's avatar
Thomas Moulard committed
58
59
    Time periodTime;
    static const Time PERIOD_TIME_DEFAULT = 1;
60

Thomas Moulard's avatar
Thomas Moulard committed
61
  public:
62

Thomas Moulard's avatar
Thomas Moulard committed
63
64
65
66
67
68
    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 );
    ~TimeDependency  () {}
69

Thomas Moulard's avatar
Thomas Moulard committed
70
71
72
    void addDependency( const SignalBase<Time>& sig );
    void removeDependency( const SignalBase<Time>& sig );
    void clearDependency  ();
Thomas Moulard's avatar
Thomas Moulard committed
73

74

Thomas Moulard's avatar
Thomas Moulard committed
75
76
77
78
    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
79

Thomas Moulard's avatar
Thomas Moulard committed
80
    bool needUpdate( const Time& t1 ) const;
81

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

Thomas Moulard's avatar
Thomas Moulard committed
84
85
    void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; }
    bool getNeedUpdateFromAllChildren  () const { return updateFromAllChildren; }
86

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

Thomas Moulard's avatar
Thomas Moulard committed
90
  };
91

Thomas Moulard's avatar
Thomas Moulard committed
92
} // end of namespace dynamicgraph
93

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