43 template <
size_t NUM_CASES>
65 ports.insert( BT::InputPort<std::string>(
"variable") );
66 for(
unsigned i=0; i < NUM_CASES; i++)
69 sprintf(case_str,
"case_%d", i+1);
70 ports.insert( BT::InputPort<std::string>(case_str) );
80 template<
size_t NUM_CASES>
inline 83 constexpr
const char * case_port_names[9] = {
84 "case_1",
"case_2",
"case_3",
"case_4",
"case_5",
"case_6",
"case_7",
"case_8",
"case_9"};
88 throw LogicError(
"Wrong number of children in SwitchNode; " 89 "must be (num_cases + default)");
94 int child_index = NUM_CASES;
99 for (
unsigned index = 0; index < NUM_CASES; ++index)
104 found = (bool)
getInput(case_port_names[index], value);
108 sprintf(case_str,
"case_%d", index+1);
109 found = (bool)
getInput(case_str, value);
112 if (found && variable == value)
127 NodeStatus ret = selected_child->executeTick();
141 #endif // SWITCH_NODE_H
size_t childrenCount() const
const std::string & name() const
Name of the instance, not the type.
std::vector< TreeNode * > children_nodes_
const NodeConfiguration & config() const
virtual void halt() override
SwitchNode(const std::string &name, const BT::NodeConfiguration &config)
The SwitchNode is equivalent to a switch statement, where a certain branch (child) is executed accord...
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
Result getInput(const std::string &key, T &destination) const
std::unordered_map< std::string, PortInfo > PortsList
static PortsList providedPorts()
virtual ~SwitchNode() override=default
void setRegistrationID(StringView ID)