// qbytearray.sip generated by MetaSIP on Sat Nov  8 11:58:27 2008
//
// This file is part of the QtCore Python extension module.
//
// Copyright (c) 2008 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.
// 
// Please review the following information to ensure GNU General
// Public Licensing requirements will be met:
// http://trolltech.com/products/qt/licenses/licensing/opensource/. If
// you are unsure which license is appropriate for your use, please
// review the following information:
// http://trolltech.com/products/qt/licenses/licensing/licensingoverview
// or contact the sales department at sales@riverbankcomputing.com.
// 
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
// granted herein.
// 
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


%ModuleCode
#include <qbytearray.h>
%End

char *qstrdup(const char *);
uint qstrlen(const char *str);
%If (Qt_4_2_0 -)
uint qstrnlen(const char *str, uint maxlen);
%End
char *qstrcpy(char *dst, const char *src);
char *qstrncpy(char *dst, const char *src, uint len);
int qstrcmp(const char *str1, const char *str2);
int qstrncmp(const char *str1, const char *str2, uint len);
int qstricmp(const char *, const char *);
int qstrnicmp(const char *, const char *, uint len);
quint16 qChecksum(const char *s /Array/, uint len /ArraySize/);

class QByteArray
{

%TypeHeaderCode
#include <qbytearray.h>
%End

%TypeCode
// This is needed by __hash__().
#include <qhash.h>


// Convenience function for converting a QByteArray to a Python str object.
static PyObject *QByteArrayToPyStr(QByteArray *ba)
{
    char *data = ba->data();

    if (data)
        // QByteArrays may have embedded '\0's so set the size explicitly.    
        return PyString_FromStringAndSize(data, ba->size());

    return PyString_FromString("");
}
%End

%ConvertToTypeCode
// Allow a Python string whenever a QByteArray is expected.

if (sipIsErr == NULL)
    return (PyString_Check(sipPy) ||
            sipCanConvertToInstance(sipPy, sipClass_QByteArray, SIP_NO_CONVERTORS));

if (PyString_Check(sipPy))
{
    *sipCppPtr = new QByteArray(PyString_AS_STRING(sipPy), PyString_GET_SIZE(sipPy));

    return sipGetState(sipTransferObj);
}

*sipCppPtr = reinterpret_cast<QByteArray *>(sipConvertToInstance(sipPy, sipClass_QByteArray, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));

return 0;
%End

%BIGetReadBufferCode
    if (sipSegment != 0)
    {
        PyErr_SetString(PyExc_SystemError, "accessing non-existent QByteArray segment");
        sipRes = -1;
    }
    else
    {
        *sipPtrPtr = (void *)sipCpp->data();
        sipRes = sipCpp->size();
    }
%End

%BIGetSegCountCode
    if (sipLenPtr)
        *sipLenPtr = sipCpp->size();
    
    sipRes = 1;
%End

%BIGetCharBufferCode
    if (sipSegment != 0)
    {
        PyErr_SetString(PyExc_SystemError, "accessing non-existent QByteArray segment");
        sipRes = -1;
    }
    else
    {
        *sipPtrPtr = (void *)sipCpp->data();
        sipRes = sipCpp->size();
    }
%End

%PickleCode
    sipRes = Py_BuildValue((char *)"(s#)", sipCpp->data(), sipCpp->size());
%End

public:
    QByteArray();
    QByteArray(int size, char c);
    QByteArray(const QByteArray &a);
    ~QByteArray();
    void resize(int size);
    QByteArray &fill(char c, int size = -1);
    void clear();
    int indexOf(const QByteArray &a, int from = 0) const;
    int indexOf(const QString &s, int from = 0) const;
    int lastIndexOf(const QByteArray &a, int from = -1) const;
    int lastIndexOf(const QString &s, int from = -1) const;
    int count(const QByteArray &a) const;
    QByteArray left(int len) const;
    QByteArray right(int len) const;
    QByteArray mid(int index, int len = -1) const;
    bool startsWith(const QByteArray &a) const;
    bool endsWith(const QByteArray &a) const;
    void truncate(int pos);
    void chop(int n);
    QByteArray toLower() const;
    QByteArray toUpper() const;
    QByteArray trimmed() const;
    QByteArray simplified() const;
    QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const;
    QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const;
    QByteArray &prepend(const QByteArray &a);
    QByteArray &append(const QByteArray &a);
    QByteArray &append(const QString &s);
    QByteArray &insert(int i, const QByteArray &a);
    QByteArray &insert(int i, const QString &s);
    QByteArray &remove(int index, int len);
    QByteArray &replace(int index, int len, const QByteArray &s);
    QByteArray &replace(const QByteArray &before, const QByteArray &after);
    QByteArray &replace(const QString &before, const QByteArray &after);
    QList<QByteArray> split(char sep) const;
    QByteArray &operator+=(const QByteArray &a);
    QByteArray &operator+=(const QString &s);
    bool operator==(const QString &s2) const;
    bool operator!=(const QString &s2) const;
    bool operator<(const QString &s2) const;
    bool operator>(const QString &s2) const;
    bool operator<=(const QString &s2) const;
    bool operator>=(const QString &s2) const;
    short toShort(bool *ok = 0, int base = 10) const;
    ushort toUShort(bool *ok = 0, int base = 10) const;
    int toInt(bool *ok = 0, int base = 10) const;
    uint toUInt(bool *ok = 0, int base = 10) const;
    long toLong(bool *ok = 0, int base = 10) const;
    ulong toULong(bool *ok = 0, int base = 10) const;
    qlonglong toLongLong(bool *ok = 0, int base = 10) const;
    qulonglong toULongLong(bool *ok = 0, int base = 10) const;
    float toFloat(bool *ok = 0) const;
    double toDouble(bool *ok = 0) const;
    QByteArray toBase64() const;
    QByteArray &setNum(int n /Constrained/, int base = 10);
    QByteArray &setNum(double /Constrained/, char f = 'g', int prec = 6);
    QByteArray &setNum(qlonglong, int base = 10);
    QByteArray &setNum(qulonglong, int base = 10);
    static QByteArray number(int /Constrained/, int base = 10);
    static QByteArray number(double /Constrained/, char f = 'g', int prec = 6);
    static QByteArray number(qlonglong, int base = 10);
    static QByteArray number(qulonglong, int base = 10);
    static QByteArray fromBase64(const QByteArray &base64);
    static QByteArray fromRawData(const char * /Array/, int size /ArraySize/);
%If (Qt_4_3_0 -)
    static QByteArray fromHex(const QByteArray &hexEncoded);
%End
    int count() const;
    int length() const;
    bool isNull() const;
    int size() const;
    const char at(int i) const;
    const char operator[](int i) const;
%MethodCode
        SIP_SSIZE_T idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
        
        if (idx < 0)
            sipIsErr = 1;
        else
            sipRes = sipCpp->operator[]((int)idx);
%End

    QByteArray operator[](SIP_PYSLICE slice) const;
%MethodCode
        SIP_SSIZE_T len, start, stop, step, slicelength, i;
        
        len = sipCpp->length();
        
        if (PySlice_GetIndicesEx((PySliceObject *)a0, len, &start, &stop, &step, &slicelength) < 0)
            sipIsErr = 1;
        else
        {
            sipRes = new QByteArray();
        
            for (i = 0; i < slicelength; ++i)
            {
                sipRes -> append(sipCpp->at(start));
                start += step;
            }
        }
%End

    int __len__() const;
%MethodCode
        sipRes = sipCpp->length();
%End

    int __contains__(const QByteArray &a) const;
%MethodCode
        // It looks like you can't assign QBool to int.
        sipRes = bool(sipCpp->contains(*a0));
%End

    long __hash__() const;
%MethodCode
        sipRes = qHash(*sipCpp);
%End

    SIP_PYOBJECT __str__() const;
%MethodCode
        sipRes = QByteArrayToPyStr(sipCpp);
%End

    SIP_PYOBJECT __repr__() const;
%MethodCode
        PyObject *str = QByteArrayToPyStr(sipCpp);
        
        if (str)
        {
            sipRes = PyString_FromString("PyQt4.QtCore.QByteArray(");
            PyString_ConcatAndDel(&sipRes, PyObject_Repr(str));
            PyString_ConcatAndDel(&sipRes, PyString_FromString(")"));
        
            Py_DECREF(str);
        }
        else
            sipRes = 0;
%End

    QByteArray operator*(int m) const;
%MethodCode
        sipRes = new QByteArray();
        
        while (a0-- > 0)
            *sipRes += *sipCpp;
%End

    QByteArray &operator*=(int m);
%MethodCode
        QByteArray orig(*sipCpp);
        
        sipCpp->clear();
        
        while (a0-- > 0)
            *sipCpp += orig;
%End

    bool isEmpty() const;
    SIP_PYOBJECT data();
%MethodCode
        // QByteArrays may contain embedded '\0's so set the size explicitly.
        
        char *res = sipCpp->data();
        int len = sipCpp->size();
        
        if (res)
        {
            if ((sipRes = PyString_FromStringAndSize(res, len)) == NULL)
                sipIsErr = 1;
        }
        else
        {
            Py_INCREF(Py_None);
            sipRes = Py_None;
        }
%End

    int capacity() const;
    void reserve(int size);
    void squeeze();
    void push_back(const QByteArray &a);
    void push_front(const QByteArray &a);
    QBool contains(const QByteArray &a) const;
%If (Qt_4_3_0 -)
    QByteArray toHex() const;
%End
%If (Qt_4_4_0 -)
    QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray(), char percent = '%') const;
%End
%If (Qt_4_4_0 -)
    static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%');
%End
};

bool operator==(const QByteArray &a1, const QByteArray &a2);
bool operator!=(const QByteArray &a1, const QByteArray &a2);
bool operator<(const QByteArray &a1, const QByteArray &a2);
bool operator<=(const QByteArray &a1, const QByteArray &a2);
bool operator>(const QByteArray &a1, const QByteArray &a2);
bool operator>=(const QByteArray &a1, const QByteArray &a2);
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2);
QDataStream &operator<<(QDataStream &, const QByteArray & /Constrained/);
QDataStream &operator>>(QDataStream &, QByteArray & /Constrained/);
QByteArray qCompress(const QByteArray &data, int compressionLevel = -1);
QByteArray qUncompress(const QByteArray &data);
%If (Qt_4_3_0 -)
void qSwap(QByteArray &value1, QByteArray &value2);
%End
