Shiboken::Conversions Namespace

namespace Shiboken::Conversions

Namespace for converter-related functionality. More...

Header: #include <sbkarrayconverter.h>

Classes

Functions

void addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc)
SbkArrayConverter *arrayTypeConverter(int index, int dimension = 1)
bool checkDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn)
bool checkIterableTypes(PyTypeObject *type, PyObject *pyIn)
bool checkMultiDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn)
bool checkPairTypes(PyTypeObject *firstType, PyTypeObject *secondType, PyObject *pyIn)
bool checkSequenceTypes(PyTypeObject *type, PyObject *pyIn)
bool convertibleDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, bool valueCheckExact, PyObject *pyIn)
bool convertibleIterableTypes(PyTypeObject *type, PyObject *pyIn)
bool convertibleIterableTypes(const SbkConverter *converter, PyObject *pyIn)
bool convertibleMultiDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, bool valueCheckExact, PyObject *pyIn)
bool convertiblePairTypes(const SbkConverter *firstConverter, bool firstCheckExact, const SbkConverter *secondConverter, bool secondCheckExact, PyObject *pyIn)
bool convertibleSequenceTypes(PyTypeObject *type, PyObject *pyIn)
bool convertibleSequenceTypes(const SbkConverter *converter, PyObject *pyIn)
PyObject *copyToPython(PyTypeObject *type, const void *cppIn)
PyObject *copyToPython(const SbkConverter *converter, const void *cppIn)
void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn)
SbkConverter *createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc)
SbkConverter *createConverter(PyTypeObject *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc = nullptr)
SbkConverter *createConverter(PyTypeObject *type, CppToPythonWithTypeFunc toPythonFunc)
void deleteConverter(SbkConverter *converter)
SbkConverter *getConverter(const char *typeName)
PyTypeObject *getPythonTypeObject(const SbkConverter *converter)
PyTypeObject *getPythonTypeObject(const char *typeName)
bool isImplicitConversion(PyTypeObject *type, PythonToCppFunc toCpp)
PythonToCppFunc isPythonToCppConvertible(const SbkConverter *converter, PyObject *pyIn)
PythonToCppFunc isPythonToCppPointerConvertible(PyTypeObject *type, PyObject *pyIn)
PythonToCppFunc isPythonToCppReferenceConvertible(PyTypeObject *type, PyObject *pyIn)
PythonToCppFunc isPythonToCppValueConvertible(PyTypeObject *type, PyObject *pyIn)
void nonePythonToCppNullPtr(PyObject *, void *cppOut)
PyObject *pointerToPython(PyTypeObject *type, const void *cppIn)
PyObject *pointerToPython(const SbkConverter *converter, const void *cppIn)
SbkConverter *primitiveTypeConverter(int index)
void pythonToCppCopy(PyTypeObject *type, PyObject *pyIn, void *cppOut)
void pythonToCppCopy(const SbkConverter *converter, PyObject *pyIn, void *cppOut)
void pythonToCppPointer(PyTypeObject *type, PyObject *pyIn, void *cppOut)
void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cppOut)
bool pythonTypeIsObjectType(const SbkConverter *converter)
bool pythonTypeIsValueType(const SbkConverter *converter)
bool pythonTypeIsWrapperType(const SbkConverter *converter)
PyObject *referenceToPython(PyTypeObject *type, const void *cppIn)
PyObject *referenceToPython(const SbkConverter *converter, const void *cppIn)
void registerConverterAlias(SbkConverter *converter, const char *typeName)
void registerConverterName(SbkConverter *converter, const char *typeName)
void setCppPointerToPythonFunction(SbkConverter *converter, CppToPythonFunc pointerToPythonFunc)
void setPythonToCppPointerFunctions(SbkConverter *converter, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc)

Detailed Description

Classes

class Array2Handle

Similar to ArrayHandle for fixed size 2 dimensional arrays. columns is the size of the last dimension. It only has a setData() method since it will be used for numpy only. More...

class ArrayHandle

ArrayHandle is the type expected by shiboken6's array converter functions. It provides access to array data which it may own (in the case of conversions from PySequence) or a flat pointer to internal data (in the case of array modules like numpy). More...

class SpecificConverter

C++ Wrapper around a type converter, which is constructed from a name. More...

Function Documentation

void Conversions::addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc)

Adds a new conversion of a Python object to a C++ value to converter consisting of the conversion function pythonToCppFunc and the check function isConvertibleToCppFunc. This is used in copy and implicit conversions.

SbkArrayConverter *Conversions::arrayTypeConverter(int index, int dimension = 1)

Returns the converter for an array type identified by index of dimension.

bool Conversions::checkDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn)

Returns true if a Python dictionary pyIn can be converted to a C++ hash or map of keyType and valueType.

bool Conversions::checkIterableTypes(PyTypeObject *type, PyObject *pyIn)

Returns true if a Python object pyIn is iterable and comprised of objects of the given type.

bool Conversions::checkMultiDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn)

Returns true if a Python dictionary pyIn can be converted to a C++ multi hash/map of keyType and valueType. The Python dictionary is expected to contain lists of values.

bool Conversions::checkPairTypes(PyTypeObject *firstType, PyTypeObject *secondType, PyObject *pyIn)

Returns true if a Python sequence pyIn can be converted to a C++ pair of firstType and secondType.

bool Conversions::checkSequenceTypes(PyTypeObject *type, PyObject *pyIn)

Returns true if a Python sequence pyIn is comprised of objects of the given type.

bool Conversions::convertibleDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, bool valueCheckExact, PyObject *pyIn)

Returns true if a Python dictionary pyIn can be converted to a C++ hash or map using keyConverter and valueConverter. keyCheckExact and valueCheckExact indicate whether an exact type check is to be performed.

bool Conversions::convertibleIterableTypes(PyTypeObject *type, PyObject *pyIn)

Returns true if a Python object pyIn is iterable and comprised of objects of a type convertible to type.

bool Conversions::convertibleIterableTypes(const SbkConverter *converter, PyObject *pyIn)

Returns true if a Python object pyIn is iterable and comprised of objects of a type convertible to the one represented by the given converter.

bool Conversions::convertibleMultiDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, bool valueCheckExact, PyObject *pyIn)

Returns true if a Python dictionary pyIn can be converted to a C++ multi hash/map using keyConverter and valueConverter. keyCheckExact and valueCheckExact indicate whether an exact type check is to be performed. The Python dictionary is expected to contain lists of values.

bool Conversions::convertiblePairTypes(const SbkConverter *firstConverter, bool firstCheckExact, const SbkConverter *secondConverter, bool secondCheckExact, PyObject *pyIn)

Returns true if a Python sequence pyIn can be converted to a C++ pair using firstConverter and secondConverter. firstCheckExact and secondCheckExact indicate whether an exact type check is to be performed.

bool Conversions::convertibleSequenceTypes(PyTypeObject *type, PyObject *pyIn)

Returns true if a Python sequence pyIn is comprised of objects of a type convertible to type.

bool Conversions::convertibleSequenceTypes(const SbkConverter *converter, PyObject *pyIn)

Returns true if a Python sequence pyIn is comprised of objects of a type convertible to the one represented by the given converter.

PyObject *Conversions::copyToPython(PyTypeObject *type, const void *cppIn)

Retrieves the Python wrapper object of type for the given C++ value pointed to by cppIn. This function is used only for Value Types. Example usage:

 TYPE var;
 PyObject *pyVar = copyToPython(SBKTYPE, &var);

PyObject *Conversions::copyToPython(const SbkConverter *converter, const void *cppIn)

Retrieves the Python wrapper object for the given C++ value pointed to by cppIn using converter.

This is an overloaded function.

void *Conversions::cppPointer(PyTypeObject *desiredType, SbkObject *pyIn)

Returns the C++ pointer for the pyIn object cast to the type passed via desiredType. It differs from Shiboken::Object::cppPointer() because it casts the pointer to a proper memory offset depending on the desired type.

SbkConverter *Conversions::createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc)

Creates a converter for a non wrapper type (primitive or container type) represented by the Python type type using the function toPythonFunc to convert a C++ object to a Python type.

Returns the new type converter.

SbkConverter *Conversions::createConverter(PyTypeObject *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc = nullptr)

Creates a converter for a wrapper type.

ParameterMeaning
typeA Shiboken.ObjectType that will receive the new converter.
toCppPointerConvFuncFunction to retrieve the C++ pointer held by a Python wrapper.
toCppPointerCheckFuncCheck and return the retriever function of the C++ pointer held by a Python wrapper.
pointerToPythonFuncFunction to convert a C++ object to a Python type wrapper, keeping their identity.
copyToPythonFuncFunction to convert a C++ object to a Python type, copying the object.
ReturnThe new converter referred by the wrapper type.

SbkConverter *Conversions::createConverter(PyTypeObject *type, CppToPythonWithTypeFunc toPythonFunc)

Creates a converter for a non wrapper type represented by the Python type type using the function toPythonFunc which additionally receives the type object.

This is an overloaded function.

void Conversions::deleteConverter(SbkConverter *converter)

Deletes the converter.

SbkConverter *Conversions::getConverter(const char *typeName)

Returns the converter for a given typeName, or nullptr if it wasn't registered before.

PyTypeObject *Conversions::getPythonTypeObject(const SbkConverter *converter)

Returns the Python type object associated with the given converter.

PyTypeObject *Conversions::getPythonTypeObject(const char *typeName)

Returns the Python type object for the given typeName.

bool Conversions::isImplicitConversion(PyTypeObject *type, PythonToCppFunc toCpp)

Returns true if the toCpp function passed is an implicit conversion of Python type. It is used when C++ expects a reference argument, so it may be the same object received from Python, or another created through implicit conversion.

PythonToCppFunc Conversions::isPythonToCppConvertible(const SbkConverter *converter, PyObject *pyIn)

This is the same as the isPythonToCppValueConvertible() function, checking pyIn using converter.

PythonToCppFunc Conversions::isPythonToCppPointerConvertible(PyTypeObject *type, PyObject *pyIn)

Returns a Python to C++ conversion function if the Python object pyIn is convertible to a C++ pointer. It returns nullptr if the Python object is not convertible to type.

PythonToCppFunc Conversions::isPythonToCppReferenceConvertible(PyTypeObject *type, PyObject *pyIn)

Returns a Python to C++ conversion function if the Python object pyIn is convertible to a C++ reference. The resulting converter function will return the underlying C++ object held by the Python wrapper, or a new C++ value if it must be an implicit conversion. It returns nullptr if the Python object is not convertible to type.

PythonToCppFunc Conversions::isPythonToCppValueConvertible(PyTypeObject *type, PyObject *pyIn)

Returns a Python to C++ conversion function if the Python object pyIn is convertible to a C++ value. The resulting converter function will create a copy of the Python object in C++, or implicitly convert the object to the expected type. It returns nullptr if the Python object is not convertible to type.

void Conversions::nonePythonToCppNullPtr(PyObject *, void *cppOut)

Helper function returned by generated convertible checking functions that sets cppOut to a C++ nullptr when the input Python object is None.

PyObject *Conversions::pointerToPython(PyTypeObject *type, const void *cppIn)

Retrieves the Python wrapper object of type for the given cppIn C++ pointer object. This function is used only for Value and Object Types. Example usage:

 TYPE *var;
 PyObject *pyVar = pointerToPython(SBKTYPE, &var);

PyObject *Conversions::pointerToPython(const SbkConverter *converter, const void *cppIn)

Retrieves the Python wrapper object for the given cppIn C++ pointer object using converter.

This is an overloaded function.

SbkConverter *Conversions::primitiveTypeConverter(int index)

Returns the converter for a primitive type identified by index.

void Conversions::pythonToCppCopy(PyTypeObject *type, PyObject *pyIn, void *cppOut)

Converts a Python object pyIn of type to C++, and copies the result to the C++ variable passed in cppOut.

void Conversions::pythonToCppCopy(const SbkConverter *converter, PyObject *pyIn, void *cppOut)

Converts a Python object pyIn to C++ using converter, and copies the result to the C++ variable passed in cppOut.

This is an overloaded function.

void Conversions::pythonToCppPointer(PyTypeObject *type, PyObject *pyIn, void *cppOut)

Converts a Python object pyIn of type to C++ and stores the result in the C++ pointer passed in cppOut.

void Conversions::pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cppOut)

Converts a Python object pyIn to C++ using converter and stores the result in the C++ pointer passed in cppOut.

This is an overloaded function.

bool Conversions::pythonTypeIsObjectType(const SbkConverter *converter)

Returns true if the Python type associated with the converter is an object type.

bool Conversions::pythonTypeIsValueType(const SbkConverter *converter)

Returns true if the Python type associated with the converter is a value type.

bool Conversions::pythonTypeIsWrapperType(const SbkConverter *converter)

Returns true if the Python type associated with the converter is a wrapper type.

PyObject *Conversions::referenceToPython(PyTypeObject *type, const void *cppIn)

For the given cppIn C++ reference it returns the Python wrapper object of type, always for Object Types, and when they already exist for reference types; for when the latter doesn't have an existing wrapper type, the C++ object is copied to Python. Example usage:

 TYPE &var = SOMETHING;
 PyObject *pyVar = referenceToPython(SBKTYPE, &var);

PyObject *Conversions::referenceToPython(const SbkConverter *converter, const void *cppIn)

Returns the Python wrapper object for the given cppIn C++ reference using converter.

This is an overloaded function.

void Conversions::registerConverterAlias(SbkConverter *converter, const char *typeName)

Registers a converter with a type name typeName that may be used to retrieve the converter unless there is already a converter for the name. Use for partially qualified names.

void Conversions::registerConverterName(SbkConverter *converter, const char *typeName)

Registers a converter with a type name typeName that may be used to retrieve the converter. Use for fully qualified names (main type). This will overwrite existing converters of the same name.

void Conversions::setCppPointerToPythonFunction(SbkConverter *converter, CppToPythonFunc pointerToPythonFunc)

Sets the C++ pointer to Python object conversion function of converter to pointerToPythonFunc.

void Conversions::setPythonToCppPointerFunctions(SbkConverter *converter, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc)

Sets the Python object to C++ pointer conversion functions of converter to toCppPointerConvFunc and the check function toCppPointerCheckFunc.