6 #ifndef DYNAMIC_GRAPH_SIGNAL_T_CPP
7 #define DYNAMIC_GRAPH_SIGNAL_T_CPP
8 #include <dynamic-graph/signal-caster.h>
9 #include <dynamic-graph/signal.h>
11 #undef VP_TEMPLATE_DEBUG_MODE
12 #define VP_TEMPLATE_DEBUG_MODE 0
13 #include <dynamic-graph/debug.h>
15 #define __SIGNAL_INIT(name, Tcpy, Tref, TrefNC, mutex) \
16 SignalBase<Time>(name), signalType(SIGNAL_TYPE_DEFAULT), Tcopy1(Tcpy), \
17 Tcopy2(Tcpy), Tcopy(&Tcopy1), Treference(Tref), \
18 TreferenceNonConst(TrefNC), Tfunction(), \
19 keepReference(KEEP_REFERENCE_DEFAULT), providerMutex(mutex)
23 template <
class T,
class Time>
24 Signal<T, Time>::Signal(std::string name)
25 : __SIGNAL_INIT(name, T(), NULL, NULL, NULL) {
31 template <
class T,
class Time>
32 void Signal<T, Time>::set(std::istringstream &stringValue) {
36 template <
class T,
class Time>
37 void Signal<T, Time>::get(std::ostream &os)
const {
41 template <
class T,
class Time>
42 void Signal<T, Time>::trace(std::ostream &os)
const {
45 }
catch DG_RETHROW
catch (...) {
47 "TRACE operation not possible with this signal. ",
48 "(bad cast while getting value from %s).",
49 SignalBase<Time>::getName().c_str());
55 template <
class T,
class Time>
56 const T &Signal<T, Time>::setTcopy(
const T &t) {
57 if (Tcopy == &Tcopy1) {
70 template <
class T,
class Time>
71 T &Signal<T, Time>::getTwork() {
78 template <
class T,
class Time>
79 const T &Signal<T, Time>::getTwork()
const {
86 template <
class T,
class Time>
87 const T &Signal<T, Time>::switchTcopy() {
88 if (Tcopy == &Tcopy1) {
97 template <
class T,
class Time>
98 void Signal<T, Time>::setConstant(
const T &t) {
99 signalType = CONSTANT;
104 template <
class T,
class Time>
105 void Signal<T, Time>::setReference(
const T *t, Mutex *mutexref) {
106 signalType = REFERENCE;
108 providerMutex = mutexref;
113 template <
class T,
class Time>
114 void Signal<T, Time>::setReferenceNonConstant(T *t, Mutex *mutexref) {
115 signalType = REFERENCE_NON_CONST;
117 TreferenceNonConst = t;
118 providerMutex = mutexref;
123 template <
class T,
class Time>
124 void Signal<T, Time>::setFunction(boost::function2<T &, T &, Time> t,
126 signalType = FUNCTION;
128 providerMutex = mutexref;
133 template <
class T,
class Time>
134 const T &Signal<T, Time>::accessCopy()
const {
138 template <
class T,
class Time>
139 const T &Signal<T, Time>::access(
const Time &t) {
140 switch (signalType) {
142 case REFERENCE_NON_CONST: {
143 if (NULL == providerMutex) {
146 return setTcopy(*Treference);
149 #ifdef HAVE_LIBBOOST_THREAD
150 boost::try_mutex::scoped_try_lock lock(*providerMutex);
154 return setTcopy(*Treference);
155 }
catch (
const MutexError &) {
164 if (NULL == providerMutex) {
166 Tfunction(getTwork(), t);
168 return switchTcopy();
171 #ifdef HAVE_LIBBOOST_THREAD
172 boost::try_mutex::scoped_try_lock lock(*providerMutex);
175 Tfunction(getTwork(), t);
177 return switchTcopy();
178 }
catch (
const MutexError &) {
186 if (this->getReady()) {
194 template <
class T,
class Time>
195 Signal<T, Time> &Signal<T, Time>::operator=(
const T &t) {
196 if (keepReference && (REFERENCE_NON_CONST == signalType) &&
197 (NULL != TreferenceNonConst)) {
198 if (NULL == providerMutex) {
200 (*TreferenceNonConst) = t;
203 #ifdef HAVE_LIBBOOST_THREAD
204 boost::try_mutex::scoped_try_lock lock(*providerMutex);
207 (*TreferenceNonConst) = t;
208 }
catch (
const MutexError &) {
217 template <
class T,
class Time>
218 std::ostream &Signal<T, Time>::display(std::ostream &os)
const {
219 os <<
"Sig:" << this->name <<
" (Type ";
220 switch (this->signalType) {
221 case Signal<T, Time>::CONSTANT:
224 case Signal<T, Time>::REFERENCE:
227 case Signal<T, Time>::REFERENCE_NON_CONST:
230 case Signal<T, Time>::FUNCTION: