// qset.sip generated by MetaSIP on Fri Feb 10 10:35:11 2012
//
// This file is part of the QtCore Python extension module.
//
// Copyright (c) 2011 Riverbank Computing Limited <info@riverbankcomputing.com>
// 
// This file is part of PyQt.
// 
// This file may be used under the terms of the GNU General Public
// License versions 2.0 or 3.0 as published by the Free Software
// Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
// included in the packaging of this file.  Alternatively you may (at
// your option) use any later version of the GNU General Public
// License if such license has been publicly approved by Riverbank
// Computing Limited (or its successors, if any) and the KDE Free Qt
// Foundation. In addition, as a special exception, Riverbank gives you
// certain additional rights. These rights are described in the Riverbank
// GPL Exception version 1.1, which can be found in the file
// GPL_EXCEPTION.txt in this package.
// 
// If you are unsure which license is appropriate for your use, please
// contact the sales department at sales@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> /DocType="set-of-int"/
{
%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> /DocType="list-of-int"/
{
%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> /DocType="set-of-int"/
{
%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> /DocType="list-of-int"/
{
%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 *> /DocType="set-of-TYPE"/
{
%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 *> /DocType="list-of-TYPE"/
{
%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> /DocType="set-of-TYPE"/
{
%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> /DocType="list-of-TYPE"/
{
%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
