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

#include "sipAPI_core.h"




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


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


extern "C" {static void *copy_wxString(const void *, Py_ssize_t);}
static void *copy_wxString(const void *sipSrc, Py_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 *sipCppV, int)
{
    ::wxString *sipCpp = reinterpret_cast< ::wxString *>(sipCppV);
    Py_BEGIN_ALLOW_THREADS
    delete sipCpp;
    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_AsWideChar(uni, NULL, 0);
        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,
        SIP_NULLPTR,
        SIP_TYPE_MAPPED,
        sipNameNr_wxString,
        SIP_NULLPTR,
        SIP_NULLPTR,
    },
    {
        -1,
        {0, 0, 1},
        0, SIP_NULLPTR,
        0, SIP_NULLPTR,
        0, SIP_NULLPTR,
        {SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR}
    },
    assign_wxString,
    array_wxString,
    copy_wxString,
    release_wxString,
    convertTo_wxString,
    convertFrom_wxString
};
