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:
68  Mutex *providerMutex;
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  public:
112  virtual void checkCompatibility() { throw Tcopy; }
113 
114  private:
115  const T &setTcopy(const T &t);
116  T &getTwork();
117  const T &getTwork() const;
118  const T &switchTcopy();
119 };
120 
121 } // end of namespace dynamicgraph
122 
124 
125 #endif // #ifndef __SIGNAL_HH
126 
127 /*
128  * Local variables:
129  * c-basic-offset: 4
130  * End:
131  */
virtual void getClassName(std::string &aClassName) const
virtual std::ostream & display(std::ostream &os) const
Definition: signal.t.cpp:218
boost::function2< T &, T &, Time > Tfunction
static const bool KEEP_REFERENCE_DEFAULT
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
Signals link I/O ports of entities. They can be constant-valued signals, or copy the value of a heap ...
Definition: fwd.hh:42
The base class for signals: not to be used as such.
Definition: fwd.hh:51
void setKeepReference(const bool &b)
virtual void recompute(const Time &t)
virtual void setReferenceNonConstant(T *t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:114
const T & setTcopy(const T &t)
Definition: signal.t.cpp:56
static const SignalType SIGNAL_TYPE_DEFAULT
virtual Signal< T, Time > & operator=(const T &t)
Definition: signal.t.cpp:195
virtual const T & operator()(const Time &t)
virtual const T & accessCopy() const
Definition: signal.t.cpp:134
const T & switchTcopy()
Definition: signal.t.cpp:87
Signal(std::string name)
Definition: signal.t.cpp:24
virtual void trace(std::ostream &os) const
Definition: signal.t.cpp:42
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:124
virtual const T & access(const Time &t)
Definition: signal.t.cpp:139
virtual void setReference(const T *t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:105


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03