Adonthell  0.4
py_callback Class Reference

Stores the C++ <-> Python callback binding. More...

#include <py_callback.h>

Public Member Functions

 py_callback ()
 Default ctor,. More...
 
 py_callback (PyObject *func, PyObject *args)
 Constructor that assigns a function and its arguments to the callback. More...
 
 ~py_callback ()
 Destructor. More...
 
Executing the callback
void callback_func0 ()
 Calls the python function without arguments. More...
 
bool callback_func0ret ()
 Calls the python function and returns bool. More...
 
void callback_func1 (int arg)
 Calls the python function with an integer. More...
 

Loading / Saving

static PyObject * instance = NULL
 When restoring a callback from file, instance has to point to the python instance (module or class) containing the callback. More...
 
void put_state (ogzstream &out) const
 Saves the callback and it's arguments to file. More...
 
bool get_state (igzstream &in)
 Restores the callback from a file. More...
 

Detailed Description

Stores the C++ <-> Python callback binding.

Definition at line 41 of file py_callback.h.

Constructor & Destructor Documentation

◆ py_callback() [1/2]

py_callback::py_callback ( )

Default ctor,.

Definition at line 37 of file py_callback.cc.

◆ py_callback() [2/2]

py_callback::py_callback ( PyObject *  func,
PyObject *  args 
)

Constructor that assigns a function and its arguments to the callback.

Parameters
funcfunction assigned to this callback.
argsArguments passed to the function.

Definition at line 44 of file py_callback.cc.

◆ ~py_callback()

py_callback::~py_callback ( )

Destructor.

Definition at line 53 of file py_callback.cc.

Member Function Documentation

◆ callback_func0()

void py_callback::callback_func0 ( )

Calls the python function without arguments.

Definition at line 60 of file py_callback.cc.

◆ callback_func0ret()

bool py_callback::callback_func0ret ( )

Calls the python function and returns bool.

Definition at line 68 of file py_callback.cc.

◆ callback_func1()

void py_callback::callback_func1 ( int  arg)

Calls the python function with an integer.

Parameters
argInteger value to pass to the callback

Definition at line 82 of file py_callback.cc.

◆ put_state()

void py_callback::put_state ( ogzstream out) const

Saves the callback and it's arguments to file.

Note
Currently, arguments have to be a tuple containing only integers and/or strings.
Parameters
outfile where to save the callback.

Definition at line 94 of file py_callback.cc.

◆ get_state()

bool py_callback::get_state ( igzstream in)

Restores the callback from a file.

For that to work, the static py_callback::instance member has to point to the python instance containing the callback.

Parameters
infile to load the callback from.
Returns
true if the callback could be restored, false otherwise
See also
instance

Definition at line 120 of file py_callback.cc.

Member Data Documentation

◆ instance

PyObject * py_callback::instance = NULL
static

When restoring a callback from file, instance has to point to the python instance (module or class) containing the callback.

See also
get_state

Definition at line 122 of file py_callback.h.


The documentation for this class was generated from the following files: