time-dependency.h 2.79 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
/*
 * Copyright 2010,
 * François Bleibel,
 * Olivier Stasse,
5
 *
Thomas Moulard's avatar
Thomas Moulard committed
6
 * CNRS/AIST
7
 *
Thomas Moulard's avatar
Thomas Moulard committed
8
9
10
11
12
13
14
15
16
17
18
19
 * 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 Lesser General 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/>.
 */
20

21
22
#ifndef __TIME_DEPENDENCY_HH
#define __TIME_DEPENDENCY_HH
23
24

#include <list>
Thomas Moulard's avatar
Thomas Moulard committed
25
#include <iostream>
26

27
28
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-array.h>
29

30
31
namespace dynamicgraph {

32
33
/** \brief A helper class for setting and specifying dependencies between signals.
 */
34
template< class Time >
35
class TimeDependency
36
37
{
 public:
38
  enum DependencyType
39
    {
Thomas Moulard's avatar
Thomas Moulard committed
40
      TIME_DEPENDENT,
41
      BOOL_DEPENDENT,
42
43
44
45
46
47
48
49
50
51
      ALWAYS_READY
    };

  mutable Time lastAskForUpdate;

  // protected:
 public:

  SignalBase< Time >& leader;

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

55
  Dependencies dependencies;
56
57
58
  bool updateFromAllChildren;
  static const bool ALL_READY_DEFAULT = false;

59
  DependencyType dependencyType;
60
61
62
63
64
65

  Time periodTime;
  static const Time PERIOD_TIME_DEFAULT = 1;

 public:

66
  TimeDependency( SignalBase<Time>* sig,
67
		     const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
68
  TimeDependency( SignalBase<Time>* sig,
Thomas Moulard's avatar
Thomas Moulard committed
69
		     const SignalArray_const<Time>& arr,
70
		     const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
71
  ~TimeDependency( void ) {}
72

73
74
75
  void addDependency( const SignalBase<Time>& sig );
  void removeDependency( const SignalBase<Time>& sig );
  void clearDependency( void );
Thomas Moulard's avatar
Thomas Moulard committed
76

77
78

  virtual std::ostream & writeGraph(std::ostream &os) const;
79
  std::ostream& displayDependencies( std::ostream& os,const int depth=-1,
80
81
				     std::string space="",
				     std::string next1="",std::string next2="" ) const;
Thomas Moulard's avatar
Thomas Moulard committed
82

83
84
  bool needUpdate( const Time& t1 ) const;

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

87
  void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; }
Thomas Moulard's avatar
Thomas Moulard committed
88
  bool getNeedUpdateFromAllChildren( void ) const { return updateFromAllChildren; }
89
90
91
92
93
94

  void setPeriodTime( const Time& p ) { periodTime = p; }
  Time getPeriodTime( void ) const { return periodTime; }

};

95
96
97
} // namespace dynamicgraph


98
#include <dynamic-graph/time-dependency.t.cpp>
99

100
#endif /* #ifndef __TIME_DEPENDENCY_HH */