[PyKDE] sip - how to get around member function templates?

Sato, Kristine Kristine.Sato at vugames.com
Wed Aug 13 20:31:00 BST 2003


On Tuesday 05 August 2003 7:05 pm, Sato, Kristine wrote:
> Hello,
>
> I want to use sip on a class which uses member function templates. Any
> suggestions on the best approach?
>
> Here's a snippet from the class - the SetValue() and GetValue() member
> functions are the problematic ones!
>
> class Record
> {
> public:
>          Record(UtTable& , const u32 );
>          template<class ITEM_TYPE>
>          UtStatus           SetValue(const u32, const ITEM_TYPE&);
>          template<class ITEM_TYPE>
>          UtStatus           GetValue(const u32, ITEM_TYPE&);
> };

At the moment you will have to implement ITEM_TYPE as a %MappedType and 
provide to handwritten code to convert between a C++ instance and a Python 
object that you choose to represent the instance.

Phil

I just tried what you suggested, and it ALMOST works for my class methods...
after running through SIP, I needed to manually add the template<class
ITEM_TYPE> prefix to the ITEM_TYPE mapping functions in order for my
conversion code to compile:

template<class ITEM_TYPE> 
extern SIP_MODULE_EXTERN int sipConvertTo_ITEM_TYPE Py_PROTO((PyObject
*,ITEM_TYPE **,int *));

template<class ITEM_TYPE> 
extern SIP_MODULE_EXTERN ITEM_TYPE *sipForceConvertTo_ITEM_TYPE
Py_PROTO((PyObject *,int *));

template<class ITEM_TYPE> 
extern SIP_MODULE_EXTERN PyObject *sipConvertFrom_ITEM_TYPE
Py_PROTO((ITEM_TYPE *));


and then I also needed to do the same for the ITEM_TYPE-related methods:


template<class ITEM_TYPE>
static PyObject *sipDo_UtTable_Record_SetValue(PyObject *sipThisObj,PyObject
*sipArgs)

template<class ITEM_TYPE>
static PyObject *sipDo_UtTable_Record_GetValue(PyObject *sipThisObj,PyObject
*sipArgs)

in order for them to compile properly.


But the problem is that now I get a compile error on:

static PyMethodDef lazyMethods_UtTable_Record[] = {
	{sipName_Engine_GetValue, sipDo_UtTable_Record_GetValue,
METH_VARARGS, NULL},
	{sipName_Engine_SetValue, sipDo_UtTable_Record_SetValue,
METH_VARARGS, NULL}
};

because the functions sipDo_UtTable_Record_GetValue() and
sipDo_UtTable_Record_SetValue() are no longer of the correct (PyCFunction)
type. 

So it doesn't look like using template member functions is going to work
with Python, as the PyMethodDef struct will not accept a template function. 

It looks like I will just have to write %MemberCode for methods for each 
specific item type I support. :(

-Kristine




More information about the PyQt mailing list