6 #ifndef DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP 7 #define DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP 8 #include <dynamic-graph/signal-ptr.h> 10 #undef VP_TEMPLATE_DEBUG_MODE 11 #define VP_TEMPLATE_DEBUG_MODE 0 12 #include <dynamic-graph/debug.h> 15 template <
class T,
class Time>
16 bool SignalPtr<T, Time>::isAbstractPluged()
const {
17 return ((NULL != signalPtr) || (abstractTransmitter));
20 template <
class T,
class Time> Signal<T, Time> *SignalPtr<T, Time>::getPtr() {
24 ExceptionSignal(ExceptionSignal::NOT_INITIALIZED,
25 "In SignalPtr: SIN ptr not set.",
" (in signal <%s>)",
31 template <
class T,
class Time>
32 const Signal<T, Time> *SignalPtr<T, Time>::getPtr()
const {
33 dgTDEBUGIN(25) << SignalBase<Time>::name <<
"(" << isPlugged() <<
")" <<
this 34 <<
"->" << signalPtr << std::endl;
37 DG_THROW ExceptionSignal(ExceptionSignal::NOT_INITIALIZED,
38 "In SignalPtr: SIN ptr not set.",
39 " (in signal <%s>)", getName().c_str());
45 template <
class T,
class Time>
46 SignalBase<Time> *SignalPtr<T, Time>::getAbstractPtr() {
47 if (!isAbstractPluged()) {
48 DG_THROW ExceptionSignal(ExceptionSignal::NOT_INITIALIZED,
49 "In SignalPtr: SIN ptr not set.",
50 " (in signal <%s>)", getName().c_str());
52 if (NULL != signalPtr)
55 return abstractTransmitter;
58 template <
class T,
class Time>
59 const SignalBase<Time> *SignalPtr<T, Time>::getAbstractPtr()
const {
60 if (!isAbstractPluged()) {
61 DG_THROW ExceptionSignal(ExceptionSignal::NOT_INITIALIZED,
62 "In SignalPtr: SIN ptr not set.",
63 " (in signal <%s>)", getName().c_str());
65 if (NULL != signalPtr)
68 return abstractTransmitter;
71 template <
class T,
class Time>
72 void SignalPtr<T, Time>::plug(SignalBase<Time> *unknown_ref) {
76 transmitAbstract =
false;
81 dgTDEBUG(5) <<
"# In T = " << getName() <<
" =" 82 <<
typeid(Signal<T, Time>::Tcopy1).name() <<
"{ " << std::endl;
84 Signal<T, Time> *ref =
dynamic_cast<Signal<T, Time> *
>(unknown_ref);
87 unknown_ref->checkCompatibility();
89 dgTDEBUG(25) <<
"Cast THROW ok." << std::endl;
90 Signal<T, Time>::setReference(t);
91 transmitAbstract =
true;
92 abstractTransmitter = unknown_ref;
93 transmitAbstractData = t;
95 dgTDEBUG(25) <<
"Fatal error." << std::endl;
96 transmitAbstract =
false;
97 DG_THROW ExceptionSignal(ExceptionSignal::PLUG_IMPOSSIBLE,
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());
106 dgTDEBUG(25) <<
"Cast ok." << std::endl;
107 transmitAbstract =
false;
114 if (isPlugged() && (!autoref())) {
115 getPtr()->checkCompatibility();
116 }
else if (isAbstractPluged() && (!autoref())) {
117 abstractTransmitter->checkCompatibility();
122 template <
class T,
class Time>
124 if ((isAbstractPluged()) && (!autoref())) {
125 return getAbstractPtr()->needUpdate(t);
131 if ((isAbstractPluged()) && (!autoref())) {
132 return getAbstractPtr()->getTime();
137 template <
class T,
class Time>
142 template <
class T,
class Time>
148 }
else if (autoref()) {
151 }
else if (transmitAbstract) {
152 abstractTransmitter->recompute(t);
154 return *transmitAbstractData;
157 return getPtr()->access(t);
166 else if (transmitAbstract)
167 return *transmitAbstractData;
169 return getPtr()->accessCopy();
171 template <
class T,
class Time>
173 std::string LeaderLocalName;
174 std::string LeaderNodeName;
176 if (isAbstractPluged() && !autoref()) {
177 std::string itLocalName, itNodeName;
178 getAbstractPtr()->ExtractNodeAndLocalNames(itLocalName, itNodeName);
179 os <<
"\t\"" << itNodeName <<
"\" -> \"" << LeaderNodeName <<
"\"" 181 <<
"\t [ headlabel = \"" << LeaderLocalName <<
"\" , taillabel = \"" 182 << itLocalName <<
"\", fontsize=7, fontcolor=red ]" << std::endl;
187 template <
class T,
class Time>
190 <<
"||" << signalPtr;
193 if ((isAbstractPluged()) && (!autoref())) {
194 os <<
" -->-- PLUGGED";
196 if (!isAbstractPluged())
199 os <<
" AUTOPLUGGED";
206 template <
class T,
class Time>
209 std::string space, std::string next1,
210 std::string next2)
const {
212 if ((isAbstractPluged()) && (!autoref())) {
213 getAbstractPtr()->displayDependencies(
virtual void checkCompatibility()
This is the only type of signal that can be plugged to, using the plug () command.
Signals link I/O ports of entities. They can be constant-valued signals, or copy the value of a heap ...
The base class for signals: not to be used as such.
virtual void checkCompatibility()