time-dependency.h 2.3 KB
Newer Older
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
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      TimeDependancy.h
 * Project:   SOT
 * 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
35
36
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

template< class Time >
class TimeDependancy
{
 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:

  TimeDependancy( SignalBase<Time>* sig,
		     const DependancyType dep = DEPENDANCY_TYPE_DEFAULT );
  TimeDependancy( SignalBase<Time>* sig,
		     const SignalArray_const<Time>& arr, 
		     const DependancyType dep = DEPENDANCY_TYPE_DEFAULT );
  ~TimeDependancy( void ) {}

  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; }

};

93
#include <dynamic-graph/time-dependency.t.cpp>
94
95

#endif /* #ifndef __TIME_DEPENDANCY_HH */