7 #ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H 8 #define DYNAMIC_GRAPH_SIGNAL_BASE_H 9 #include <boost/noncopyable.hpp> 14 #include <dynamic-graph/exception-signal.h> 15 #include <dynamic-graph/fwd.hh> 26 template <
class Time>
class SignalBase :
public boost::noncopyable {
28 explicit SignalBase(std::string name =
"")
29 : name(name), signalTime(0), ready(false) {}
31 virtual ~SignalBase() {}
35 virtual const Time &getTime()
const {
return signalTime; }
37 virtual void setTime(
const Time &t) { signalTime = t; }
39 const bool &getReady()
const {
return ready; }
41 const std::string &getName()
const {
return name; }
43 void getClassName(std::string &aClassName)
const {
44 aClassName =
typeid(
this).name();
47 virtual void setPeriodTime(
const Time &) {}
49 virtual Time getPeriodTime()
const {
return 1; }
56 virtual void addDependency(
const SignalBase<Time> &) {}
58 virtual void removeDependency(
const SignalBase<Time> &) {}
60 virtual void clearDependencies() {}
62 virtual bool needUpdate(
const Time &)
const {
return ready; }
64 inline void setReady(
const bool sready =
true) { ready = sready; }
66 virtual std::ostream &writeGraph(std::ostream &os)
const {
return os; }
68 virtual std::ostream &displayDependencies(std::ostream &os,
const int = -1,
69 std::string space =
"",
70 std::string next1 =
"",
71 std::string =
"")
const {
72 os << space << next1 <<
"-- ";
86 virtual void plug(SignalBase<Time> *sigarg) {
87 DG_THROW ExceptionSignal(
88 ExceptionSignal::PLUG_IMPOSSIBLE,
89 "Plug-in operation not possible with this signal. ",
90 "(while trying to plug %s on %s).", sigarg->getName().c_str(),
91 this->getName().c_str());
94 virtual void unplug() {
95 DG_THROW ExceptionSignal(
96 ExceptionSignal::PLUG_IMPOSSIBLE,
97 "Plug-in operation not possible with this signal. ",
98 "(while trying to unplug %s).", this->getName().c_str());
101 virtual bool isPlugged()
const {
return false; }
103 virtual SignalBase<Time> *getPluged()
const {
return NULL; }
105 virtual void setConstantDefault() {
106 DG_THROW ExceptionSignal(
107 ExceptionSignal::PLUG_IMPOSSIBLE,
108 "Plug-in operation not possible with this signal. ",
109 "(while trying to save %s).", this->getName().c_str());
120 virtual void set(std::istringstream &) {
121 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
122 "Set operation not possible with this signal. ",
123 "(while trying to set %s).",
124 this->getName().c_str());
127 virtual void get(std::ostream &)
const {
128 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
129 "Get operation not possible with this signal. ",
130 "(while trying to get %s).",
131 this->getName().c_str());
134 virtual inline void recompute(
const Time &) {
135 DG_THROW ExceptionSignal(
136 ExceptionSignal::SET_IMPOSSIBLE,
137 "Recompute operation not possible with this signal. ",
138 "(while trying to recompute %s).", this->getName().c_str());
141 virtual void trace(std::ostream &)
const {
142 DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
143 "Trace operation not possible with this signal. ",
144 "(while trying to trace %s).",
145 this->getName().c_str());
153 virtual std::ostream &display(std::ostream &os)
const {
154 os <<
"Sig:" << name;
158 std::string shortName()
const {
159 std::istringstream iss(name);
160 const int SIZE = 128;
163 iss.getline(buffer, SIZE,
':');
165 const std::string res(buffer);
173 virtual void ExtractNodeAndLocalNames(std::string &LocalName,
174 std::string &NodeName)
const {
175 std::string fullname = this->getName();
177 size_t IdxPosLocalName = fullname.rfind(
":");
178 LocalName = fullname.substr(IdxPosLocalName + 1,
179 fullname.length() - IdxPosLocalName + 1);
180 size_t IdxPosNodeNameStart = fullname.find(
"(");
181 size_t IdxPosNodeNameEnd = fullname.find(
")");
182 NodeName = fullname.substr(IdxPosNodeNameStart + 1,
183 IdxPosNodeNameEnd - IdxPosNodeNameStart - 1);
190 virtual void checkCompatibility() {
191 DG_THROW ExceptionSignal(ExceptionSignal::PLUG_IMPOSSIBLE,
192 "Abstract signal not compatible with anything.",
193 "(while trying to plug <%s>).",
194 this->getName().c_str());
205 template <
class Time>
206 std::ostream &operator<<(std::ostream &os, const SignalBase<Time> &sig) {
207 return sig.display(os);