MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / tick

Method tick

include/behaviortree_cpp/controls/switch_node.h:112–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111template <size_t NUM_CASES>
112inline NodeStatus SwitchNode<NUM_CASES>::tick()
113{
114 if(childrenCount() != NUM_CASES + 1)
115 {
116 throw LogicError("Wrong number of children in SwitchNode; "
117 "must be (num_cases + default)");
118 }
119
120 std::string variable;
121 std::string value;
122 int match_index = int(NUM_CASES); // default index;
123
124 // no variable? jump to default
125 if(getInput("variable", variable))
126 {
127 // check each case until you find a match
128 for(int index = 0; index < int(NUM_CASES); ++index)
129 {
130 const std::string& case_key = case_keys_[index];
131 if(getInput(case_key, value))
132 {
133 if(details::CheckStringEquality(variable, value, this->config().enums.get()))
134 {
135 match_index = index;
136 break;
137 }
138 }
139 }
140 }
141
142 // if another one was running earlier, halt it
143 if(running_child_ != -1 && running_child_ != match_index)
144 {
145 haltChild(running_child_);
146 }
147
148 auto& selected_child = children_nodes_[match_index];
149 NodeStatus ret = selected_child->executeTick();
150 if(ret == NodeStatus::SKIPPED)
151 {
152 // if the matching child is SKIPPED, should I jump to default or
153 // be SKIPPED myself? Going with the former, for the time being.
154 running_child_ = -1;
155 return NodeStatus::SKIPPED;
156 }
157 else if(ret == NodeStatus::RUNNING)
158 {
159 running_child_ = match_index;
160 }
161 else
162 {
163 resetChildren();
164 running_child_ = -1;
165 }
166 return ret;
167}
168
169} // namespace BT

Callers

nothing calls this directly

Calls 4

LogicErrorClass · 0.85
CheckStringEqualityFunction · 0.85
getMethod · 0.45
executeTickMethod · 0.45

Tested by

no test coverage detected