updated custom conversions to use Converter<T>::isConvertible properly

This commit is contained in:
Marcelo Lira 2009-10-28 17:54:22 -03:00
commit 9c0e56b598
6 changed files with 16 additions and 16 deletions

View file

@ -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)

View file

@ -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++) {

View file

@ -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)

View file

@ -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)
{ {

View file

@ -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)

View file

@ -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)
{ {