include/dynamic-graph/signal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef __SIGNAL_HH
11 #define __SIGNAL_HH
12 
15 
16 #include <boost/bind.hpp>
17 #include <boost/function.hpp>
18 #include <string>
19 
20 #ifdef HAVE_LIBBOOST_THREAD
21 #include <boost/thread.hpp>
22 #endif
23 
24 namespace dynamicgraph {
25 
40 template <class T, class Time>
41 class Signal : public SignalBase<Time> {
42  protected:
45 
48  T *Tcopy;
49  bool copyInit;
50 
51  const T *Treference;
53  boost::function2<T &, T &, Time> Tfunction;
54 
56  const static bool KEEP_REFERENCE_DEFAULT = false;
57 
58  public:
59 #ifdef HAVE_LIBBOOST_THREAD
60  typedef boost::try_mutex Mutex;
61  typedef boost::lock_error MutexError;
62 #else
63  typedef int *Mutex;
64  typedef int *MutexError;
65 #endif
66 
67  protected:
70 
71  public:
73 
74  public:
75  /* --- Constructor/destrusctor --- */
76  Signal(std::string name);
77  virtual ~Signal() {}
78 
79  /* --- Generic In/Out function --- */
80  virtual void get(std::ostream &value) const;
81  virtual void set(std::istringstream &value);
82  virtual void trace(std::ostream &os) const;
83 
84  /* --- Generic Set function --- */
85  virtual void setConstant(const T &t);
86  virtual void setReference(const T *t, Mutex *mutexref = NULL);
87  virtual void setReferenceNonConstant(T *t, Mutex *mutexref = NULL);
88  virtual void setFunction(boost::function2<T &, T &, Time> t,
89  Mutex *mutexref = NULL);
90 
91  inline bool getKeepReference() { return keepReference; }
92  inline void setKeepReference(const bool &b) { keepReference = b; }
93 
94  /* --- Signal computation --- */
95  virtual const T &access(const Time &t);
96  virtual inline void recompute(const Time &t) { access(t); }
97  virtual const T &accessCopy() const;
98 
99  virtual std::ostream &display(std::ostream &os) const;
100 
101  /* --- Operators --- */
102  virtual inline const T &operator()(const Time &t) { return access(t); }
103  virtual Signal<T, Time> &operator=(const T &t);
104  inline operator const T &() const { return accessCopy(); }
105  virtual void getClassName(std::string &aClassName) const {
106  aClassName = typeid(this).name();
107  }
108 
109  private:
110  const T &setTcopy(const T &t);
111  T &getTwork();
112  const T &getTwork() const;
113  const T &switchTcopy();
114 };
115 
116 } // end of namespace dynamicgraph
117 
119 
120 #endif // #ifndef __SIGNAL_HH
121 
122 /*
123  * Local variables:
124  * c-basic-offset: 4
125  * End:
126  */
dynamicgraph::Signal::recompute
virtual void recompute(const Time &t)
Definition: include/dynamic-graph/signal.h:96
dynamicgraph::Signal< double, sigtime_t >::SignalType
SignalType
Definition: include/dynamic-graph/signal.h:43
dynamicgraph::Signal
Signals link I/O ports of entities. They can be constant-valued signals, or copy the value of a heap ...
Definition: fwd.hh:44
dynamicgraph::Signal::SIGNAL_TYPE_DEFAULT
static const SignalType SIGNAL_TYPE_DEFAULT
Definition: include/dynamic-graph/signal.h:44
dynamicgraph::Signal::get
virtual void get(std::ostream &value) const
Definition: signal.t.cpp:37
dynamicgraph::Signal::REFERENCE
@ REFERENCE
Definition: include/dynamic-graph/signal.h:43
dynamicgraph
dynamicgraph::Signal::operator=
virtual Signal< T, Time > & operator=(const T &t)
Definition: signal.t.cpp:195
dynamicgraph::Signal::operator()
virtual const T & operator()(const Time &t)
Definition: include/dynamic-graph/signal.h:102
dynamicgraph::Signal::accessCopy
virtual const T & accessCopy() const
Definition: signal.t.cpp:134
dynamicgraph::Signal::providerMutex
Mutex * providerMutex
Definition: include/dynamic-graph/signal.h:68
dynamicgraph::Signal::access
virtual const T & access(const Time &t)
Definition: signal.t.cpp:139
dynamicgraph::Signal::FUNCTION
@ FUNCTION
Definition: include/dynamic-graph/signal.h:43
dynamicgraph::Signal::setReference
virtual void setReference(const T *t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:105
dynamicgraph::Signal::~Signal
virtual ~Signal()
Definition: include/dynamic-graph/signal.h:77
dynamicgraph::Signal::getClassName
virtual void getClassName(std::string &aClassName) const
Definition: include/dynamic-graph/signal.h:105
signal.t.cpp
dynamicgraph::Signal::setFunction
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:124
dynamicgraph::Signal::MutexError
int * MutexError
Definition: include/dynamic-graph/signal.h:64
dynamicgraph::Signal::getTwork
T & getTwork()
Definition: signal.t.cpp:71
dynamicgraph::Signal::setTcopy
const T & setTcopy(const T &t)
Definition: signal.t.cpp:56
exception-signal.h
signal-base.h
dynamicgraph::Signal::switchTcopy
const T & switchTcopy()
Definition: signal.t.cpp:87
dynamicgraph::Signal::Signal
Signal(std::string name)
Definition: signal.t.cpp:24
dynamicgraph::Signal::Tcopy1
T Tcopy1
Definition: include/dynamic-graph/signal.h:47
dynamicgraph::Signal::copyInit
bool copyInit
Definition: include/dynamic-graph/signal.h:49
dynamicgraph::Signal::Tfunction
boost::function2< T &, T &, Time > Tfunction
Definition: include/dynamic-graph/signal.h:53
dynamicgraph::Signal::CONSTANT
@ CONSTANT
Definition: include/dynamic-graph/signal.h:43
dynamicgraph::Signal::trace
virtual void trace(std::ostream &os) const
Definition: signal.t.cpp:42
dynamicgraph::Signal::setConstant
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
dynamicgraph::Signal::keepReference
bool keepReference
Definition: include/dynamic-graph/signal.h:55
dynamicgraph::Signal::set
virtual void set(std::istringstream &value)
Definition: signal.t.cpp:32
dynamicgraph::Signal::display
virtual std::ostream & display(std::ostream &os) const
Definition: signal.t.cpp:218
dynamicgraph::Signal::Mutex
int * Mutex
Definition: include/dynamic-graph/signal.h:63
dynamicgraph::Signal::Tcopy2
T Tcopy2
Definition: include/dynamic-graph/signal.h:47
dynamicgraph::Signal::Treference
const T * Treference
Definition: include/dynamic-graph/signal.h:51
dynamicgraph::Signal::KEEP_REFERENCE_DEFAULT
const static bool KEEP_REFERENCE_DEFAULT
Definition: include/dynamic-graph/signal.h:56
dynamicgraph::Signal::getKeepReference
bool getKeepReference()
Definition: include/dynamic-graph/signal.h:91
dynamicgraph::Signal::signalType
SignalType signalType
Definition: include/dynamic-graph/signal.h:46
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
dynamicgraph::Signal::Tcopy
T * Tcopy
Definition: include/dynamic-graph/signal.h:48
dynamicgraph::Signal::setReferenceNonConstant
virtual void setReferenceNonConstant(T *t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:114
dynamicgraph::Signal::REFERENCE_NON_CONST
@ REFERENCE_NON_CONST
Definition: include/dynamic-graph/signal.h:43
compile.name
name
Definition: compile.py:23
dynamicgraph::Signal::TreferenceNonConst
T * TreferenceNonConst
Definition: include/dynamic-graph/signal.h:52
dynamicgraph::Signal::setKeepReference
void setKeepReference(const bool &b)
Definition: include/dynamic-graph/signal.h:92


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38