7 #ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H
8 #define DYNAMIC_GRAPH_SIGNAL_BASE_H
9 #include <dynamic-graph/exception-signal.h>
11 #include <boost/noncopyable.hpp>
12 #include <dynamic-graph/fwd.hh>
27 class SignalBase :
public boost::noncopyable {
29 explicit SignalBase(std::string name =
"")
30 : name(name), signalTime(0), ready(false) {}
32 virtual ~SignalBase() {}
36 virtual const Time &getTime()
const {
return signalTime; }
38 virtual void setTime(
const Time &t) { signalTime = t; }
40 const bool &getReady()
const {
return ready; }
42 const std::string &getName()
const {
return name; }
44 void getClassName(std::string &aClassName)
const {
45 aClassName =
typeid(
this).name();
48 virtual void setPeriodTime(
const Time &) {}
50 virtual Time getPeriodTime()
const {
return 1; }
57 virtual void addDependency(
const SignalBase<Time> &) {}
59 virtual void removeDependency(
const SignalBase<Time> &) {}
61 virtual void clearDependencies() {}
63 virtual bool needUpdate(
const Time &)
const {
return ready; }
65 inline void setReady(
const bool sready =
true) { ready = sready; }
67 virtual std::ostream &writeGraph(std::ostream &os)
const {
return os; }
69 virtual std::ostream &displayDependencies(std::ostream &os,
const int = -1,
70 std::string space =
"",
71 std::string next1 =
"",
72 std::string =
"")
const {
73 os << space << next1 <<
"-- ";
87 virtual void plug(SignalBase<Time> *sigarg) {
88 DG_THROW ExceptionSignal(
89 ExceptionSignal::PLUG_IMPOSSIBLE,
90 "Plug-in operation not possible with this signal. ",
91 "(while trying to plug %s on %s).", sigarg->getName().c_str(),
92 this->getName().c_str());
95 virtual void unplug() {
96 DG_THROW ExceptionSignal(
97 ExceptionSignal::PLUG_IMPOSSIBLE,
98 "Plug-in operation not possible with this signal. ",
99 "(while trying to unplug %s).", this->getName().c_str());
102 virtual bool isPlugged()
const {
return false; }
104 virtual SignalBase<Time> *getPluged()
const {
return NULL; }
106 virtual void setConstantDefault() {
107 DG_THROW ExceptionSignal(
108 ExceptionSignal::PLUG_IMPOSSIBLE,
109 "Plug-in operation not possible with this signal. ",
110 "(while trying to save %s).", this->getName().c_str());
121 virtual void set(std::istringstream &) {
122 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
123 "Set operation not possible with this signal. ",
124 "(while trying to set %s).",
125 this->getName().c_str());
128 virtual void get(std::ostream &)
const {
129 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
130 "Get operation not possible with this signal. ",
131 "(while trying to get %s).",
132 this->getName().c_str());
135 virtual inline void recompute(
const Time &) {
136 DG_THROW ExceptionSignal(
137 ExceptionSignal::SET_IMPOSSIBLE,
138 "Recompute operation not possible with this signal. ",
139 "(while trying to recompute %s).", this->getName().c_str());
142 virtual void trace(std::ostream &)
const {
143 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
144 "Trace operation not possible with this signal. ",
145 "(while trying to trace %s).",
146 this->getName().c_str());
154 virtual std::ostream &display(std::ostream &os)
const {
155 os <<
"Sig:" << name;
159 std::string shortName()
const {
160 std::istringstream iss(name);
161 const int SIZE = 128;
164 iss.getline(buffer, SIZE,
':');
166 const std::string res(buffer);
174 virtual void ExtractNodeAndLocalNames(std::string &LocalName,
175 std::string &NodeName)
const {
176 std::string fullname = this->getName();
178 size_t IdxPosLocalName = fullname.rfind(
":");
179 LocalName = fullname.substr(IdxPosLocalName + 1,
180 fullname.length() - IdxPosLocalName + 1);
181 size_t IdxPosNodeNameStart = fullname.find(
"(");
182 size_t IdxPosNodeNameEnd = fullname.find(
")");
183 NodeName = fullname.substr(IdxPosNodeNameStart + 1,
184 IdxPosNodeNameEnd - IdxPosNodeNameStart - 1);
191 virtual void checkCompatibility() {
192 DG_THROW ExceptionSignal(ExceptionSignal::PLUG_IMPOSSIBLE,
193 "Abstract signal not compatible with anything.",
194 "(while trying to plug <%s>).",
195 this->getName().c_str());
206 template <
class Time>
208 return sig.display(os);