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
23
24
25
26
27
28
 * Author:    Nicolas Mansard
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/




#ifndef __TIME_DEPENDANCY_HH
#define __TIME_DEPENDANCY_HH

#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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{
 public:
  enum DependancyType
    {
      TIME_DEPENDANT, 
      BOOL_DEPENDANT,
      ALWAYS_READY
    };

  mutable Time lastAskForUpdate;

  // protected:
 public:

  SignalBase< Time >& leader;

  typedef std::list< const SignalBase<Time> * > Dependancies;
  static const DependancyType DEPENDANCY_TYPE_DEFAULT = TIME_DEPENDANT;

  Dependancies dependancies;
  bool updateFromAllChildren;
  static const bool ALL_READY_DEFAULT = false;

  DependancyType dependancyType;

  Time periodTime;
  static const Time PERIOD_TIME_DEFAULT = 1;

 public:

67
  TimeDependency( SignalBase<Time>* sig,
68
		     const DependancyType dep = DEPENDANCY_TYPE_DEFAULT );
69
  TimeDependency( SignalBase<Time>* sig,
70
71
		     const SignalArray_const<Time>& arr, 
		     const DependancyType dep = DEPENDANCY_TYPE_DEFAULT );
72
  ~TimeDependency( void ) {}
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

  void addDependancy( const SignalBase<Time>& sig );
  void removeDependancy( const SignalBase<Time>& sig );
  void clearDependancy( void );
  

  virtual std::ostream & writeGraph(std::ostream &os) const;
  std::ostream& displayDependancies( std::ostream& os,const int depth=-1,
				     std::string space="",
				     std::string next1="",std::string next2="" ) const;
  
  bool needUpdate( const Time& t1 ) const;

  void setDependancyType( DependancyType dep ) { dependancyType = dep; }
  
  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_DEPENDANCY_HH */