[PyQt] SIP Non type template parameter

srikanth.nagella at stfc.ac.uk srikanth.nagella at stfc.ac.uk
Thu Aug 11 10:44:00 BST 2016


Hi

I am trying to create a wrapper for a template class with non type template parameter but the SIP throws syntax error. Is there a work around to the code below?

array.h
------------------------------------------
template <typename T,int SIZE>
class array {
    T  var[SIZE];
public:
    T getValue(int index);
    void setValue(int index,T val);
};

template<typename T,int SIZE> T array<T,SIZE>::getValue(int index)
{
    return var[index];
}

template<typename T,int SIZE> int array<T,SIZE>::getSize()
{
    return SIZE;
}

template<typename T,int SIZE> void  array<T,SIZE>::setValue(int index, T val)
{
    var[index]=val;
}


array.sip
--------------------------------------------------------
%MappedType array<int,10> /DocType="array-of-int"/      <<<<<<<< Syntax error.
{
%TypeHeaderCode
#include "array.h"
%End

%ConvertFromTypeCode
    //Create the list
    PyObject *l;
    if((l = PyList_New(sipCpp->getSize())) == NULL)
      return NULL;
    //Set the list elements
    for(int i=0; i < sipCpp->getSize); ++i)
    {
       PyObject *tobj;
        if ((tobj = SIPLong_FromLong(sipCpp->getValue(i))) == NULL)
        {
            Py_DECREF(l);
            return NULL;
        }
        PyList_SET_ITEM(l, i, tobj);
    }
    return l;
%End

%ConvertToTypeCode
    SIP_SSIZE_T len;
    // Check the type if that is all that is required.
    if (sipIsErr == NULL)
    {
        return (PySequence_Check(sipPy) && PySequence_Size(sipPy) >= 0);
    }
    array<int,10> *ql = new array<int,10>();
    len = PySequence_Size(sipPy);
    for (SIP_SSIZE_T i = 0; i < len; ++i)
    {
        PyObject *itm = PySequence_ITEM(sipPy, i);
        PyErr_Clear();
        long val = itm ? SIPLong_AsLong(itm) : -1;
        if(!itm || (val == -1 && PyErr_Occurred()))
         {
           Py_DECREF(itm);
           delete ql;
           *sipIsErr = 1;
           return 0;
         }
        ql->setValue(i,val);
        Py_DECREF(itm);
    }
    *sipCppPtr = ql;
    return sipGetState(sipTransferObj);
%End

};

Thanks
Sri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160811/b91d953f/attachment-0001.html>


More information about the PyQt mailing list