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>
21 Signal<T, Time> *SignalPtr<T, Time>::getPtr() {
23 if (!isPlugged()) DG_THROW
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;
113 template <
class T,
class Time>
114 void SignalPtr<T, Time>::checkCompatibility() {
115 if (isPlugged() && (!autoref())) {
116 getPtr()->checkCompatibility();
117 }
else if (isAbstractPluged() && (!autoref())) {
118 abstractTransmitter->checkCompatibility();
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);
128 return Signal<T, Time>::needUpdate(t);
131 template <
class T,
class Time>
132 const Time &SignalPtr<T, Time>::getTime()
const {
133 if ((isAbstractPluged()) && (!autoref())) {
134 return getAbstractPtr()->getTime();
136 return Signal<T, Time>::getTime();
139 template <
class T,
class Time>
140 const T &SignalPtr<T, Time>::operator()(
const Time &t) {
144 template <
class T,
class Time>
145 const T &SignalPtr<T, Time>::access(
const Time &t) {
147 if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit) {
149 return Signal<T, Time>::accessCopy();
150 }
else if (autoref()) {
152 return Signal<T, Time>::access(t);
153 }
else if (transmitAbstract) {
154 abstractTransmitter->recompute(t);
156 return *transmitAbstractData;
159 return getPtr()->access(t);
163 template <
class T,
class Time>
164 const T &SignalPtr<T, Time>::accessCopy()
const {
165 if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit)
166 return Signal<T, Time>::accessCopy();
168 return Signal<T, Time>::accessCopy();
169 else if (transmitAbstract)
170 return *transmitAbstractData;
172 return getPtr()->accessCopy();
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 <<
"\""
184 <<
"\t [ headlabel = \"" << LeaderLocalName <<
"\" , taillabel = \""
185 << itLocalName <<
"\", fontsize=7, fontcolor=red ]" << std::endl;
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); }
196 if ((isAbstractPluged()) && (!autoref())) {
197 os <<
" -->-- PLUGGED";
199 if (!isAbstractPluged())
202 os <<
" AUTOPLUGGED";
209 template <
class T,
class Time>
210 std::ostream &SignalPtr<T, Time>::displayDependencies(std::ostream &os,
214 std::string next2)
const {
216 if ((isAbstractPluged()) && (!autoref())) {
217 getAbstractPtr()->displayDependencies(
218 os, depth, space, next1 +
"-- " + SignalBase<Time>::name +
" -->",
221 SignalBase<Time>::displayDependencies(os, depth, space, next1, next2);