signal-base.h
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 // LAAS, CNRS
5 //
6 
7 #ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H
8 #define DYNAMIC_GRAPH_SIGNAL_BASE_H
10 
11 #include <boost/noncopyable.hpp>
12 #include <dynamic-graph/fwd.hh>
13 #include <sstream>
14 #include <string>
15 #include <typeinfo>
16 
17 namespace dynamicgraph {
18 
26 template <class Time>
27 class SignalBase : public boost::noncopyable {
28  public:
29  explicit SignalBase(std::string name = "")
30  : name(name), signalTime(0), ready(false) {}
31 
32  virtual ~SignalBase() {}
33 
36  virtual const Time &getTime() const { return signalTime; }
37 
38  virtual void setTime(const Time &t) { signalTime = t; }
39 
40  const bool &getReady() const { return ready; }
41 
42  const std::string &getName() const { return name; }
43 
44  void getClassName(std::string &aClassName) const {
45  aClassName = typeid(this).name();
46  }
47 
48  virtual void setPeriodTime(const Time &) {}
49 
50  virtual Time getPeriodTime() const { return 1; }
51 
53 
56 
57  virtual void addDependency(const SignalBase<Time> &) {}
58 
59  virtual void removeDependency(const SignalBase<Time> &) {}
60 
61  virtual void clearDependencies() {}
62 
63  virtual bool needUpdate(const Time &) const { return ready; }
64 
65  inline void setReady(const bool sready = true) { ready = sready; }
66 
67  virtual std::ostream &writeGraph(std::ostream &os) const { return os; }
68 
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 << "-- ";
74  display(os);
75  return os;
76  }
77 
79 
82 
83  /* Plug the arg-signal on the <this> object. Plug-in is always
84  * a descending operation (the actual <this> object will call the arg-signal
85  * and not the opposite).
86  */
87  virtual void plug(SignalBase<Time> *sigarg) {
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());
93  }
94 
95  virtual void unplug() {
98  "Plug-in operation not possible with this signal. ",
99  "(while trying to unplug %s).", this->getName().c_str());
100  }
101 
102  virtual bool isPlugged() const { return false; }
103 
104  virtual SignalBase<Time> *getPluged() const { return NULL; }
105 
106  virtual void setConstantDefault() {
109  "Plug-in operation not possible with this signal. ",
110  "(while trying to save %s).", this->getName().c_str());
111  }
112 
114 
117 
118  /* Generic set function. Should be reimplemented by the specific
119  * Signal. Sets a signal value
120  */
121  virtual void set(std::istringstream &) {
123  "Set operation not possible with this signal. ",
124  "(while trying to set %s).",
125  this->getName().c_str());
126  }
127 
128  virtual void get(std::ostream &) const {
130  "Get operation not possible with this signal. ",
131  "(while trying to get %s).",
132  this->getName().c_str());
133  }
134 
135  virtual inline void recompute(const Time &) {
138  "Recompute operation not possible with this signal. ",
139  "(while trying to recompute %s).", this->getName().c_str());
140  }
141 
142  virtual void trace(std::ostream &) const {
144  "Trace operation not possible with this signal. ",
145  "(while trying to trace %s).",
146  this->getName().c_str());
147  }
148 
150 
153 
154  virtual std::ostream &display(std::ostream &os) const {
155  os << "Sig:" << name;
156  return os;
157  }
158 
159  std::string shortName() const {
160  std::istringstream iss(name);
161  const int SIZE = 128;
162  char buffer[SIZE];
163  while (iss.good()) {
164  iss.getline(buffer, SIZE, ':');
165  }
166  const std::string res(buffer);
167  return res;
168  }
170 
173 
174  virtual void ExtractNodeAndLocalNames(std::string &LocalName,
175  std::string &NodeName) const {
176  std::string fullname = this->getName();
177 
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);
185  }
186 
188 
189  protected:
190  std::string name;
192  bool ready;
193 };
194 
196 template <class Time>
197 std::ostream &operator<<(std::ostream &os, const SignalBase<Time> &sig) {
198  return sig.display(os);
199 }
200 } // end of namespace dynamicgraph.
201 
202 #endif
dynamicgraph::SignalBase::getTime
virtual const Time & getTime() const
Definition: signal-base.h:36
dynamicgraph::ExceptionSignal::SET_IMPOSSIBLE
@ SET_IMPOSSIBLE
Definition: exception-signal.h:27
dynamicgraph::SignalBase::setTime
virtual void setTime(const Time &t)
Definition: signal-base.h:38
dynamicgraph::operator<<
DYNAMIC_GRAPH_DLLAPI std::ostream & operator<<(std::ostream &os, const dynamicgraph::Entity &ent)
Definition: src/dgraph/entity.cpp:174
dynamicgraph::SignalBase::ExtractNodeAndLocalNames
virtual void ExtractNodeAndLocalNames(std::string &LocalName, std::string &NodeName) const
Definition: signal-base.h:174
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::SignalBase::recompute
virtual void recompute(const Time &)
Definition: signal-base.h:135
dynamicgraph::SignalBase::getClassName
void getClassName(std::string &aClassName) const
Definition: signal-base.h:44
dynamicgraph::ExceptionSignal::PLUG_IMPOSSIBLE
@ PLUG_IMPOSSIBLE
Definition: exception-signal.h:26
dynamicgraph::SignalBase::setPeriodTime
virtual void setPeriodTime(const Time &)
Definition: signal-base.h:48
dynamicgraph
dynamicgraph::SignalBase::setConstantDefault
virtual void setConstantDefault()
Definition: signal-base.h:106
dynamicgraph::SignalBase::SignalBase
SignalBase(std::string name="")
Definition: signal-base.h:29
fwd.hh
dynamicgraph::SignalBase::~SignalBase
virtual ~SignalBase()
Definition: signal-base.h:32
dynamicgraph::SignalBase::display
virtual std::ostream & display(std::ostream &os) const
Definition: signal-base.h:154
exception-signal.h
dynamicgraph::SignalBase::get
virtual void get(std::ostream &) const
Definition: signal-base.h:128
dynamicgraph::SignalBase::set
virtual void set(std::istringstream &)
Definition: signal-base.h:121
dynamicgraph::SignalBase::isPlugged
virtual bool isPlugged() const
Definition: signal-base.h:102
dynamicgraph::SignalBase::getPluged
virtual SignalBase< Time > * getPluged() const
Definition: signal-base.h:104
sig
dynamicgraph::SignalArray_const< double > sig
Definition: signal-all.cpp:25
dynamicgraph::SignalBase::plug
virtual void plug(SignalBase< Time > *sigarg)
Definition: signal-base.h:87
dynamicgraph::SignalBase::getName
const std::string & getName() const
Definition: signal-base.h:42
dynamicgraph::SignalBase::shortName
std::string shortName() const
Definition: signal-base.h:159
DG_THROW
#define DG_THROW
Definition: exception-abstract.h:24
dynamicgraph::SignalBase::unplug
virtual void unplug()
Definition: signal-base.h:95
dynamicgraph::SignalBase::addDependency
virtual void addDependency(const SignalBase< Time > &)
Definition: signal-base.h:57
dynamicgraph::ExceptionSignal
Exceptions raised when an error related to signals happen.
Definition: exception-signal.h:19
dynamicgraph::SignalBase::name
std::string name
Definition: signal-base.h:190
dynamicgraph::SignalBase::removeDependency
virtual void removeDependency(const SignalBase< Time > &)
Definition: signal-base.h:59
dynamicgraph::SignalBase::needUpdate
virtual bool needUpdate(const Time &) const
Definition: signal-base.h:63
dynamicgraph::SignalBase::writeGraph
virtual std::ostream & writeGraph(std::ostream &os) const
Definition: signal-base.h:67
dynamicgraph::SignalBase::trace
virtual void trace(std::ostream &) const
Definition: signal-base.h:142
dynamicgraph::SignalBase::ready
bool ready
Definition: signal-base.h:192
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
dynamicgraph::SignalBase::signalTime
Time signalTime
Definition: signal-base.h:191
dynamicgraph::SignalBase::clearDependencies
virtual void clearDependencies()
Definition: signal-base.h:61
dynamicgraph::SignalBase::getReady
const bool & getReady() const
Definition: signal-base.h:40
dynamicgraph::SignalBase::getPeriodTime
virtual Time getPeriodTime() const
Definition: signal-base.h:50
dynamicgraph::SignalBase::setReady
void setReady(const bool sready=true)
Definition: signal-base.h:65


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38