File: qmap_convert.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 (82 lines) | stat: -rw-r--r-- 2,124 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
75
76
77
78
79
80
81
82
// QMap<double, QString> is implemented as a Python dictionary.

%MappedType QMap<double,QString> /TypeHint="Dict[double,QString]", TypeHintValue="{}"/
{
%TypeHeaderCode
#include <qwt_compass.h>
%End

%ConvertFromTypeCode
    // Create the dictionary.
    PyObject *d = PyDict_New();

    if (!d)
        return NULL;

    // Set the dictionary elements.
    QMap<double,QString>::const_iterator i = sipCpp->constBegin();

    while (i != sipCpp->constEnd())
    {
        QString *t = new QString(i.value());

        PyObject *kobj = PyFloat_FromDouble(i.key());
        PyObject *tobj = sipConvertFromType(t, sipType_QString, sipTransferObj);

        if (kobj == NULL || tobj == NULL || PyDict_SetItem(d, kobj, tobj) < 0)
        {
            Py_DECREF(d);
            if (kobj)
            {
                Py_DECREF(kobj);
            }
            if (tobj)
            {
                Py_DECREF(tobj);
            }
            else
            {
                delete t;
            }
            return NULL;
        }
        Py_DECREF(kobj);
        Py_DECREF(tobj);
        ++i;
    }
    return d;
%End

%ConvertToTypeCode
    PyObject *kobj, *tobj;
    SIP_SSIZE_T i = 0;
    // Check the type if that is all that is required.
    if (sipIsErr == NULL)
    {
        if (!PyDict_Check(sipPy))
            return 0;
        while (PyDict_Next(sipPy, &i, &kobj, &tobj))
            if (!sipCanConvertToType(tobj, sipType_QString, SIP_NOT_NONE))
                return 0;
        return 1;
    }
    QMap<double,QString> *qm = new QMap<double,QString>;
    while (PyDict_Next(sipPy, &i, &kobj, &tobj))
    {
        int state;
        double k = PyFloat_AS_DOUBLE(kobj);
        QString *t = reinterpret_cast<QString *>(sipConvertToType(tobj, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
        if (*sipIsErr)
        {
            sipReleaseType(t, sipType_QString, state);
            delete qm;
            return 0;
        }
        qm->insert(k, *t);
        sipReleaseType(t, sipType_QString, state);
    }
    *sipCppPtr = qm;
    return sipGetState(sipTransferObj);
%End
};