// qset.sip generated by MetaSIP
//
// This file is part of the QtCore Python extension module.
//
// Copyright (c) 2016 Riverbank Computing Limited <info@riverbankcomputing.com>
// 
// This file is part of PyQt4.
// 
// This file may be used under the terms of the GNU General Public License
// version 3.0 as published by the Free Software Foundation and appearing in
// the file LICENSE included in the packaging of this file.  Please review the
// following information to ensure the GNU General Public License version 3.0
// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
// 
// If you do not wish to use this file under the terms of the GPL version 3.0
// then you may purchase a commercial license.  For more information contact
// info@riverbankcomputing.com.
// 
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


%If (Py_v3)
// QSet<int> is implemented as a Python set in Python v3.
%MappedType QSet<int> /TypeHintIn="Iterable[int]", TypeHintOut="Set[int]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the set.
    PyObject *s;

    if ((s = PySet_New(NULL)) == NULL)
        return NULL;

    // Set the set elements.
    QSet<int>::const_iterator it = sipCpp->constBegin();
    QSet<int>::const_iterator end = sipCpp->constEnd();

    while (it != end)
    {
        PyObject *el_obj;

        if ((el_obj = SIPLong_FromLong(*it)) == NULL)
        {
            Py_DECREF(s);
            return NULL;
        }

        PySet_Add(s, el_obj);

        ++it;
    }

    return s;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<int> *qs = new QSet<int>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        qs->insert(SIPLong_AsLong(itm));
        Py_DECREF(itm);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (!Py_v3)
// QSet<int> is implemented as a Python list in Python v2.
%MappedType QSet<int> /TypeHintIn="Iterable[int]", TypeHintOut="List[int]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the list.
    PyObject *l;

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

    // Set the list elements.
    QSet<int>::const_iterator it = sipCpp->constBegin();

    for (int i = 0; i < sipCpp->size(); ++i)
    {
        PyObject *el_obj;

        if ((el_obj = SIPLong_FromLong(*it)) == NULL)
        {
            Py_DECREF(l);
            return NULL;
        }

        PyList_SET_ITEM(l, i, el_obj);

        ++it;
    }

    return l;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<int> *qs = new QSet<int>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        qs->insert(SIPLong_AsLong(itm));
        Py_DECREF(itm);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (Py_v3)
// QSet<unsigned> is implemented as a Python set in Python v3.
%MappedType QSet<unsigned> /TypeHintIn="Iterable[int]", TypeHintOut="Set[int]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the set.
    PyObject *s;

    if ((s = PySet_New(NULL)) == NULL)
        return NULL;

    // Set the set elements.
    QSet<unsigned>::const_iterator it = sipCpp->constBegin();
    QSet<unsigned>::const_iterator end = sipCpp->constEnd();

    while (it != end)
    {
        PyObject *el_obj;

        if ((el_obj = PyLong_FromUnsignedLong(*it)) == NULL)
        {
            Py_DECREF(s);
            return NULL;
        }

        PySet_Add(s, el_obj);

        ++it;
    }

    return s;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<unsigned> *qs = new QSet<unsigned>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        qs->insert(PyLong_AsUnsignedLong(itm));
        Py_DECREF(itm);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (!Py_v3)
// QSet<unsigned> is implemented as a Python list in Python v2.
%MappedType QSet<unsigned> /TypeHintIn="Iterable[int]", TypeHintOut="List[int]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the list.
    PyObject *l;

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

    // Set the list elements.
    QSet<unsigned>::const_iterator it = sipCpp->constBegin();

    for (int i = 0; i < sipCpp->size(); ++i)
    {
        PyObject *el_obj;

        if ((el_obj = PyLong_FromUnsignedLong(*it)) == NULL)
        {
            Py_DECREF(l);
            return NULL;
        }

        PyList_SET_ITEM(l, i, el_obj);

        ++it;
    }

    return l;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<unsigned> *qs = new QSet<unsigned>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        qs->insert(PyLong_AsUnsignedLong(itm));
        Py_DECREF(itm);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (Py_v3)
// QSet<TYPE *> is implemented as a Python set in Python v3.
template<TYPE>
%MappedType QSet<TYPE *> /TypeHintIn="Iterable[TYPE]", TypeHintOut="Set[TYPE]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the set.
    PyObject *s;

    if ((s = PySet_New(NULL)) == NULL)
        return NULL;

    // Set the set elements.
    QSet<TYPE *>::const_iterator it = sipCpp->constBegin();
    QSet<TYPE *>::const_iterator end = sipCpp->constEnd();

    while (it != end)
    {
        PyObject *tobj;

        // The explicit (void *) cast allows TYPE to be const.
        if ((tobj = sipConvertFromType((void *)*it, sipType_TYPE, sipTransferObj)) == NULL)
        {
            Py_DECREF(s);
            return NULL;
        }

        PySet_Add(s, tobj);

        ++it;
    }

    return s;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        while ((itm = PyIter_Next(it)) != NULL)
        {
            int ok = sipCanConvertToType(itm, sipType_TYPE, 0);

            Py_DECREF(itm);

            if (!ok)
            {
                Py_DECREF(it);
                return 0;
            }
        }

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<TYPE *> *qs = new QSet<TYPE *>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, 0, 0, sipIsErr));

        Py_DECREF(itm);

        if (*sipIsErr)
        {
            delete qs;
            Py_DECREF(it);
            return 0;
        }

        qs->insert(t);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (!Py_v3)
// QSet<TYPE *> is implemented as a Python list in Python v2.
template<TYPE>
%MappedType QSet<TYPE *> /TypeHintIn="Iterable[TYPE]", TypeHintOut="List[TYPE]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the list.
    PyObject *l;

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

    // Set the list elements.
    QSet<TYPE *>::const_iterator it = sipCpp->constBegin();

    for (int i = 0; i < sipCpp->size(); ++i)
    {
        PyObject *tobj;

        // The explicit (void *) cast allows TYPE to be const.
        if ((tobj = sipConvertFromType((void *)*it, sipType_TYPE, sipTransferObj)) == NULL)
        {
            Py_DECREF(l);
            return NULL;
        }

        PyList_SET_ITEM(l, i, tobj);

        ++it;
    }

    return l;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        while ((itm = PyIter_Next(it)) != NULL)
        {
            int ok = sipCanConvertToType(itm, sipType_TYPE, 0);

            Py_DECREF(itm);

            if (!ok)
            {
                Py_DECREF(it);
                return 0;
            }
        }

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<TYPE *> *qs = new QSet<TYPE *>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, 0, 0, sipIsErr));

        Py_DECREF(itm);

        if (*sipIsErr)
        {
            delete qs;
            Py_DECREF(it);
            return 0;
        }

        qs->insert(t);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (Py_v3)
// QSet<TYPE> is implemented as a Python set in Python v3.
template<TYPE>
%MappedType QSet<TYPE> /TypeHintIn="Iterable[TYPE]", TypeHintOut="Set[Type]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the set.
    PyObject *s;

    if ((s = PySet_New(NULL)) == NULL)
        return NULL;

    // Set the set elements.
    QSet<TYPE>::const_iterator it = sipCpp->constBegin();
    QSet<TYPE>::const_iterator end = sipCpp->constEnd();

    while (it != end)
    {
        TYPE *t = new TYPE(*it);
        PyObject *tobj;

        if ((tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj)) == NULL)
        {
            Py_DECREF(s);
            delete t;

            return NULL;
        }

        PySet_Add(s, tobj);

        ++it;
    }

    return s;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        while ((itm = PyIter_Next(it)) != NULL)
        {
            int ok = sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE);

            Py_DECREF(itm);

            if (!ok)
            {
                Py_DECREF(it);
                return 0;
            }
        }

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<TYPE> *qs = new QSet<TYPE>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        int state;
        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

        Py_DECREF(itm);

        if (*sipIsErr)
        {
            sipReleaseType(t, sipType_TYPE, state);

            delete qs;
            Py_DECREF(it);
            return 0;
        }

        qs->insert(*t);

        sipReleaseType(t, sipType_TYPE, state);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
%If (!Py_v3)
// QSet<TYPE> is implemented as a Python list in Python v2.
template<TYPE>
%MappedType QSet<TYPE> /TypeHintIn="Iterable[TYPE]", TypeHintOut="List[TYPE]", TypeHintValue="set()"/
{
%TypeHeaderCode
#include <qset.h>
%End

%ConvertFromTypeCode
    // Create the list.
    PyObject *l;

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

    // Set the list elements.
    QSet<TYPE>::const_iterator it = sipCpp->constBegin();

    for (int i = 0; i < sipCpp->size(); ++i)
    {
        TYPE *t = new TYPE(*it);
        PyObject *tobj;

        if ((tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj)) == NULL)
        {
            Py_DECREF(l);
            delete t;

            return NULL;
        }

        PyList_SET_ITEM(l, i, tobj);

        ++it;
    }

    return l;
%End

%ConvertToTypeCode
    PyObject *it = PyObject_GetIter(sipPy), *itm;

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

        while ((itm = PyIter_Next(it)) != NULL)
        {
            int ok = sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE);

            Py_DECREF(itm);

            if (!ok)
            {
                Py_DECREF(it);
                return 0;
            }
        }

        Py_DECREF(it);
        return 1;
    }

    if (it == NULL)
    {
        *sipIsErr = 1;
        return 0;
    }

    QSet<TYPE> *qs = new QSet<TYPE>;

    while ((itm = PyIter_Next(it)) != NULL)
    {
        int state;
        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

        Py_DECREF(itm);

        if (*sipIsErr)
        {
            sipReleaseType(t, sipType_TYPE, state);

            delete qs;
            Py_DECREF(it);
            return 0;
        }

        qs->insert(*t);

        sipReleaseType(t, sipType_TYPE, state);
    }

    Py_DECREF(it);

    *sipCppPtr = qs;

    return sipGetState(sipTransferObj);
%End
};
%End
