aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/qstring_conversions.h
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.lima@openbossa.org>2010-06-03 15:34:17 -0300
committerHugo Parente Lima <hugo.lima@openbossa.org>2010-06-10 14:57:41 -0300
commite39bfefde9edda662f51eeaf9a482f209c7f1217 (patch)
treea4add52f8ca3460fcaed99c6d9c7fc810f341a49 /PySide/QtCore/qstring_conversions.h
parent24a944590663582df72aefd1929ec19ba3c6414f (diff)
Remove wrapper for classes: QString, QStringRef, QLatin1String, QStringMatcher, QChar and QLatin1Char.
Diffstat (limited to 'PySide/QtCore/qstring_conversions.h')
-rw-r--r--PySide/QtCore/qstring_conversions.h124
1 files changed, 61 insertions, 63 deletions
diff --git a/PySide/QtCore/qstring_conversions.h b/PySide/QtCore/qstring_conversions.h
index 2c59928dd..392f0e7b7 100644
--- a/PySide/QtCore/qstring_conversions.h
+++ b/PySide/QtCore/qstring_conversions.h
@@ -1,72 +1,70 @@
namespace Shiboken {
-inline bool Converter<QString>::isConvertible(PyObject* pyObj)
-{
- SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QString>());
- return PyString_Check(pyObj)
- || PyObject_TypeCheck(pyObj, SbkType<QString>())
- || PyUnicode_Check(pyObj)
- || SbkQByteArray_Check(pyObj)
- || SbkQLatin1String_Check(pyObj)
- || pyObj == Py_None
-#if PY_VERSION_HEX < 0x03000000
- || (pyObj->ob_type->tp_as_buffer
- && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
- && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer)
-#endif
- || SbkQChar_Check(pyObj)
- || (shiboType->ext_isconvertible && shiboType->ext_isconvertible(pyObj));
-}
-inline QString Converter<QString>::toCpp(PyObject* pyObj)
+template<>
+class Converter<QString>
{
- SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QString>());
- if (SbkQChar_Check(pyObj)) {
- return QString(Converter< QChar >::toCpp(pyObj));
- } else if (SbkQByteArray_Check(pyObj)) {
- return QString(Converter< QByteArray >::toCpp(pyObj));
- } else if (SbkQLatin1String_Check(pyObj)) {
- return QString(Converter< QLatin1String >::toCpp(pyObj));
- } else if (PyUnicode_Check(pyObj)) {
- Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj);
-#if defined(Py_UNICODE_WIDE)
- // cast as Py_UNICODE can be a different type
- return QString::fromUcs4(reinterpret_cast<const uint*>(unicode));
-#else
- return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj));
-#endif
- } else if (PyString_Check(pyObj)) {
- return QString(Converter< char * >::toCpp(pyObj));
- } else if (pyObj == Py_None) {
- return QString();
+public:
+ static bool isConvertible(PyObject* pyObj)
+ {
+ return PyString_Check(pyObj)
+ || PyUnicode_Check(pyObj)
+ || SbkQByteArray_Check(pyObj)
+ || pyObj == Py_None
+ #if PY_VERSION_HEX < 0x03000000
+ || (pyObj->ob_type->tp_as_buffer
+ && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
+ && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer)
+ #endif
+ ;
}
+
+ static QString toCpp(PyObject* pyObj)
+ {
+ if (PyUnicode_Check(pyObj)) {
+ Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj);
+ #if defined(Py_UNICODE_WIDE)
+ // cast as Py_UNICODE can be a different type
+ return QString::fromUcs4(reinterpret_cast<const uint*>(unicode));
+ #else
+ return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj));
+ #endif
+ } else if (PyString_Check(pyObj)) {
+ return QString(Converter< char * >::toCpp(pyObj));
+ } else if (pyObj == Py_None) {
+ return QString();
+ } else if (SbkQByteArray_Check(pyObj)) {
+ return QString(Converter< QByteArray >::toCpp(pyObj));
+ }
#if PY_VERSION_HEX < 0x03000000
- // Support for buffer objects on QString constructor
- else if (pyObj->ob_type->tp_as_buffer
- && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
- && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) {
- QByteArray data;
- PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer;
- int segments = bufferProcs->bf_getsegcount(pyObj, 0);
- for (int i = 0; i < segments; ++i) {
- char* segmentData;
- int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData);
- if (length == -1)
- break;
- data.append(segmentData, length);
+ // Support for buffer objects on QString constructor
+ else if (pyObj->ob_type->tp_as_buffer
+ && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER)
+ && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) {
+ QByteArray data;
+ PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer;
+ int segments = bufferProcs->bf_getsegcount(pyObj, 0);
+ for (int i = 0; i < segments; ++i) {
+ char* segmentData;
+ int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData);
+ if (length == -1)
+ break;
+ data.append(segmentData, length);
+ }
+ return QString(data);
}
- return QString(data);
- }
-#endif
- else if (shiboType->ext_isconvertible && shiboType->ext_tocpp && shiboType->ext_isconvertible(pyObj)) {
- QString* cptr = reinterpret_cast<QString*>(shiboType->ext_tocpp(pyObj));
- std::auto_ptr<QString> cptr_auto_ptr(cptr);
- return *cptr;
+ #endif
+ return QString();
}
- return *Converter<QString*>::toCpp(pyObj);
-}
-inline PyObject* Converter<QString>::toPython(const QString& cppObj)
-{
- return ValueTypeConverter<QString>::toPython(cppObj);
-}
+ static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast<QString*>(cppObj)); }
+ static PyObject* toPython(const QString& cppObj)
+ {
+ const int N = cppObj.length();
+ wchar_t* str = new wchar_t[N];
+ cppObj.toWCharArray(str);
+ PyObject* pyObj = PyUnicode_FromWideChar(str, N);
+ delete[] str;
+ return pyObj;
+ }
+};
}