File: conversions.sip

package info (click to toggle)
pyqt-qwt 1.02.02-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 796 kB
  • sloc: python: 5,663; cpp: 273; makefile: 16; sh: 13
file content (74 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Code borrowed from qgis */

%MappedType QVector< QVector<qreal> >
{
%TypeHeaderCode
#include <QVector>
%End
%ConvertFromTypeCode
  // Create the list.
  PyObject *l;

  if ((l = PyList_New(sipCpp->size())) == NULL)
    return NULL;

  const sipMappedType* qvector_qreal = sipFindType("QVector<qreal>");

  // Set the list elements.
  for (int i = 0; i < sipCpp->size(); ++i)
  {
    QVector<qreal>* t = new QVector<qreal>(sipCpp->at(i));
    PyObject *tobj;

    if ((tobj = sipConvertFromType(t, qvector_qreal, sipTransferObj)) == NULL)
    {
      Py_DECREF(l);
      delete t;
      return NULL;
    }
    PyList_SET_ITEM(l, i, tobj);
  }

  return l;
%End

%ConvertToTypeCode
  const sipMappedType* qvector_qreal = sipFindType("QVector<qreal>");

  // Check the type if that is all that is required.
  if (sipIsErr == NULL)
  {
    if (!PyList_Check(sipPy))
      return 0;

    for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
      if (!sipCanConvertToType(PyList_GET_ITEM(sipPy, i), qvector_qreal, SIP_NOT_NONE))
        return 0;

    return 1;
  }


  QVector< QVector<qreal> > *ql = new QVector< QVector<qreal> >;

  for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
  {
    int state;
    //qreal *t = reinterpret_cast<qreal *>(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_qreal, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
    QVector<qreal> * t = reinterpret_cast< QVector<qreal> * >(sipConvertToType(PyList_GET_ITEM(sipPy, i), qvector_qreal, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

    if (*sipIsErr)
    {
      sipReleaseType(t, qvector_qreal, state);
      delete ql;
      return 0;
    }
    ql->append(*t);
    sipReleaseType(t, qvector_qreal, state);
  }

  *sipCppPtr = ql;
  return sipGetState(sipTransferObj);
%End
};