/*
 * Interface wrapper code.
 *
 * Generated by SIP 4.19.6
 */

#include "sipAPIKWidgetsAddons.h"

#include <qmap.h>

#include <qdatetime.h>
#include <qstring.h>


extern "C" {static void assign_QMap_0100QDate_0100QString(void *, SIP_SSIZE_T, void *);}
static void assign_QMap_0100QDate_0100QString(void *sipDst, SIP_SSIZE_T sipDstIdx, void *sipSrc)
{
    reinterpret_cast<QMap< ::QDate, ::QString> *>(sipDst)[sipDstIdx] = *reinterpret_cast<QMap< ::QDate, ::QString> *>(sipSrc);
}


extern "C" {static void *array_QMap_0100QDate_0100QString(SIP_SSIZE_T);}
static void *array_QMap_0100QDate_0100QString(SIP_SSIZE_T sipNrElem)
{
    return new QMap< ::QDate, ::QString>[sipNrElem];
}


extern "C" {static void *copy_QMap_0100QDate_0100QString(const void *, SIP_SSIZE_T);}
static void *copy_QMap_0100QDate_0100QString(const void *sipSrc, SIP_SSIZE_T sipSrcIdx)
{
    return new QMap< ::QDate, ::QString>(reinterpret_cast<const QMap< ::QDate, ::QString> *>(sipSrc)[sipSrcIdx]);
}


/* Call the mapped type's destructor. */
extern "C" {static void release_QMap_0100QDate_0100QString(void *, int);}
static void release_QMap_0100QDate_0100QString(void *ptr, int)
{
    delete reinterpret_cast<QMap< ::QDate, ::QString> *>(ptr);
}



extern "C" {static int convertTo_QMap_0100QDate_0100QString(PyObject *, void **, int *, PyObject *);}
static int convertTo_QMap_0100QDate_0100QString(PyObject *sipPy,void **sipCppPtrV,int *sipIsErr,PyObject *sipTransferObj)
{
    QMap< ::QDate, ::QString> **sipCppPtr = reinterpret_cast<QMap< ::QDate, ::QString> **>(sipCppPtrV);

    if (!sipIsErr)
        return PyDict_Check(sipPy);

    QMap<QDate, QString> *qm = new QMap<QDate, QString>;

    Py_ssize_t pos = 0;
    PyObject *kobj, *vobj;
 
    while (PyDict_Next(sipPy, &pos, &kobj, &vobj))
    {
        int kstate;
        QDate *k = reinterpret_cast<QDate *>(
                sipForceConvertToType(kobj, sipType_QDate, sipTransferObj,
                        SIP_NOT_NONE, &kstate, sipIsErr));

        if (*sipIsErr)
        {
            PyErr_Format(PyExc_TypeError,
                    "a dict key has type '%s' but 'QDate' is expected",
                    sipPyTypeName(Py_TYPE(kobj)));

            delete qm;

            return 0;
        }

        int vstate;
        QString *v = reinterpret_cast<QString *>(
                sipForceConvertToType(vobj, sipType_QString, sipTransferObj,
                        SIP_NOT_NONE, &vstate, sipIsErr));

        if (*sipIsErr)
        {
            PyErr_Format(PyExc_TypeError,
                    "a dict value has type '%s' but 'QString' is expected",
                    sipPyTypeName(Py_TYPE(vobj)));

            sipReleaseType(k, sipType_QDate, kstate);
            delete qm;

            return 0;
        }

        qm->insert(*k, *v);

        sipReleaseType(v, sipType_QString, vstate);
        sipReleaseType(k, sipType_QDate, kstate);
    }
 
    *sipCppPtr = qm;
 
    return sipGetState(sipTransferObj);
}


extern "C" {static PyObject *convertFrom_QMap_0100QDate_0100QString(void *, PyObject *);}
static PyObject *convertFrom_QMap_0100QDate_0100QString(void *sipCppV, PyObject *sipTransferObj)
{
   QMap< ::QDate, ::QString> *sipCpp = reinterpret_cast<QMap< ::QDate, ::QString> *>(sipCppV);

    PyObject *d = PyDict_New();

    if (!d)
        return 0;

    QMap<QDate, QString>::const_iterator it = sipCpp->constBegin();
    QMap<QDate, QString>::const_iterator end = sipCpp->constEnd();

    while (it != end)
    {
        QDate *k = new QDate(it.key());
        PyObject *kobj = sipConvertFromNewType(k, sipType_QDate,
                sipTransferObj);

        if (!kobj)
        {
            delete k;
            Py_DECREF(d);

            return 0;
        }

        QString *v = new QString(it.value());
        PyObject *vobj = sipConvertFromNewType(v, sipType_QString,
                sipTransferObj);

        if (!vobj)
        {
            delete v;
            Py_DECREF(kobj);
            Py_DECREF(d);

            return 0;
        }

        int rc = PyDict_SetItem(d, kobj, vobj);

        Py_DECREF(vobj);
        Py_DECREF(kobj);

        if (rc < 0)
        {
            Py_DECREF(d);

            return 0;
        }

        ++it;
    }

    return d;
}


sipMappedTypeDef sipTypeDef_KWidgetsAddons_QMap_0100QDate_0100QString = {
    {
        -1,
        0,
        0,
        SIP_TYPE_MAPPED,
        sipNameNr_2978,     /* QMap<QDate,QString> */
        {0},
        0
    },
    {
        -1,
        {0, 0, 1},
        0, 0,
        0, 0,
        0, 0,
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    assign_QMap_0100QDate_0100QString,
    array_QMap_0100QDate_0100QString,
    copy_QMap_0100QDate_0100QString,
    release_QMap_0100QDate_0100QString,
    convertTo_QMap_0100QDate_0100QString,
    convertFrom_QMap_0100QDate_0100QString
};
