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

#include "sipAPIKConfigCore.h"

#include <qlist.h>

#include <kcoreconfigskeleton.h>


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


extern "C" {static void *array_QList_0101KConfigSkeletonItem(SIP_SSIZE_T);}
static void *array_QList_0101KConfigSkeletonItem(SIP_SSIZE_T sipNrElem)
{
    return new QList< ::KConfigSkeletonItem*>[sipNrElem];
}


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


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



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

    PyObject *iter = PyObject_GetIter(sipPy);

    if (!sipIsErr)
    {
        Py_XDECREF(iter);

        return (iter
#if PY_MAJOR_VERSION < 3
                && !PyString_Check(sipPy)
#endif
                && !PyUnicode_Check(sipPy));
    }

    if (!iter)
    {
        *sipIsErr = 1;

        return 0;
    }

    QList<KConfigSkeletonItem *> *ql = new QList<KConfigSkeletonItem *>;
 
    for (Py_ssize_t i = 0; ; ++i)
    {
        PyErr_Clear();
        PyObject *itm = PyIter_Next(iter);

        if (!itm)
        {
            if (PyErr_Occurred())
            {
                delete ql;
                Py_DECREF(iter);
                *sipIsErr = 1;

                return 0;
            }

            break;
        }

        KConfigSkeletonItem *t = reinterpret_cast<KConfigSkeletonItem *>(
                sipForceConvertToType(itm, sipType_KConfigSkeletonItem, sipTransferObj, 0,
                        0, sipIsErr));
 
        if (*sipIsErr)
        {
            PyErr_Format(PyExc_TypeError,
                    "index %zd has type '%s' but 'KConfigSkeletonItem' is expected", i,
                    sipPyTypeName(Py_TYPE(itm)));

            Py_DECREF(itm);
            delete ql;
            Py_DECREF(iter);

            return 0;
        }

        ql->append(t);

        Py_DECREF(itm);
    }

    Py_DECREF(iter);
 
    *sipCppPtr = ql;
 
    return sipGetState(sipTransferObj);
}


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

    int gc_enabled = sipEnableGC(0);
    PyObject *l = PyList_New(sipCpp->size());

    if (l)
    {
        for (int i = 0; i < sipCpp->size(); ++i)
        {
            KConfigSkeletonItem *t = sipCpp->at(i);

            // The explicit (void *) cast allows KConfigSkeletonItem to be const.
            PyObject *tobj = sipConvertFromType((void *)t, sipType_KConfigSkeletonItem,
                    sipTransferObj);

            if (!tobj)
            {
                Py_DECREF(l);
                l = 0;

                break;
            }

            PyList_SetItem(l, i, tobj);
        }
    }

    sipEnableGC(gc_enabled);

    return l;
}


sipMappedTypeDef sipTypeDef_KConfigCore_QList_0101KConfigSkeletonItem = {
    {
        -1,
        0,
        0,
        SIP_TYPE_MAPPED,
        sipNameNr_856,     /* QList<KConfigSkeletonItem*> */
        {0},
        0
    },
    {
        -1,
        {0, 0, 1},
        0, 0,
        0, 0,
        0, 0,
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    assign_QList_0101KConfigSkeletonItem,
    array_QList_0101KConfigSkeletonItem,
    copy_QList_0101KConfigSkeletonItem,
    release_QList_0101KConfigSkeletonItem,
    convertTo_QList_0101KConfigSkeletonItem,
    convertFrom_QList_0101KConfigSkeletonItem
};
