signal-ptr.t.cpp
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_T_CPP
7 #define DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP
9 
10 #undef VP_TEMPLATE_DEBUG_MODE
11 #define VP_TEMPLATE_DEBUG_MODE 0
12 #include <dynamic-graph/debug.h>
13 
14 namespace dynamicgraph {
15 template <class T, class Time>
17  return ((NULL != signalPtr) || (abstractTransmitter));
18 }
19 
20 template <class T, class Time>
22  dgTDEBUGIN(25);
23  if (!isPlugged()) DG_THROW
25  "In SignalPtr: SIN ptr not set.", " (in signal <%s>)",
26  getName().c_str());
27  dgTDEBUGOUT(25);
28  return signalPtr;
29 }
30 
31 template <class T, class Time>
33  dgTDEBUGIN(25) << SignalBase<Time>::name << "(" << isPlugged() << ")" << this
34  << "->" << signalPtr << std::endl;
35  dgTDEBUGIN(25);
36  if (!isPlugged()) {
38  "In SignalPtr: SIN ptr not set.",
39  " (in signal <%s>)", getName().c_str());
40  }
41  dgTDEBUGOUT(25);
42  return signalPtr;
43 }
44 
45 template <class T, class Time>
47  if (!isAbstractPluged()) {
49  "In SignalPtr: SIN ptr not set.",
50  " (in signal <%s>)", getName().c_str());
51  }
52  if (NULL != signalPtr)
53  return signalPtr;
54  else
55  return abstractTransmitter;
56 }
57 
58 template <class T, class Time>
60  if (!isAbstractPluged()) {
62  "In SignalPtr: SIN ptr not set.",
63  " (in signal <%s>)", getName().c_str());
64  }
65  if (NULL != signalPtr)
66  return signalPtr;
67  else
68  return abstractTransmitter;
69 }
70 
71 template <class T, class Time>
73  dgTDEBUGIN(5);
74  if (!unknown_ref) {
75  signalPtr = NULL;
76  transmitAbstract = false;
77  dgTDEBUGOUT(5);
78  return;
79  }
80 
81  dgTDEBUG(5) << "# In T = " << getName() << " ="
82  << typeid(Signal<T, Time>::Tcopy1).name() << "{ " << std::endl;
83 
84  Signal<T, Time> *ref = dynamic_cast<Signal<T, Time> *>(unknown_ref);
85  if (NULL == ref) {
86  try {
87  unknown_ref->checkCompatibility();
88  } catch (T *t) {
89  dgTDEBUG(25) << "Cast THROW ok." << std::endl;
91  transmitAbstract = true;
92  abstractTransmitter = unknown_ref;
93  transmitAbstractData = t;
94  } catch (...) {
95  dgTDEBUG(25) << "Fatal error." << std::endl;
96  transmitAbstract = false;
98  "Compl. Uncompatible types for plugin.",
99  "(while trying to plug <%s> on <%s>)"
100  " with types <%s> on <%s>.",
101  unknown_ref->getName().c_str(),
102  this->getName().c_str(), typeid(T).name(),
103  typeid(unknown_ref).name());
104  }
105  } else {
106  dgTDEBUG(25) << "Cast ok." << std::endl;
107  transmitAbstract = false;
108  signalPtr = ref;
109  }
110  dgTDEBUGOUT(5);
111 }
112 
113 template <class T, class Time>
115  if (isPlugged() && (!autoref())) {
116  getPtr()->checkCompatibility();
117  } else if (isAbstractPluged() && (!autoref())) {
118  abstractTransmitter->checkCompatibility();
119  } else
121 }
122 
123 template <class T, class Time>
124 bool SignalPtr<T, Time>::needUpdate(const Time &t) const {
125  if ((isAbstractPluged()) && (!autoref())) {
126  return getAbstractPtr()->needUpdate(t);
127  } else
128  return Signal<T, Time>::needUpdate(t);
129 }
130 
131 template <class T, class Time>
132 const Time &SignalPtr<T, Time>::getTime() const {
133  if ((isAbstractPluged()) && (!autoref())) {
134  return getAbstractPtr()->getTime();
135  }
136  return Signal<T, Time>::getTime();
137 }
138 
139 template <class T, class Time>
140 const T &SignalPtr<T, Time>::operator()(const Time &t) {
141  return access(t);
142 }
143 
144 template <class T, class Time>
145 const T &SignalPtr<T, Time>::access(const Time &t) {
146  dgTDEBUGIN(15);
147  if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit) {
148  dgTDEBUGOUT(15);
150  } else if (autoref()) {
151  dgTDEBUGOUT(15);
152  return Signal<T, Time>::access(t);
153  } else if (transmitAbstract) {
154  abstractTransmitter->recompute(t);
155  dgTDEBUGOUT(15);
156  return *transmitAbstractData;
157  } else {
158  dgTDEBUGOUT(15);
159  return getPtr()->access(t);
160  }
161 }
162 
163 template <class T, class Time>
165  if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit)
167  else if (autoref())
169  else if (transmitAbstract)
170  return *transmitAbstractData;
171  else
172  return getPtr()->accessCopy();
173 }
174 template <class T, class Time>
175 std::ostream &SignalPtr<T, Time>::writeGraph(std::ostream &os) const {
176  std::string LeaderLocalName;
177  std::string LeaderNodeName;
178  Signal<T, Time>::ExtractNodeAndLocalNames(LeaderLocalName, LeaderNodeName);
179  if (isAbstractPluged() && !autoref()) {
180  std::string itLocalName, itNodeName;
181  getAbstractPtr()->ExtractNodeAndLocalNames(itLocalName, itNodeName);
182  os << "\t\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\""
183  << std::endl
184  << "\t [ headlabel = \"" << LeaderLocalName << "\" , taillabel = \""
185  << itLocalName << "\", fontsize=7, fontcolor=red ]" << std::endl;
186  }
187  return os;
188 }
189 
190 template <class T, class Time>
191 std::ostream &SignalPtr<T, Time>::display(std::ostream &os) const {
192  dgTDEBUGIN(25) << SignalBase<Time>::name << this << "||" << isPlugged()
193  << "||" << signalPtr;
194  { Signal<T, Time>::display(os); }
195 
196  if ((isAbstractPluged()) && (!autoref())) {
197  os << " -->-- PLUGGED";
198  } else {
199  if (!isAbstractPluged())
200  os << " UNPLUGGED";
201  else if (autoref())
202  os << " AUTOPLUGGED";
203  }
204 
205  dgTDEBUGOUT(25);
206  return os;
207 }
208 
209 template <class T, class Time>
210 std::ostream &SignalPtr<T, Time>::displayDependencies(std::ostream &os,
211  const int depth,
212  std::string space,
213  std::string next1,
214  std::string next2) const {
215  dgTDEBUGIN(25);
216  if ((isAbstractPluged()) && (!autoref())) {
217  getAbstractPtr()->displayDependencies(
218  os, depth, space, next1 + "-- " + SignalBase<Time>::name + " -->",
219  next2);
220  } else {
221  SignalBase<Time>::displayDependencies(os, depth, space, next1, next2);
222  }
223  dgTDEBUGOUT(25);
224  return os;
225 }
226 
227 } // end of namespace dynamicgraph.
228 
229 #endif
#define dgTDEBUGOUT(level)
Definition: debug.h:210
virtual void ExtractNodeAndLocalNames(std::string &LocalName, std::string &NodeName) const
Definition: signal-base.h:174
virtual std::ostream & display(std::ostream &os) const
Definition: signal.t.cpp:218
virtual bool isAbstractPluged() const
#define dgTDEBUG(level)
Definition: debug.h:187
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
Exceptions raised when an error related to signals happen.
#define dgTDEBUGIN(level)
Definition: debug.h:208
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 void checkCompatibility()
Definition: signal-base.h:191
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()
virtual bool needUpdate(const Time &) const
Definition: signal-base.h:63
#define DG_THROW
virtual std::ostream & display(std::ostream &os) const
virtual const T & accessCopy() const
Definition: signal.t.cpp:134
virtual const Time & getTime() const
Definition: signal-base.h:36
virtual bool needUpdate(const Time &t) const
Signal< T, Time > * getPtr()
virtual std::ostream & displayDependencies(std::ostream &os, const int=-1, std::string space="", std::string next1="", std::string="") const
Definition: signal-base.h:69
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