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  dgTDEBUGIN(25);
18  if (!isPlugged()) DG_THROW
20  "In SignalPtr: SIN ptr not set.", " (in signal <%s>)",
21  getName().c_str());
22  dgTDEBUGOUT(25);
23  return signalPtr;
24 }
25 
26 template <class T, class Time>
28  dgTDEBUGIN(25) << SignalBase<Time>::name << "(" << isPlugged() << ")" << this
29  << "->" << signalPtr << std::endl;
30  dgTDEBUGIN(25);
31  if (!isPlugged()) {
33  "In SignalPtr: SIN ptr not set.",
34  " (in signal <%s>)", getName().c_str());
35  }
36  dgTDEBUGOUT(25);
37  return signalPtr;
38 }
39 
40 template <class T, class Time>
42  dgTDEBUGIN(5);
43  if (!unknown_ref) {
44  signalPtr = NULL;
45  dgTDEBUGOUT(5);
46  return;
47  }
48 
49  dgTDEBUG(5) << "# In T = " << getName() << " ="
50  << typeid(Signal<T, Time>::Tcopy1).name() << "{ " << std::endl;
51 
52  Signal<T, Time> *ref = dynamic_cast<Signal<T, Time> *>(unknown_ref);
53  if (NULL != ref) {
54  dgTDEBUG(25) << "Cast ok." << std::endl;
55  signalPtr = ref;
56  }
57  dgTDEBUGOUT(5);
58 }
59 
60 template <class T, class Time>
61 bool SignalPtr<T, Time>::needUpdate(const Time &t) const {
62  if ((isPlugged()) && (!autoref())) {
63  return getPtr()->needUpdate(t);
64  } else
66 }
67 
68 template <class T, class Time>
69 const Time &SignalPtr<T, Time>::getTime() const {
70  if ((isPlugged()) && (!autoref())) {
71  return getPtr()->getTime();
72  }
73  return Signal<T, Time>::getTime();
74 }
75 
76 template <class T, class Time>
77 const T &SignalPtr<T, Time>::operator()(const Time &t) {
78  return access(t);
79 }
80 
81 template <class T, class Time>
82 const T &SignalPtr<T, Time>::access(const Time &t) {
83  dgTDEBUGIN(15);
84  if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit) {
85  dgTDEBUGOUT(15);
87  } else if (autoref()) {
88  dgTDEBUGOUT(15);
89  return Signal<T, Time>::access(t);
90  } else {
91  dgTDEBUGOUT(15);
92  return getPtr()->access(t);
93  }
94 }
95 
96 template <class T, class Time>
98  if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit)
100  else if (autoref())
102  else
103  return getPtr()->accessCopy();
104 }
105 template <class T, class Time>
106 std::ostream &SignalPtr<T, Time>::writeGraph(std::ostream &os) const {
107  std::string LeaderLocalName;
108  std::string LeaderNodeName;
109  Signal<T, Time>::ExtractNodeAndLocalNames(LeaderLocalName, LeaderNodeName);
110  if (isPlugged() && !autoref()) {
111  std::string itLocalName, itNodeName;
112  getPtr()->ExtractNodeAndLocalNames(itLocalName, itNodeName);
113  os << "\t\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\""
114  << std::endl
115  << "\t [ headlabel = \"" << LeaderLocalName << "\" , taillabel = \""
116  << itLocalName << "\", fontsize=7, fontcolor=red ]" << std::endl;
117  }
118  return os;
119 }
120 
121 template <class T, class Time>
122 std::ostream &SignalPtr<T, Time>::display(std::ostream &os) const {
123  dgTDEBUGIN(25) << SignalBase<Time>::name << this << "||" << isPlugged()
124  << "||" << signalPtr;
125  { Signal<T, Time>::display(os); }
126 
127  if ((isPlugged()) && (!autoref())) {
128  os << " -->-- PLUGGED";
129  } else {
130  if (!isPlugged())
131  os << " UNPLUGGED";
132  else if (autoref())
133  os << " AUTOPLUGGED";
134  }
135 
136  dgTDEBUGOUT(25);
137  return os;
138 }
139 
140 template <class T, class Time>
141 std::ostream &SignalPtr<T, Time>::displayDependencies(std::ostream &os,
142  const int depth,
143  std::string space,
144  std::string next1,
145  std::string next2) const {
146  dgTDEBUGIN(25);
147  if ((isPlugged()) && (!autoref())) {
148  getPtr()->displayDependencies(
149  os, depth, space, next1 + "-- " + SignalBase<Time>::name + " -->",
150  next2);
151  } else {
152  SignalBase<Time>::displayDependencies(os, depth, space, next1, next2);
153  }
154  dgTDEBUGOUT(25);
155  return os;
156 }
157 
158 } // end of namespace dynamicgraph.
159 
160 #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::SignalBase::displayDependencies
virtual std::ostream & displayDependencies(std::ostream &os, const int=-1, std::string space="", std::string next1="", std::string="") const
Definition: signal-base.h:69
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
dynamicgraph::Signal::accessCopy
virtual const T & accessCopy() const
Definition: signal.t.cpp:134
dynamicgraph::SignalPtr::plug
virtual void plug(SignalBase< Time > *ref)
Definition: signal-ptr.t.cpp:41
dynamicgraph::Signal::access
virtual const T & access(const Time &t)
Definition: signal.t.cpp:139
signal-ptr.h
dynamicgraph::ExceptionSignal::NOT_INITIALIZED
@ NOT_INITIALIZED
Definition: exception-signal.h:25
dgTDEBUGIN
#define dgTDEBUGIN(level)
Definition: debug.h:208
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::access
virtual const T & access(const Time &t)
Definition: signal-ptr.t.cpp:82
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
DG_THROW
#define DG_THROW
Definition: exception-abstract.h:24
dynamicgraph::ExceptionSignal
Exceptions raised when an error related to signals happen.
Definition: exception-signal.h:19
dynamicgraph::Signal::display
virtual std::ostream & display(std::ostream &os) const
Definition: signal.t.cpp:218
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
dgTDEBUG
#define dgTDEBUG(level)
Definition: debug.h:187
dynamicgraph::SignalPtr::operator()
virtual const T & operator()(const Time &t)
Definition: signal-ptr.t.cpp:77
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
dgTDEBUGOUT
#define dgTDEBUGOUT(level)
Definition: debug.h:210
debug.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