13 #include <dynamic-graph/exception-signal.h>
14 #include <dynamic-graph/signal-base.h>
16 #include <boost/bind.hpp>
17 #include <boost/function.hpp>
20 #ifdef HAVE_LIBBOOST_THREAD
21 #include <boost/thread.hpp>
40 template <
class T,
class Time>
41 class Signal :
public SignalBase<Time> {
43 enum SignalType { CONSTANT, REFERENCE, REFERENCE_NON_CONST, FUNCTION };
44 static const SignalType SIGNAL_TYPE_DEFAULT = CONSTANT;
46 SignalType signalType;
52 T *TreferenceNonConst;
53 boost::function2<T &, T &, Time> Tfunction;
56 const static bool KEEP_REFERENCE_DEFAULT =
false;
59 #ifdef HAVE_LIBBOOST_THREAD
60 typedef boost::try_mutex Mutex;
61 typedef boost::lock_error MutexError;
64 typedef int *MutexError;
69 using SignalBase<Time>::signalTime;
72 using SignalBase<Time>::setReady;
76 Signal(std::string name);
80 virtual void get(std::ostream &value)
const;
81 virtual void set(std::istringstream &value);
82 virtual void trace(std::ostream &os)
const;
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);
91 inline bool getKeepReference() {
return keepReference; }
92 inline void setKeepReference(
const bool &b) { keepReference = b; }
95 virtual const T &access(
const Time &t);
96 virtual inline void recompute(
const Time &t) { access(t); }
97 virtual const T &accessCopy()
const;
99 virtual std::ostream &display(std::ostream &os)
const;
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();
115 const T &setTcopy(
const T &t);
117 const T &getTwork()
const;
118 const T &switchTcopy();
123 #include <dynamic-graph/signal.t.cpp>
125 #endif // #ifndef __SIGNAL_HH