switch.hh
Go to the documentation of this file.
1 // Copyright (c) 2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 
4 #ifndef __SOT_SWITCH_H__
5 #define __SOT_SWITCH_H__
6 
9 #include <dynamic-graph/entity.h>
10 #include <dynamic-graph/pool.h>
13 #include <dynamic-graph/signal.h>
14 
15 #include <sot/core/config.hh>
16 #include <sot/core/variadic-op.hh>
17 
18 namespace dynamicgraph {
19 namespace sot {
21 template <typename Value, typename Time = sigtime_t>
22 class SOT_CORE_DLLAPI Switch : public VariadicAbstract<Value, Value, Time> {
24 
25  public:
27 
28  Switch(const std::string &name)
29  : Base(name, CLASS_NAME),
30  selectionSIN(NULL, "Switch(" + name + ")::input(size_type)::selection"),
31  boolSelectionSIN(NULL,
32  "Switch(" + name + ")::input(bool)::boolSelection") {
33  this->signalRegistration(selectionSIN << boolSelectionSIN);
34  this->SOUT.setFunction(boost::bind(&Switch::signal, this, _1, _2));
35  this->SOUT.addDependency(selectionSIN);
36  this->SOUT.addDependency(boolSelectionSIN);
37 
39  std::string docstring =
40  "\n"
41  " Set number of input signals\n";
42  this->addCommand(
43  "setSignalNumber",
44  makeCommandVoid1(*(Base *)this, &Base::setSignalNumber, docstring));
45 
46  docstring =
47  "\n"
48  " Get number of input signals\n";
49  this->addCommand("getSignalNumber",
51  *this, &Base::getSignalNumber, docstring));
52  }
53 
54  ~Switch() {}
55 
57  virtual std::string getDocString() const {
58  return "Dynamically select a given signal based on a input information.\n";
59  }
60 
63 
64  private:
65  Value &signal(Value &ret, const Time &time) {
66  size_type sel;
67  if (selectionSIN.isPlugged()) {
68  sel = selectionSIN(time);
69  } else {
70  const bool &b = boolSelectionSIN(time);
71  sel = b ? 1 : 0;
72  }
73  if (sel < 0 || sel >= size_type(this->signalsIN.size()))
74  throw std::runtime_error("Signal selection is out of range.");
75 
76  ret = this->signalsIN[sel]->access(time);
77  return ret;
78  }
79 };
80 } // namespace sot
81 } // namespace dynamicgraph
82 #endif // __SOT_SWITCH_H__
signal-ptr.h
signal-time-dependent.h
dynamicgraph::sot::Switch::~Switch
~Switch()
Definition: switch.hh:54
dynamicgraph::sot::Switch::Switch
Switch(const std::string &name)
Definition: switch.hh:28
dynamicgraph::SignalPtr
dynamicgraph
dynamicgraph::sot::Switch::signal
Value & signal(Value &ret, const Time &time)
Definition: switch.hh:65
dynamicgraph::sot::Switch
Switch.
Definition: switch.hh:22
command-getter.h
dynamicgraph::sot::Switch::Base
VariadicAbstract< Value, Value, Time > Base
Definition: switch.hh:26
b
Vec3f b
dynamicgraph::sot::Switch::getDocString
virtual std::string getDocString() const
Header documentation of the python class.
Definition: switch.hh:57
command-bind.h
DYNAMIC_GRAPH_ENTITY_DECL
#define DYNAMIC_GRAPH_ENTITY_DECL()
dynamicgraph::sot::VariadicAbstract
Definition: variadic-op.hh:39
variadic-op.hh
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::sot::Switch::selectionSIN
SignalPtr< size_type, Time > selectionSIN
Definition: switch.hh:61
dynamicgraph::SignalPtr::isPlugged
virtual bool isPlugged() const
dynamicgraph::command::Getter
dynamicgraph::command::Value
dynamicgraph::sot::Switch::boolSelectionSIN
SignalPtr< bool, Time > boolSelectionSIN
Definition: switch.hh:62
dynamicgraph::command::makeCommandVoid1
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
compile.name
name
Definition: compile.py:23


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31