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:
37 
38  inline bool autoref() const { return signalPtr == this; }
39 
40  public: /* --- CONSTRUCTORS --- */
41  SignalPtr(Signal<T, Time> *ptr, std::string name = "")
42  : Signal<T, Time>(name),
43  signalPtr(ptr),
44  modeNoThrow(false),
45  transmitAbstract(false),
46  abstractTransmitter(NULL) {}
47 
48  virtual ~SignalPtr() { signalPtr = NULL; }
49 
50  public:
51  /* --- PLUG-IN OPERATION --- */
52  Signal<T, Time> *getPtr(); // throw
53  const Signal<T, Time> *getPtr() const; // throw
54  SignalBase<Time> *getAbstractPtr(); // throw
55  const SignalBase<Time> *getAbstractPtr() const; // throw
56  virtual void plug(SignalBase<Time> *ref);
57 
58  virtual void unplug() { plug(NULL); }
59 
60  virtual bool isPlugged() const { return (NULL != signalPtr); }
61  virtual SignalBase<Time> *getPluged() const { return signalPtr; }
62  virtual bool isAbstractPluged() const;
63  virtual const Time &getTime() const;
64 
65  /* Equivalent operator-like definitions. */
66  inline Signal<T, Time> *operator->() { return getPtr(); }
67  inline const Signal<T, Time> *operator->() const { return getPtr(); }
68  inline Signal<T, Time> &operator*() { return *getPtr(); }
69  inline const Signal<T, Time> &operator*() const { return *getPtr(); }
70  inline operator bool() const { return isPlugged(); }
71 
72  public: /* --- INHERITANCE --- */
73  virtual bool needUpdate(const Time &t) const;
74  virtual std::ostream &writeGraph(std::ostream &os) const;
75  virtual std::ostream &display(std::ostream &os) const;
76 
77  /* For compatibility, .access () is equivalent to ->access (). For explicit
78  * pointer dereference :
79  * Prefere -> () to ()
80  */
81  virtual const T &operator()(const Time &t);
82  /* Similarly, Prefere ->access to .access
83  */
84  virtual const T &access(const Time &t);
85  virtual const T &accessCopy() const;
86 
87  inline void setConstantDefault(const T &t) {
89  modeNoThrow = true;
90  }
91  virtual inline void setConstantDefault() { setConstantDefault(accessCopy()); }
92  inline void unsetConstantDefault() { modeNoThrow = false; }
93 
94  virtual void checkCompatibility();
95 
96  public: /* --- INHERITANCE --- */
97  /* SignalPtr could be used as a classical signal, through the normal
98  * setting functions. The behavior is to plugged the signalPtr on
99  * the classical mother Signal layer of the object.
100  */
101  virtual void setConstant(const T &t) {
102  plug(this);
104  }
105  virtual void setReference(const T *t,
106  typename Signal<T, Time>::Mutex *m = NULL) {
107  plug(this);
109  }
110  virtual void setFunction(boost::function2<T &, T &, Time> t,
111  typename Signal<T, Time>::Mutex *m = NULL) {
112  plug(this);
114  }
115 
116  /* template< class Provider > */
117  /* void setFunction( T& (Provider::*fun)(Time,T&),Provider& obj, */
118  /* boost::try_mutex *mutexref=NULL ) */
119  /* { plug(this); Signal<T,Time>::setFunction(fun,obj,mutexref); } */
120 
121  virtual inline Signal<T, Time> &operator=(const T &t) {
122  setConstant(t);
123  return *this;
124  }
125 
126  virtual std::ostream &displayDependencies(std::ostream &os,
127  const int depth = -1,
128  std::string space = "",
129  std::string next1 = "",
130  std::string next2 = "") const;
131 
132  protected: // Interdiction of the rest of the heritage
134  virtual void addDependency() {}
136  virtual void removeDependency() {}
137  virtual void clearDependencies() {}
138 };
139 
140 } // end of namespace dynamicgraph
141 
143 #endif
Signal< T, Time > * signalPtr
Definition: signal-ptr.h:32
virtual void removeDependency()
Definition: signal-ptr.h:136
virtual void setConstantDefault()
Definition: signal-ptr.h:91
virtual bool isAbstractPluged() const
virtual void setFunction(boost::function2< T &, T &, Time > t, typename Signal< T, Time >::Mutex *m=NULL)
Definition: signal-ptr.h:110
virtual void unplug()
Definition: signal-ptr.h:58
Signal< T, Time > * operator->()
Definition: signal-ptr.h:66
virtual void setReference(const T *t, typename Signal< T, Time >::Mutex *m=NULL)
Definition: signal-ptr.h:105
virtual void clearDependencies()
Definition: signal-ptr.h:137
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
virtual std::ostream & displayDependencies(std::ostream &os, const int depth=-1, std::string space="", std::string next1="", std::string next2="") const
Signals link I/O ports of entities. They can be constant-valued signals, or copy the value of a heap ...
Definition: fwd.hh:42
const Signal< T, Time > & operator*() const
Definition: signal-ptr.h:69
SignalPtr(Signal< T, Time > *ptr, std::string name="")
Definition: signal-ptr.h:41
void setConstantDefault(const T &t)
Definition: signal-ptr.h:87
virtual void setConstant(const T &t)
Definition: signal-ptr.h:101
const std::string & getName() const
Definition: signal-base.h:42
virtual std::ostream & writeGraph(std::ostream &os) const
virtual void plug(SignalBase< Time > *ref)
virtual const T & access(const Time &t)
The base class for signals: not to be used as such.
Definition: fwd.hh:51
virtual void checkCompatibility()
virtual const Time & getTime() const
virtual const T & operator()(const Time &t)
virtual const T & accessCopy() const
SignalBase< Time > * getAbstractPtr()
const Signal< T, Time > * operator->() const
Definition: signal-ptr.h:67
virtual void addDependency()
Definition: signal-ptr.h:134
virtual bool isPlugged() const
Definition: signal-ptr.h:60
virtual std::ostream & display(std::ostream &os) const
virtual Signal< T, Time > & operator=(const T &t)
Definition: signal-ptr.h:121
virtual bool needUpdate(const Time &t) const
Signal< T, Time > * getPtr()
virtual SignalBase< Time > * getPluged() const
Definition: signal-ptr.h:61
bool autoref() const
Definition: signal-ptr.h:38
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
Definition: signal.t.cpp:124
Signal< T, Time > & operator*()
Definition: signal-ptr.h:68
SignalBase< Time > * abstractTransmitter
Definition: signal-ptr.h:35
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