updated custom conversions to use Converter<T>::isConvertible properly
This commit is contained in:
parent
7c0aea7c45
commit
9c0e56b598
6 changed files with 16 additions and 16 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
template <typename qhash>
|
template <typename qhash>
|
||||||
struct Converter_qhash
|
struct Converter_qhash
|
||||||
{
|
{
|
||||||
static bool isConvertible(const PyObject* pyObj) {
|
static bool isConvertible(PyObject* pyObj) {
|
||||||
return PyDict_Check(const_cast<PyObject*>(pyObj));
|
return PyDict_Check(pyObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* toPython(qhash hash)
|
static PyObject* toPython(qhash hash)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
template <typename qlist>
|
template <typename qlist>
|
||||||
struct Converter_qlist
|
struct Converter_qlist
|
||||||
{
|
{
|
||||||
static bool isConvertible(const PyObject* pyObj) {
|
static bool isConvertible(PyObject* pyObj) {
|
||||||
return PySequence_Check(const_cast<PyObject*>(pyObj));
|
return PySequence_Check(pyObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* toPython(const qlist holder)
|
static PyObject* toPython(qlist holder)
|
||||||
{
|
{
|
||||||
PyObject* result = PyList_New(holder.size());
|
PyObject* result = PyList_New(holder.size());
|
||||||
for (int i = 0; i < holder.size(); i++) {
|
for (int i = 0; i < holder.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
template <typename qmap>
|
template <typename qmap>
|
||||||
struct Converter_qmap
|
struct Converter_qmap
|
||||||
{
|
{
|
||||||
static bool isConvertible(const PyObject* pyObj) {
|
static bool isConvertible(PyObject* pyObj) {
|
||||||
return PyDict_Check(const_cast<PyObject*>(pyObj));
|
return PyDict_Check(pyObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* toPython(qmap map)
|
static PyObject* toPython(qmap map)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
template <typename qpair>
|
template <typename qpair>
|
||||||
struct Converter_qpair
|
struct Converter_qpair
|
||||||
{
|
{
|
||||||
static bool isConvertible(const PyObject* pyObj) {
|
static bool isConvertible(PyObject* pyObj) {
|
||||||
return PySequence_Check(const_cast<PyObject*>(pyObj));
|
return PySequence_Check(pyObj);
|
||||||
}
|
}
|
||||||
static PyObject* toPython(qpair holder)
|
static PyObject* toPython(qpair holder)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
inline bool Converter< QString >::isConvertible(const PyObject* pyObj)
|
inline bool Converter< QString >::isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
return PyObject_TypeCheck(pyObj, &PyQString_Type) || PyUnicode_Check(pyObj) || PyString_Check(pyObj);
|
return PyObject_TypeCheck(pyObj, &PyQString_Type) || PyUnicode_Check(pyObj) || PyString_Check(pyObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PyObject* Converter< QString >::toPython(const QString cppobj)
|
inline PyObject* Converter< QString >::toPython(QString cppobj)
|
||||||
{
|
{
|
||||||
PyObject* pyobj;
|
PyObject* pyobj;
|
||||||
void* holder = (void*) new QString(cppobj);
|
void* holder = (void*) new QString(cppobj);
|
||||||
|
|
@ -13,11 +13,11 @@ inline PyObject* Converter< QString >::toPython(const QString cppobj)
|
||||||
|
|
||||||
inline QString Converter< QString >::toCpp(PyObject* pyobj)
|
inline QString Converter< QString >::toCpp(PyObject* pyobj)
|
||||||
{
|
{
|
||||||
if (Converter<QChar>::isConvertible(pyobj)) {
|
if (PyQChar_Check(pyobj)) {
|
||||||
return QString(Converter< QChar >::toCpp(pyobj));
|
return QString(Converter< QChar >::toCpp(pyobj));
|
||||||
} else if (Converter<QByteArray>::isConvertible(pyobj)) {
|
} else if (PyQByteArray_Check(pyobj)) {
|
||||||
return QString(Converter< QByteArray >::toCpp(pyobj));
|
return QString(Converter< QByteArray >::toCpp(pyobj));
|
||||||
} else if (Converter<QLatin1String>::isConvertible(pyobj)) {
|
} else if (PyQLatin1String_Check(pyobj)) {
|
||||||
return QString(Converter< QLatin1String >::toCpp(pyobj));
|
return QString(Converter< QLatin1String >::toCpp(pyobj));
|
||||||
} else if (PyUnicode_Check(pyobj)) {
|
} else if (PyUnicode_Check(pyobj)) {
|
||||||
#if defined(Py_UNICODE_WIDE)
|
#if defined(Py_UNICODE_WIDE)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
template <typename qvector>
|
template <typename qvector>
|
||||||
struct Converter_qvector
|
struct Converter_qvector
|
||||||
{
|
{
|
||||||
static bool isConvertible(const PyObject* pyObj) {
|
static bool isConvertible(PyObject* pyObj) {
|
||||||
return PySequence_Check(const_cast<PyObject*>(pyObj));
|
return PySequence_Check(pyObj);
|
||||||
}
|
}
|
||||||
static PyObject* toPython(qvector vector)
|
static PyObject* toPython(qvector vector)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue