diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-09-05 13:41:43 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-11-02 12:04:19 +0000 |
commit | 8c9037dc83fbdbb0b9913961fbe7f84066630e18 (patch) | |
tree | c68ca10add975adf4dadf669ea5a96b9c5c0f07d /sources/shiboken2/libshiboken/sbkconverter.h | |
parent | e30e0c161b2b4d50484314bf006e9e5e8ff6b380 (diff) |
Remove dead / unused code regarding conversions
There's a lot of code that was previously used for doing conversions
between C++ / Python types (apparently relying on extensive
RTTI / typeid manipulations), which got superseded by a cleaner
templated approach.
The old code was left behind, and there were a few instances where it
was still used even though it wasn't needed, like in QtScript
typesystem XML and shiboken's enum handling.
Remove the old code, apply the small changes needed to make it work
with new the code.
This is cleanup to reduce the confusion regarding conversion
behavior, and also preparation for a proper implementation of handling
"void*" types.
Change-Id: I8f16bb31436f9a677bb2d64c7197c4375005b656
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken/sbkconverter.h')
-rw-r--r-- | sources/shiboken2/libshiboken/sbkconverter.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/sbkconverter.h b/sources/shiboken2/libshiboken/sbkconverter.h index 7489b930d..7eb666b25 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.h +++ b/sources/shiboken2/libshiboken/sbkconverter.h @@ -358,7 +358,38 @@ template<> inline SbkConverter* PrimitiveTypeConverter<unsigned long>() { return template<> inline SbkConverter* PrimitiveTypeConverter<unsigned short>() { return primitiveTypeConverter(SBK_UNSIGNEDSHORT_IDX); } template<> inline SbkConverter* PrimitiveTypeConverter<void*>() { return primitiveTypeConverter(SBK_VOIDPTR_IDX); } -} } // namespace Shiboken::Conversions +} // namespace Shiboken::Conversions + +/** +* This function template is used to get the PyTypeObject of a C++ type T. +* All implementations should be provided by template specializations generated by the generator when +* T isn't a C++ primitive type. +* \see SpecialCastFunction +*/ +template<typename T> PyTypeObject* SbkType() { return 0; } + +// Below are the template specializations for C++ primitive types. +template<> inline PyTypeObject* SbkType<PY_LONG_LONG>() { return &PyLong_Type; } +template<> inline PyTypeObject* SbkType<bool>() { return &PyBool_Type; } +template<> inline PyTypeObject* SbkType<char>() { return &PyInt_Type; } +template<> inline PyTypeObject* SbkType<double>() { return &PyFloat_Type; } +template<> inline PyTypeObject* SbkType<float>() { return &PyFloat_Type; } +template<> inline PyTypeObject* SbkType<int>() { return &PyInt_Type; } +template<> inline PyTypeObject* SbkType<long>() { return &PyLong_Type; } +template<> inline PyTypeObject* SbkType<short>() { return &PyInt_Type; } +template<> inline PyTypeObject* SbkType<signed char>() { return &PyInt_Type; } +template<> inline PyTypeObject* SbkType<unsigned PY_LONG_LONG>() { return &PyLong_Type; } +template<> inline PyTypeObject* SbkType<unsigned char>() { return &PyInt_Type; } +template<> inline PyTypeObject* SbkType<unsigned int>() { return &PyLong_Type; } +template<> inline PyTypeObject* SbkType<unsigned long>() { return &PyLong_Type; } +template<> inline PyTypeObject* SbkType<unsigned short>() { return &PyInt_Type; } + +} // namespace Shiboken + +// When the user adds a function with an argument unknown for the typesystem, the generator writes type checks as +// TYPENAME_Check, so this macro allows users to add PyObject arguments to their added functions. +#define PyObject_Check(X) true +#define SbkChar_Check(X) (SbkNumber_Check(X) || Shiboken::String::checkChar(X)) struct _SbkGenericType { PyHeapTypeObject super; SbkConverter** converter; }; #define SBK_CONVERTER(pyType) (*reinterpret_cast<_SbkGenericType*>(pyType)->converter) |