time-dependency.h 2.71 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
25
26

#include <list>
#include <iostream> 

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

30
31
32
namespace dynamicgraph {


33
template< class Time >
34
class TimeDependency
35
36
{
 public:
37
  enum DependencyType
38
    {
39
40
      TIME_DEPENDENT, 
      BOOL_DEPENDENT,
41
42
43
44
45
46
47
48
49
50
      ALWAYS_READY
    };

  mutable Time lastAskForUpdate;

  // protected:
 public:

  SignalBase< Time >& leader;

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

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

58
  DependencyType dependencyType;
59
60
61
62
63
64

  Time periodTime;
  static const Time PERIOD_TIME_DEFAULT = 1;

 public:

65
  TimeDependency( SignalBase<Time>* sig,
66
		     const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
67
  TimeDependency( SignalBase<Time>* sig,
68
		     const SignalArray_const<Time>& arr, 
69
		     const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
70
  ~TimeDependency( void ) {}
71

72
73
74
  void addDependency( const SignalBase<Time>& sig );
  void removeDependency( const SignalBase<Time>& sig );
  void clearDependency( void );
75
76
77
  

  virtual std::ostream & writeGraph(std::ostream &os) const;
78
  std::ostream& displayDependencies( std::ostream& os,const int depth=-1,
79
80
81
82
83
				     std::string space="",
				     std::string next1="",std::string next2="" ) const;
  
  bool needUpdate( const Time& t1 ) const;

84
  void setDependencyType( DependencyType dep ) { dependencyType = dep; }
85
86
87
88
89
90
91
92
93
  
  void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; }
  bool getNeedUpdateFromAllChildren( void ) const { return updateFromAllChildren; } 

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

};

94
95
96
} // namespace dynamicgraph


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

99
#endif /* #ifndef __TIME_DEPENDENCY_HH */