summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-11-01 16:17:01 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 20:28:07 -0300
commitda38f960cef3e105e959cfd80a193e029d82d9aa (patch)
treeb995687b88514f297a28ad983446f08260b29833 /libshiboken
parentd427000699fe74f7f0b1d1fdf1907a0d40f83ba8 (diff)
downloadshiboken-da38f960cef3e105e959cfd80a193e029d82d9aa.tar.gz
shiboken-da38f960cef3e105e959cfd80a193e029d82d9aa.tar.xz
shiboken-da38f960cef3e105e959cfd80a193e029d82d9aa.zip
Added some setting and converting functions to the new converter's API.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/sbkconverter.cpp30
-rw-r--r--libshiboken/sbkconverter.h16
2 files changed, 40 insertions, 6 deletions
diff --git a/libshiboken/sbkconverter.cpp b/libshiboken/sbkconverter.cpp
index 32d43507..202ba264 100644
--- a/libshiboken/sbkconverter.cpp
+++ b/libshiboken/sbkconverter.cpp
@@ -125,6 +125,18 @@ void deleteConverter(SbkConverter* converter)
}
}
+void setCppPointerToPythonFunction(SbkConverter* converter, CppToPythonFunc pointerToPythonFunc)
+{
+ converter->pointerToPython = pointerToPythonFunc;
+}
+
+void setPythonToCppPointerFunctions(SbkConverter* converter,
+ PythonToCppFunc toCppPointerConvFunc,
+ IsConvertibleToCppFunc toCppPointerCheckFunc)
+{
+ converter->toCppPointerConversion = std::make_pair(toCppPointerCheckFunc, toCppPointerConvFunc);
+}
+
void addPythonToCppValueConversion(SbkConverter* converter,
PythonToCppFunc pythonToCppFunc,
IsConvertibleToCppFunc isConvertibleToCppFunc)
@@ -140,9 +152,15 @@ void addPythonToCppValueConversion(SbkObjectType* type,
PyObject* pointerToPython(SbkObjectType* type, const void* cppIn)
{
+ return pointerToPython(type->d->converter, cppIn);
+}
+
+PyObject* pointerToPython(SbkConverter* converter, const void* cppIn)
+{
+ assert(converter);
if (!cppIn)
Py_RETURN_NONE;
- return type->d->converter->pointerToPython(cppIn);
+ return converter->pointerToPython(cppIn);
}
PyObject* referenceToPython(SbkObjectType* type, const void* cppIn)
@@ -236,6 +254,14 @@ void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut)
*((void**)cppOut) = (pyIn == Py_None) ? 0 : cppPointer((PyTypeObject*)type, (SbkObject*)pyIn);
}
+void pythonToCppPointer(SbkConverter* converter, PyObject* pyIn, void* cppOut)
+{
+ assert(converter);
+ assert(pyIn);
+ assert(cppOut);
+ *((void**)cppOut) = (pyIn == Py_None) ? 0 : cppPointer((PyTypeObject*)converter->pythonType, (SbkObject*)pyIn);
+}
+
static void _pythonToCppCopy(SbkConverter* converter, PyObject* pyIn, void* cppOut)
{
assert(converter);
@@ -252,7 +278,7 @@ void pythonToCppCopy(SbkObjectType* type, PyObject* pyIn, void* cppOut)
_pythonToCppCopy(type->d->converter, pyIn, cppOut);
}
-void pythonToCpp(SbkConverter* converter, PyObject* pyIn, void* cppOut)
+void pythonToCppCopy(SbkConverter* converter, PyObject* pyIn, void* cppOut)
{
_pythonToCppCopy(converter, pyIn, cppOut);
}
diff --git a/libshiboken/sbkconverter.h b/libshiboken/sbkconverter.h
index b0868598..c400693b 100644
--- a/libshiboken/sbkconverter.h
+++ b/libshiboken/sbkconverter.h
@@ -113,6 +113,14 @@ LIBSHIBOKEN_API SbkConverter* createConverter(PyTypeObject* type, CppToPythonFun
LIBSHIBOKEN_API void deleteConverter(SbkConverter* converter);
+/// Sets the Python object to C++ pointer conversion function.
+LIBSHIBOKEN_API void setCppPointerToPythonFunction(SbkConverter* converter, CppToPythonFunc pointerToPythonFunc);
+
+/// Sets the C++ pointer to Python object conversion functions.
+LIBSHIBOKEN_API void setPythonToCppPointerFunctions(SbkConverter* converter,
+ PythonToCppFunc toCppPointerConvFunc,
+ IsConvertibleToCppFunc toCppPointerCheckFunc);
+
/**
* Adds a new conversion of a Python object to a C++ value.
* This is used in copy and implicit conversions.
@@ -134,6 +142,7 @@ LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType* type,
* PyObject* pyVar = pointerToPython(SBKTYPE, &var);
*/
LIBSHIBOKEN_API PyObject* pointerToPython(SbkObjectType* type, const void* cppIn);
+LIBSHIBOKEN_API PyObject* pointerToPython(SbkConverter* converter, const void* cppIn);
/**
* For the given \p cppIn C++ reference it returns the Python wrapper object,
@@ -192,12 +201,11 @@ LIBSHIBOKEN_API void* cppPointer(PyTypeObject* desiredType, SbkObject* pyIn);
/// Converts a Python object \p pyIn to C++ and stores the result in the C++ pointer passed in \p cppOut.
LIBSHIBOKEN_API void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut);
+LIBSHIBOKEN_API void pythonToCppPointer(SbkConverter* converter, PyObject* pyIn, void* cppOut);
-/// Converts a Python object \p pyIn to C++ and copies the result in the C++ variable passed in \p cppOut.
+/// Converts a Python object \p pyIn to C++, and copies the result in the C++ variable passed in \p cppOut.
LIBSHIBOKEN_API void pythonToCppCopy(SbkObjectType* type, PyObject* pyIn, void* cppOut);
-
-/// Converts a Python object \p pyIn to C++, copying the result in the C++ variable passed in \p cppOut.
-LIBSHIBOKEN_API void pythonToCpp(SbkConverter* converter, PyObject* pyIn, void* cppOut);
+LIBSHIBOKEN_API void pythonToCppCopy(SbkConverter* converter, PyObject* pyIn, void* cppOut);
/**
* Helper function returned by generated convertible checking functions