Skip to content

Commit

Permalink
Pass the entire binding name instead of just a suffix for the Behavio…
Browse files Browse the repository at this point in the history
…r class bindings
  • Loading branch information
ll-nick committed Jan 7, 2025
1 parent 584563d commit 66bd8a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/arbitration_graphs/internal/behavior_py.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class PyBehavior : public Behavior<CommandT> {
};

template <typename CommandT>
void bindBehavior(py::module& module, const std::string& suffix = "") {
void bindBehavior(py::module& module, const std::string& bindingName = "Behavior") {
using BehaviorT = Behavior<CommandT>;
using PyBehaviorT = PyBehavior<CommandT>;

py::class_<BehaviorT, PyBehaviorT, std::shared_ptr<BehaviorT>>(module, ("Behavior" + suffix).c_str())
py::class_<BehaviorT, PyBehaviorT, std::shared_ptr<BehaviorT>>(module, bindingName.c_str())
.def(py::init<const std::string&>(), py::arg("name") = "Behavior")
.def("get_command", &BehaviorT::getCommand, py::arg("time"))
.def("check_invocation_condition", &BehaviorT::checkInvocationCondition, py::arg("time"))
Expand Down
10 changes: 5 additions & 5 deletions include/arbitration_graphs/python_bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ template <typename CommandT,
typename VerifierT = verification::PlaceboVerifier<SubCommandT>,
typename VerificationResultT = typename decltype(std::function{VerifierT::analyze})::result_type>
void bindArbitrationGraphs(py::module& module,
const std::string& behaviorCommandSuffix = "",
const std::string& behaviorSubCommandSuffix = "") {
const std::string& behaviorBindingName = "Behavior",
const std::string& behaviorSubCommandBindingName = "BehaviorSubCommand") {
bindExceptions(module);
bindPlaceboVerifier<SubCommandT>(module);

bindBehavior<CommandT>(module, behaviorCommandSuffix);
// Only bind behavior for SubCommandT if it is different from CommandT
bindBehavior<CommandT>(module, behaviorBindingName);
// Bind the behavior for the SubCommandT only if it is different from the CommandT
if constexpr (!std::is_same_v<CommandT, SubCommandT>) {
bindBehavior<SubCommandT>(module, behaviorSubCommandSuffix);
bindBehavior<SubCommandT>(module, behaviorSubCommandBindingName);
}

bindArbitrator<CommandT, SubCommandT, VerifierT, VerificationResultT>(module);
Expand Down
2 changes: 1 addition & 1 deletion test/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PYBIND11_MODULE(arbitration_graphs_py, mainModule) {
}

PYBIND11_MODULE(arbitration_graphs_py_with_subcommand, mainModule) {
python_api::bindArbitrationGraphs<DummyCommandInt, DummyCommand>(mainModule, "Int");
python_api::bindArbitrationGraphs<DummyCommandInt, DummyCommand>(mainModule, "BehaviorInt", "Behavior");

py::module testingModule = mainModule.def_submodule("testing_types");
bindTestingTypes(testingModule);
Expand Down

0 comments on commit 66bd8a1

Please sign in to comment.