time-dependency.h 2.37 KB
Newer Older
1
2
3
4
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
5
 * File:      TimeDependency.h
6
 * Project:   DYNAMIC-GRAPH
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 * Author:    Nicolas Mansard
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/




23
24
#ifndef __TIME_DEPENDENCY_HH
#define __TIME_DEPENDENCY_HH
25
26
27
28

#include <list>
#include <iostream> 

29
30
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-array.h>
31

32
33
34
namespace dynamicgraph {


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

  mutable Time lastAskForUpdate;

  // protected:
 public:

  SignalBase< Time >& leader;

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

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

60
  DependencyType dependencyType;
61
62
63
64
65
66

  Time periodTime;
  static const Time PERIOD_TIME_DEFAULT = 1;

 public:

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

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

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

86
  void setDependencyType( DependencyType dep ) { dependencyType = dep; }
87
88
89
90
91
92
93
94
95
  
  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; }

};

96
97
98
} // namespace dynamicgraph


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

101
#endif /* #ifndef __TIME_DEPENDENCY_HH */