Skip to content

Commit

Permalink
bounds checking in instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
zflat committed Apr 16, 2022
1 parent fd4763c commit a36ca05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions include/behaviortree_cpp_v3/controls/parallel_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class ParallelNode : public ControlNode

unsigned int thresholdM();
unsigned int thresholdFM();
void setThresholdM(unsigned int threshold_M);
void setThresholdFM(unsigned int threshold_M);
void setThresholdM(int threshold_M);
void setThresholdFM(int threshold_M);

private:
unsigned int success_threshold_;
unsigned int failure_threshold_;
int success_threshold_;
int failure_threshold_;

std::set<int> skip_list_;

Expand Down
11 changes: 7 additions & 4 deletions src/controls/parallel_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <algorithm>
#include <cstddef>

#include "behaviortree_cpp_v3/controls/parallel_node.h"

namespace BT
Expand Down Expand Up @@ -145,23 +148,23 @@ void ParallelNode::halt()
unsigned int ParallelNode::thresholdM()
{
return success_threshold_ < 0
? children_nodes_.size() + success_threshold_ + 1
? std::max(children_nodes_.size() + success_threshold_ + 1, static_cast<std::size_t>(0))
: success_threshold_;
}

unsigned int ParallelNode::thresholdFM()
{
return failure_threshold_ < 0
? children_nodes_.size() + success_threshold_ + 1
? std::max(children_nodes_.size() + success_threshold_ + 1, static_cast<std::size_t>(0))
: failure_threshold_;
}

void ParallelNode::setThresholdM(unsigned int threshold_M)
void ParallelNode::setThresholdM(int threshold_M)
{
success_threshold_ = threshold_M;
}

void ParallelNode::setThresholdFM(unsigned int threshold_M)
void ParallelNode::setThresholdFM(int threshold_M)
{
failure_threshold_ = threshold_M;
}
Expand Down

0 comments on commit a36ca05

Please sign in to comment.