4 #ifndef __SOT_SWITCH_H__
5 #define __SOT_SWITCH_H__
7 #include <dynamic-graph/command-bind.h>
8 #include <dynamic-graph/command-getter.h>
9 #include <dynamic-graph/entity.h>
10 #include <dynamic-graph/pool.h>
11 #include <dynamic-graph/signal-ptr.h>
12 #include <dynamic-graph/signal-time-dependent.h>
13 #include <dynamic-graph/signal.h>
21 template <
typename Value,
typename Time =
int>
23 DYNAMIC_GRAPH_ENTITY_DECL();
27 Switch(
const std::string &name)
28 :
Base(name, CLASS_NAME),
29 selectionSIN(NULL,
"Switch(" + name +
")::input(int)::selection"),
30 boolSelectionSIN(NULL,
31 "Switch(" + name +
")::input(bool)::boolSelection") {
32 this->signalRegistration(selectionSIN << boolSelectionSIN);
33 this->SOUT.setFunction(boost::bind(&Switch::signal,
this, _1, _2));
34 this->SOUT.addDependency(selectionSIN);
35 this->SOUT.addDependency(boolSelectionSIN);
37 using command::makeCommandVoid1;
38 std::string docstring =
"\n"
39 " Set number of input signals\n";
42 makeCommandVoid1(*(
Base *)
this, &Base::setSignalNumber, docstring));
45 " Get number of input signals\n";
46 this->addCommand(
"getSignalNumber",
47 new command::Getter<Base, int>(
48 *
this, &Base::getSignalNumber, docstring));
54 virtual std::string getDocString()
const {
55 return "Dynamically select a given signal based on a input information.\n";
59 Value &signal(Value &ret,
const Time &time) {
61 if (selectionSIN.isPlugged()) {
62 sel = selectionSIN(time);
64 const bool &b = boolSelectionSIN(time);
67 if (sel < 0 || sel >=
int(this->signalsIN.size()))
68 throw std::runtime_error(
"Signal selection is out of range.");
70 ret = this->signalsIN[sel]->access(time);
74 SignalPtr<int, Time> selectionSIN;
75 SignalPtr<bool, Time> boolSelectionSIN;
79 #endif // __SOT_SWITCH_H__