16#ifndef YASMIN_PYBIND11_UTILS_HPP
17#define YASMIN_PYBIND11_UTILS_HPP
20#include <pybind11/pybind11.h>
25namespace py = pybind11;
42inline std::shared_ptr<yasmin::Blackboard>
44 std::shared_ptr<yasmin::Blackboard> blackboard;
47 if (blackboard_obj.is_none()) {
48 blackboard = std::make_shared<yasmin::Blackboard>();
51 else if (py::isinstance<yasmin::BlackboardPyWrapper>(blackboard_obj)) {
54 blackboard = wrapper.get_cpp_blackboard();
57 else if (py::isinstance<yasmin::Blackboard>(blackboard_obj)) {
58 blackboard = blackboard_obj.cast<std::shared_ptr<yasmin::Blackboard>>();
62 blackboard = std::make_shared<yasmin::Blackboard>();
81 return [cb](std::shared_ptr<yasmin::Blackboard> blackboard,
auto... args) {
82 py::gil_scoped_acquire acquire;
100template <
typename ReturnType>
102 return [cb](std::shared_ptr<yasmin::Blackboard> blackboard) -> ReturnType {
103 py::gil_scoped_acquire acquire;
105 return cb(wrapper).cast<ReturnType>();
123template <
typename ClassType,
typename StateType>
127 [](StateType &self, py::object blackboard_obj = py::none()) {
130 py::gil_scoped_release release;
131 return self(blackboard);
133 "Execute the state and return the outcome",
134 py::arg(
"blackboard") = py::none());
A wrapper around the C++ Blackboard that stores Python objects and native types.
Definition blackboard_pywrapper.hpp:48
Definition pybind11_utils.hpp:28
std::shared_ptr< yasmin::Blackboard > convert_blackboard_from_python(py::object blackboard_obj)
Convert a Python blackboard object to a C++ Blackboard shared pointer.
Definition pybind11_utils.hpp:43
void add_call_operator(ClassType &cls)
Helper to define the standard call method for State classes.
Definition pybind11_utils.hpp:124
auto wrap_blackboard_callback_with_return(py::function cb)
Wrap a C++ callback to handle BlackboardPyWrapper conversion with return value.
Definition pybind11_utils.hpp:101
auto wrap_blackboard_callback(py::function cb)
Wrap a C++ callback to handle BlackboardPyWrapper conversion (void return).
Definition pybind11_utils.hpp:80
Definition blackboard.hpp:29