42 template <
size_t NUM_CASES>
63 ports.insert(BT::InputPort<std::string>(
"variable"));
64 for (
unsigned i = 0; i < NUM_CASES; i++)
67 sprintf(case_str,
"case_%d", i + 1);
68 ports.insert(BT::InputPort<std::string>(case_str));
78 template <
size_t NUM_CASES>
81 if (childrenCount() != NUM_CASES + 1)
83 throw LogicError(
"Wrong number of children in SwitchNode; "
84 "must be (num_cases + default)");
89 int match_index = int(NUM_CASES);
91 if (getInput(
"variable", variable))
94 for (
int index = 0; index < int(NUM_CASES); ++index)
97 sprintf(case_key,
"case_%d",
int(index + 1));
98 bool found =
static_cast<bool>(getInput(case_key, value));
100 if (found && variable == value)
109 if (running_child_ != -1 && running_child_ != match_index)
111 haltChild(running_child_);
114 auto& selected_child = children_nodes_[match_index];
115 NodeStatus ret = selected_child->executeTick();
118 running_child_ = match_index;