Callback

class CallbackBase

The CallbackBase class.

This class represents a base class for callback functions. A callback function is a function that is passed as an argument to another function. This class provides functionality for setting, resetting, and checking if the callback function is set.

Subclassed by Module::Callback< CommandResponseState >, Module::Callback< bool >, Module::Callback< T >, Module::Callback< void >

Public Functions

inline void reset(py::object &callable)

Resets the callback function to a new value.

This function generates a signature for the callable object, and compares it with the expected signature. If the signatures don’t match, the callback function is unset, and an invalid_argument exception is thrown.

Parameters:

callable – The new callback function.

Throws:

std::invalid_argument – If the callable object is not a callable or if its signature does not match the expected signature.

inline bool is_set() const

Check if the callback function is set.

This function checks if the callback object is not None.

Returns:

true if the callback function is set, false otherwise.

template<typename T>
class Callback : public Module::CallbackBase

Public Functions

template<typename ...Types>
inline bool call(Types&&... values)

Calls the callback function with the given values.

Template Parameters:

Types – The types of the values to pass to the callback

Parameters:

values – The values to pass to the callback

Returns:

bool True if the callback was called successfully, false otherwise

inline T getResult()

Retrieves the result of a callback.

Template Parameters:

T – The type of the result

Throws:

std::invalid_argument – if no result is set

Returns:

T The result of the callback

template<>
class Callback<void> : public Module::CallbackBase

Public Functions

template<typename ...Types>
inline bool call(Types&&... values)

Calls the callback function with the given values.

Template Parameters:

Types – The types of the values.

Parameters:

values – The values to pass to the callback function.

Returns:

bool Returns true if the callback function is called successfully, false otherwise.