C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin::pybind11_utils Namespace Reference

Functions

std::shared_ptr< yasmin::blackboard::Blackboardconvert_blackboard_from_python (py::object blackboard_obj)
 Convert a Python blackboard object to a C++ Blackboard shared pointer.
 
template<typename Func>
auto wrap_blackboard_callback (py::function cb)
 Wrap a C++ callback to handle BlackboardPyWrapper conversion (void return).
 
template<typename ReturnType>
auto wrap_blackboard_callback_with_return (py::function cb)
 Wrap a C++ callback to handle BlackboardPyWrapper conversion with return value.
 
template<typename ClassType, typename StateType>
void add_call_operator (ClassType &cls)
 Helper to define the standard call method for State classes.
 

Function Documentation

◆ add_call_operator()

template<typename ClassType, typename StateType>
void yasmin::pybind11_utils::add_call_operator ( ClassType & cls)
inline

Helper to define the standard call method for State classes.

This template function adds a call method that:

  1. Accepts an optional Python blackboard object
  2. Converts it to a C++ Blackboard using convert_blackboard_from_python
  3. Releases the GIL to allow C++ threads to run
  4. Calls the C++ operator() with the converted blackboard
  5. Reacquires the GIL before returning to Python
Template Parameters
ClassTypeThe pybind11 class type
StateTypeThe state class type (State, StateMachine, Concurrence)
Parameters
clsThe pybind11 class definition

◆ convert_blackboard_from_python()

std::shared_ptr< yasmin::blackboard::Blackboard > yasmin::pybind11_utils::convert_blackboard_from_python ( py::object blackboard_obj)
inline

Convert a Python blackboard object to a C++ Blackboard shared pointer.

This function handles multiple input types:

  • None/not provided: creates a new Blackboard
  • BlackboardPyWrapper: extracts the underlying C++ Blackboard
  • Blackboard: uses directly
  • Other types: creates a new Blackboard
Parameters
blackboard_objPython object that may contain a blackboard
Returns
std::shared_ptr<yasmin::blackboard::Blackboard> The C++ blackboard

◆ wrap_blackboard_callback()

template<typename Func>
auto yasmin::pybind11_utils::wrap_blackboard_callback ( py::function cb)
inline

Wrap a C++ callback to handle BlackboardPyWrapper conversion (void return).

This is a generic wrapper for callbacks that take a blackboard as the first parameter and return void.

Template Parameters
FuncThe function type to wrap
Parameters
cbThe Python callback function
Returns
A wrapped C++ function that converts Blackboard to BlackboardPyWrapper

◆ wrap_blackboard_callback_with_return()

template<typename ReturnType>
auto yasmin::pybind11_utils::wrap_blackboard_callback_with_return ( py::function cb)
inline

Wrap a C++ callback to handle BlackboardPyWrapper conversion with return value.

This wrapper is for callbacks that return a value (e.g., std::string for CbState).

Template Parameters
ReturnTypeThe return type of the callback
Parameters
cbThe Python callback function
Returns
A wrapped C++ function that converts Blackboard to BlackboardPyWrapper and returns the callback result