[PyKDE] SIP: MappedType for pointers?
Jim Bublitz
jbublitz at nwinternet.com
Tue Mar 21 20:41:14 GMT 2006
On Tuesday 21 March 2006 10:23, Giovanni Bajo wrote:
> Hello,
>
> I'm writing a SIP wrapper for a serie of overloaded functions like this:
>
> void Foo(char *str);
> void Foo(wchar_t *str);
>
> void Bar(char *str);
> void Bar(wchar_t *str);
>
> [etc.]
>
> Python supports conversion to/from wchar_t buffers using
> PyUnicode_From/AsWideChar, but SIP does not support it. Could this be added
> automatically?
>
> This notwithstanding, I couldn't find a way to use %MappedType to solve my
> problem, without having to write many duplicated %MappedCode. Any pointer?
Same as the following, except "%MappedType wchar_t" and other obvious changes.
You'd only have to write it once - all conversions will be handled correctly
wherever wchar_t is referenced.
%MappedType longlong
//converts a Python long
{
%TypeHeaderCode
typedef long long longlong;
#if PY_MAJOR_VERSION >= 2 && PY_MINOR_VERSION >= 3
#define LONG_LONG PY_LONG_LONG
#endif
%End
%ConvertFromTypeCode
if (!sipCpp)
Py_INCREF (Py_None);
return Py_None;
return PyLong_FromLongLong (*(LONG_LONG *)sipCpp);
%End
%ConvertToTypeCode
if (sipIsErr == NULL)
return PyLong_Check (sipPy) || PyInt_Check (sipPy);
long long *ll = new long long;
*ll = 0;
if (PyLong_Check (sipPy))
*ll = PyLong_AsLongLong (sipPy);
else if (PyInt_Check (sipPy))
*ll = (long long)PyInt_AS_LONG (sipPy);
*sipCppPtr = ll;
return 1;
%End
};
Jim
More information about the PyQt
mailing list