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

#include "sipAPIKConfigCore.h"

#include <qhash.h>

#include <kcoreconfigskeleton.h>
#include <qstring.h>


extern "C" {static void assign_QHash_0100QString_0101KConfigSkeletonItem(void *, SIP_SSIZE_T, const void *);}
static void assign_QHash_0100QString_0101KConfigSkeletonItem(void *sipDst, SIP_SSIZE_T sipDstIdx, const void *sipSrc)
{
    reinterpret_cast<QHash< ::QString, ::KConfigSkeletonItem*> *>(sipDst)[sipDstIdx] = *reinterpret_cast<const QHash< ::QString, ::KConfigSkeletonItem*> *>(sipSrc);
}


extern "C" {static void *array_QHash_0100QString_0101KConfigSkeletonItem(SIP_SSIZE_T);}
static void *array_QHash_0100QString_0101KConfigSkeletonItem(SIP_SSIZE_T sipNrElem)
{
    return new QHash< ::QString, ::KConfigSkeletonItem*>[sipNrElem];
}


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


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



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

    if (!sipIsErr)
        return PyDict_Check(sipPy);

    QHash<QString, KConfigSkeletonItem *> *qh = new QHash<QString, KConfigSkeletonItem *>;

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

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

            delete qh;

            return 0;
        }

        KConfigSkeletonItem *v = reinterpret_cast<KConfigSkeletonItem *>(
                sipForceConvertToType(vobj, sipType_KConfigSkeletonItem, sipTransferObj, 0,
                        0, sipIsErr));

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

            sipReleaseType(k, sipType_QString, kstate);
            delete qh;

            return 0;
        }

        qh->insert(*k, v);

        sipReleaseType(k, sipType_QString, kstate);
    }
 
    *sipCppPtr = qh;
 
    return sipGetState(sipTransferObj);
}


extern "C" {static PyObject *convertFrom_QHash_0100QString_0101KConfigSkeletonItem(void *, PyObject *);}
static PyObject *convertFrom_QHash_0100QString_0101KConfigSkeletonItem(void *sipCppV, PyObject *sipTransferObj)
{
   QHash< ::QString, ::KConfigSkeletonItem*> *sipCpp = reinterpret_cast<QHash< ::QString, ::KConfigSkeletonItem*> *>(sipCppV);

    int gc_enabled = sipEnableGC(0);
    PyObject *d = PyDict_New();

    if (d)
    {
        QHash<QString, KConfigSkeletonItem *>::const_iterator it = sipCpp->constBegin();
        QHash<QString, KConfigSkeletonItem *>::const_iterator end = sipCpp->constEnd();

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

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

                break;
            }

            KConfigSkeletonItem *v = it.value();
            PyObject *vobj = sipConvertFromNewType(v, sipType_KConfigSkeletonItem,
                    sipTransferObj);

            if (!vobj)
            {
                Py_DECREF(kobj);
                Py_DECREF(d);
                d = 0;

                break;
            }

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

            Py_DECREF(vobj);
            Py_DECREF(kobj);

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

                break;
            }

            ++it;
        }
    }

    sipEnableGC(gc_enabled);

    return d;
}


sipMappedTypeDef sipTypeDef_KConfigCore_QHash_0100QString_0101KConfigSkeletonItem = {
    {
        -1,
        0,
        0,
        SIP_TYPE_MAPPED,
        sipNameNr_121,     /* QHash<QString,KConfigSkeletonItem*> */
        {0},
        0
    },
    {
        -1,
        {0, 0, 1},
        0, 0,
        0, 0,
        0, 0,
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    assign_QHash_0100QString_0101KConfigSkeletonItem,
    array_QHash_0100QString_0101KConfigSkeletonItem,
    copy_QHash_0100QString_0101KConfigSkeletonItem,
    release_QHash_0100QString_0101KConfigSkeletonItem,
    convertTo_QHash_0100QString_0101KConfigSkeletonItem,
    convertFrom_QHash_0100QString_0101KConfigSkeletonItem
};
