signal-ptr.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3 // JRL, CNRS/AIST.
4 //
5 
6 #ifndef DYNAMIC_GRAPH_SIGNAL_PTR_H
7 #define DYNAMIC_GRAPH_SIGNAL_PTR_H
8 
10 #include <dynamic-graph/signal.h>
11 
12 namespace dynamicgraph {
26 template <class T, class Time>
27 class SignalPtr : public virtual Signal<T, Time> {
28  public:
30 
31  protected:
36 
37  inline bool autoref() const { return signalPtr == this; }
38 
39  public: /* --- CONSTRUCTORS --- */
40  SignalPtr(Signal<T, Time> *ptr, std::string name = "")
41  : Signal<T, Time>(name),
42  signalPtr(ptr),
43  modeNoThrow(false),
44  abstractTransmitter(NULL) {}
45 
46  virtual ~SignalPtr() { signalPtr = NULL; }
47 
48  public:
49  /* --- PLUG-IN OPERATION --- */
50  Signal<T, Time> *getPtr(); // throw
51  const Signal<T, Time> *getPtr() const; // throw
52  virtual void plug(SignalBase<Time> *ref);
53 
54  virtual void unplug() { plug(NULL); }
55 
56  virtual bool isPlugged() const { return (NULL != signalPtr); }
57  virtual SignalBase<Time> *getPluged() const { return signalPtr; }
58  virtual const Time &getTime() const;
59 
60  /* Equivalent operator-like definitions. */
61  inline Signal<T, Time> *operator->() { return getPtr(); }
62  inline const Signal<T, Time> *operator->() const { return getPtr(); }
63  inline Signal<T, Time> &operator*() { return *getPtr(); }
64  inline const Signal<T, Time> &operator*() const { return *getPtr(); }
65  inline operator bool() const { return isPlugged(); }
66 
67  public: /* --- INHERITANCE --- */
68  virtual bool needUpdate(const Time &t) const;
69  virtual std::ostream &writeGraph(std::ostream &os) const;
70  virtual std::ostream &display(std::ostream &os) const;
71 
72  /* For compatibility, .access () is equivalent to ->access (). For explicit
73  * pointer dereference :
74  * Prefere -> () to ()
75  */
76  virtual const T &operator()(const Time &t);
77  /* Similarly, Prefere ->access to .access
78  */
79  virtual const T &access(const Time &t);
80  virtual const T &accessCopy() const;
81 
82  inline void setConstantDefault(const T &t) {
84  modeNoThrow = true;
85  }
86  virtual inline void setConstantDefault() { setConstantDefault(accessCopy()); }
87  inline void unsetConstantDefault() { modeNoThrow = false; }
88 
89  public: /* --- INHERITANCE --- */
90  /* SignalPtr could be used as a classical signal, through the normal
91  * setting functions. The behavior is to plugged the signalPtr on
92  * the classical mother Signal layer of the object.
93  */
94  virtual void setConstant(const T &t) {
95  plug(this);
97  }
98  virtual void setReference(const T *t,
99  typename Signal<T, Time>::Mutex *m = NULL) {
100  plug(this);
102  }
103  virtual void setFunction(boost::function2<T &, T &, Time> t,
104  typename Signal<T, Time>::Mutex *m = NULL) {
105  plug(this);
107  }
108 
109  /* template< class Provider > */
110  /* void setFunction( T& (Provider::*fun)(Time,T&),Provider& obj, */
111  /* boost::try_mutex *mutexref=NULL ) */
112  /* { plug(this); Signal<T,Time>::setFunction(fun,obj,mutexref); } */
113 
114  virtual inline Signal<T, Time> &operator=(const T &t) {
115  setConstant(t);
116  return *this;
117  }
118 
119  virtual std::ostream &displayDependencies(std::ostream &os,
120  const int depth = -1,
121  std::string space = "",
122  std::string next1 = "",
123  std::string next2 = "") const;
124 
125  protected: // Interdiction of the rest of the heritage
127  virtual void addDependency() {}
129  virtual void removeDependency() {}
130  virtual void clearDependencies() {}
131 };
132 
133 } // end of namespace dynamicgraph
134 
136 #endif
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::SignalPtr::operator*
const Signal< T, Time > & operator*() const
Definition: signal-ptr.h:64
dynamicgraph::SignalPtr::getPtr
Signal< T, Time > * getPtr()
Definition: signal-ptr.t.cpp:16
dynamicgraph::SignalPtr::accessCopy
virtual const T & accessCopy() const
Definition: signal-ptr.t.cpp:97
dynamicgraph::SignalPtr::setConstant
virtual void setConstant(const T &t)
Definition: signal-ptr.h:94
dynamicgraph
dynamicgraph::SignalPtr::operator=
virtual Signal< T, Time > & operator=(const T &t)
Definition: signal-ptr.h:114
dynamicgraph::SignalPtr::addDependency
virtual void addDependency()
Definition: signal-ptr.h:127
dynamicgraph::SignalPtr::removeDependency
virtual void removeDependency()
Definition: signal-ptr.h:129
dynamicgraph::SignalPtr::plug
virtual void plug(SignalBase< Time > *ref)
Definition: signal-ptr.t.cpp:41
dynamicgraph::SignalPtr::operator*
Signal< T, Time > & operator*()
Definition: signal-ptr.h:63
dynamicgraph::Signal::setReference
virtual void setReference(const T *t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:105
dynamicgraph::SignalPtr::setFunction
virtual void setFunction(boost::function2< T &, T &, Time > t, typename Signal< T, Time >::Mutex *m=NULL)
Definition: signal-ptr.h:103
signal-ptr.t.cpp
dynamicgraph::Signal::setFunction
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:124
dynamicgraph::SignalPtr::setReference
virtual void setReference(const T *t, typename Signal< T, Time >::Mutex *m=NULL)
Definition: signal-ptr.h:98
dynamicgraph::SignalPtr::clearDependencies
virtual void clearDependencies()
Definition: signal-ptr.h:130
dynamicgraph::SignalPtr::writeGraph
virtual std::ostream & writeGraph(std::ostream &os) const
Definition: signal-ptr.t.cpp:106
dynamicgraph::SignalPtr::needUpdate
virtual bool needUpdate(const Time &t) const
Definition: signal-ptr.t.cpp:61
dynamicgraph::SignalPtr::getPluged
virtual SignalBase< Time > * getPluged() const
Definition: signal-ptr.h:57
dynamicgraph::SignalPtr::access
virtual const T & access(const Time &t)
Definition: signal-ptr.t.cpp:82
exception-signal.h
dynamicgraph::SignalPtr::getTime
virtual const Time & getTime() const
Definition: signal-ptr.t.cpp:69
dynamicgraph::SignalPtr::display
virtual std::ostream & display(std::ostream &os) const
Definition: signal-ptr.t.cpp:122
dynamicgraph::SignalPtr::signalPtr
Signal< T, Time > * signalPtr
Definition: signal-ptr.h:32
dynamicgraph::SignalBase::getName
const std::string & getName() const
Definition: signal-base.h:42
dynamicgraph::SignalPtr::modeNoThrow
bool modeNoThrow
Definition: signal-ptr.h:33
dynamicgraph::Signal::setConstant
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
dynamicgraph::SignalPtr::abstractTransmitter
SignalBase< Time > * abstractTransmitter
Definition: signal-ptr.h:34
dynamicgraph::SignalPtr::transmitAbstractData
T * transmitAbstractData
Definition: signal-ptr.h:35
dynamicgraph::SignalPtr::setConstantDefault
void setConstantDefault(const T &t)
Definition: signal-ptr.h:82
dynamicgraph::SignalPtr::~SignalPtr
virtual ~SignalPtr()
Definition: signal-ptr.h:46
dynamicgraph::SignalPtr::unsetConstantDefault
void unsetConstantDefault()
Definition: signal-ptr.h:87
dynamicgraph::Signal::Mutex
int * Mutex
Definition: include/dynamic-graph/signal.h:63
dynamicgraph::SignalPtr::operator->
const Signal< T, Time > * operator->() const
Definition: signal-ptr.h:62
dynamicgraph::SignalPtr::setConstantDefault
virtual void setConstantDefault()
Definition: signal-ptr.h:86
dynamicgraph::SignalPtr::displayDependencies
virtual std::ostream & displayDependencies(std::ostream &os, const int depth=-1, std::string space="", std::string next1="", std::string next2="") const
Definition: signal-ptr.t.cpp:141
dynamicgraph::SignalPtr::autoref
bool autoref() const
Definition: signal-ptr.h:37
dynamicgraph::SignalPtr::isPlugged
virtual bool isPlugged() const
Definition: signal-ptr.h:56
dynamicgraph::SignalPtr::unplug
virtual void unplug()
Definition: signal-ptr.h:54
dynamicgraph::SignalPtr::operator()
virtual const T & operator()(const Time &t)
Definition: signal-ptr.t.cpp:77
dynamicgraph::SignalPtr::SignalPtr
SignalPtr(Signal< T, Time > *ptr, std::string name="")
Definition: signal-ptr.h:40
dynamicgraph::SignalPtr::operator->
Signal< T, Time > * operator->()
Definition: signal-ptr.h:61
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
signal.h
compile.name
name
Definition: compile.py:23


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