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




#ifndef __DEPENDANT_SIGNAL_HH
#define __DEPENDANT_SIGNAL_HH

26
#include <dynamic-graph/signal.h>
27

28
#include <dynamic-graph/time-dependency.h>
29
30
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

namespace dynamicgraph {

template< class T,class Time >
class SignalTimeDependant
: public virtual Signal<T,Time>
, public TimeDependancy<Time> 
{

  //TimeDependancy<Time> timeDependancy;

 public:
  SignalTimeDependant( std::string name = "" );
  SignalTimeDependant( const SignalArray_const<Time> & arr
			  ,std::string name = "" );
  SignalTimeDependant( boost::function2<T&,T&,Time> t
			  ,const SignalArray_const<Time> & sig
			  ,std::string name = "" );
  
  virtual ~SignalTimeDependant( void ) {}
  
  inline const T& operator() ( const Time& t1 ){ return access(t1); }
  const T& access( const Time& t1 );
  
  virtual void addDependancy( const SignalBase<Time>& signal ) ;
  virtual void removeDependancy( const SignalBase<Time>& signal ) ;
  virtual void clearDependancies( void );

  std::ostream& writeGraph(std::ostream &os) const
    { return os;}

  std::ostream& displayDependancies( std::ostream& os,const int depth=-1,
				     std::string space="",
				     std::string next1="",std::string next2="" ) const
    { return TimeDependancy<Time>::displayDependancies( os,depth,space,next1,next2 ); }

  
  virtual bool needUpdate( const Time& t ) const;
  virtual void setPeriodTime( const Time& p ) ;
  virtual Time getPeriodTime( void ) const;

};


/* -------------------------------------------- */


template < class T,class Time >
SignalTimeDependant<T,Time>::
SignalTimeDependant( std::string name )
    :Signal<T,Time>(name)
     ,TimeDependancy<Time>(this)
    {}

template< class T,class Time>
SignalTimeDependant<T,Time>::
SignalTimeDependant( const SignalArray_const<Time> & arr
			  ,std::string name )
    :Signal<T,Time>(name)
    ,TimeDependancy<Time>(this,arr)
    {}

template< class T,class Time>
SignalTimeDependant<T,Time>::
  SignalTimeDependant( boost::function2<T&,T&,Time> t
			  ,const SignalArray_const<Time> & sig
			  ,std::string name )
    :Signal<T,Time>(name)
    ,TimeDependancy<Time>(this,sig)
    { setFunction(t); }
 
template< class T,class Time>
  const T& SignalTimeDependant<T,Time>::
access( const Time& t1 )
    {
      const bool up = TimeDependancy<Time>::needUpdate(t1); 
      //SignalBase<Time>::setReady(false);

/*       std::cout << "Time before: "<< signalTime << " -- "   */
/*   		<< t1<< "  -> Up: "<<up <<std::endl ;   */
      if( up )
	{
	  TimeDependancy<Time>::lastAskForUpdate = false;
	  const T& Tres = Signal<T,Time>::access(t1);
	  SignalBase<Time>::setReady(false);    
	  return Tres;
	}
      else { return Signal<T,Time>::accessCopy(); }
    }


template< class T,class Time>
   void SignalTimeDependant<T,Time>::
addDependancy( const SignalBase<Time>& signal ) 
    { TimeDependancy<Time>::addDependancy(signal); }

template< class T,class Time>
   void SignalTimeDependant<T,Time>::
removeDependancy( const SignalBase<Time>& signal ) 
    { TimeDependancy<Time>::removeDependancy(signal); }

template< class T,class Time>
   void SignalTimeDependant<T,Time>::
clearDependancies( void )
    { TimeDependancy<Time>::clearDependancy(); }

template< class T,class Time>
  bool SignalTimeDependant<T,Time>::
needUpdate( const Time& t ) const
{
  return TimeDependancy<Time>::needUpdate(t); 
}

template< class T,class Time>
    void SignalTimeDependant<T,Time>::
setPeriodTime( const Time& p ) 
    { TimeDependancy<Time>::setPeriodTime( p ); }
template< class T,class Time>
 Time SignalTimeDependant<T,Time>::
getPeriodTime( void )  const
    { return TimeDependancy<Time>::getPeriodTime();  }

} // namespace dynamicgraph

#endif /* #ifndef __DEPENDANT_SIGNAL_HH */