/*
 * Interface wrapper code.
 *
 * Generated by SIP 4.19.16
 *
 *     Copyright: (c) 2018 by Total Control Software
 *     License:   wxWindows License
 */

#include "sipAPI_core.h"




extern "C" {static void assign_wxString(void *, SIP_SSIZE_T, void *);}
static void assign_wxString(void *sipDst, SIP_SSIZE_T sipDstIdx, void *sipSrc)
{
    reinterpret_cast< ::wxString *>(sipDst)[sipDstIdx] = *reinterpret_cast< ::wxString *>(sipSrc);
}


extern "C" {static void *array_wxString(SIP_SSIZE_T);}
static void *array_wxString(SIP_SSIZE_T sipNrElem)
{
    return new  ::wxString[sipNrElem];
}


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


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



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

        #if wxUSE_UNICODE_WCHAR == 0
        #error wxString conversion can only handle WCHAR wxStrings currently
        #endif

        // Code to test a PyObject for compatibility with wxString
        if (!sipIsErr) {
            if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy))
                return TRUE;
            return FALSE;
        }

        // Code to convert a compatible PyObject to a wxString
        PyObject* uni = sipPy;
        if (PyBytes_Check(sipPy)) {
            // if it's a string object convert it to unicode first, assuming utf-8
            uni = PyUnicode_FromEncodedObject(sipPy, "utf-8", "strict");
            if (PyErr_Occurred()) {
                *sipIsErr = 1;
                return 0;
            }
        }
        *sipCppPtr = new wxString();
        size_t len = PyUnicode_GET_SIZE(uni);
        if (len) {
            wxPyUnicode_AsWideChar(uni, wxStringBuffer(**sipCppPtr, len), len);
        }
        if (PyBytes_Check(sipPy))
            Py_DECREF(uni);  // release the temporary Unicode object we created
        return sipGetState(sipTransferObj);
}


extern "C" {static PyObject *convertFrom_wxString(void *, PyObject *);}
static PyObject *convertFrom_wxString(void *sipCppV, PyObject *)
{
    ::wxString *sipCpp = reinterpret_cast< ::wxString *>(sipCppV);

        // Convert a wxString to a Python Unicode object.  See wxpy_api.sip
        return wx2PyString(*sipCpp);
}


sipMappedTypeDef sipTypeDef__core_wxString = {
    {
        -1,
        SIP_NULLPTR,
        0,
        SIP_TYPE_MAPPED,
        sipNameNr_wxString,     /* wxString */
        {0},
        0
    },
    {
        -1,
        {0, 0, 1},
        0, 0,
        0, 0,
        0, 0,
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    assign_wxString,
    array_wxString,
    copy_wxString,
    release_wxString,
    convertTo_wxString,
    convertFrom_wxString
};
