Convertion vs wrapping

Wrapping classes from C++ to Python

The wrapping of a C++ function or class consist in creating a new function or class in Python which exposes its data and functionnality. For example, by wrapping a C++ Green function class, one produces a new Python module, written in C/C++, with new Python objects.

This notion is to be distinguished from the more general notion of convertion.

Convertion

Each time a function in C++ is called from python:

  • Each argument has to be converted from Python to C++

  • The function is then called in C++

  • Its result is then converted back to Python (to None for a function returning void).

Indeed the types are different in Python and C++. A convertion is necessary. E.g. a Python integer is not simply a C++ int.

The convertion is determined by the C++ type.

The wrapped classes are automatically convertible, as well as a list of C++/Python types. The t able of possible convertions is (here by convertion Tp is the Python convertion of C++ T):