diff options
author | Renato Araujo Oliveira Filho <renato.filho@openbossa.org> | 2010-11-19 14:30:22 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:08:59 -0300 |
commit | 00924f871f1ed0511078157b5c37072d15621b3a (patch) | |
tree | 33d46c782be341318691cff84a02afb91f2c0c15 /libshiboken/conversions.h | |
parent | 7e98252ba8e0d2fc72fc569b3ceb82662297ac9d (diff) |
Created private pointer for Shiboken Meta Type.
Renamed ObjectType to BaseType.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Hugo Parente Lima <hugo.pl@gmail.com>
Diffstat (limited to 'libshiboken/conversions.h')
-rw-r--r-- | libshiboken/conversions.h | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h index 4d55ef0fe..d6a3dd5ee 100644 --- a/libshiboken/conversions.h +++ b/libshiboken/conversions.h @@ -99,7 +99,7 @@ struct CppObjectCopier<T, true> { static inline T* copy(const T& obj) { - return reinterpret_cast<T*>(reinterpret_cast<SbkObjectType*>(SbkType<T>())->obj_copier(&obj)); + return reinterpret_cast<T*>(BaseType::copy(reinterpret_cast<SbkBaseType*>(SbkType<T>()), &obj)); } }; @@ -113,7 +113,7 @@ inline PyObject* createWrapper(const T* cppobj, bool hasOwnership = false, bool const char* typeName = 0; if (!isExactType) typeName = typeid(*const_cast<T*>(cppobj)).name(); - return Wrapper::newObject(reinterpret_cast<SbkObjectType*>(SbkType<T>()), + return Wrapper::newObject(reinterpret_cast<SbkBaseType*>(SbkType<T>()), const_cast<T*>(cppobj), hasOwnership, isExactType, typeName); } @@ -213,10 +213,8 @@ struct ValueTypeConverter { if (PyObject_TypeCheck(pyobj, SbkType<T>())) return true; - SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType<T>()); - if (shiboType->ext_isconvertible) - return shiboType->ext_isconvertible(pyobj); - return false; + SbkBaseType* shiboType = reinterpret_cast<SbkBaseType*>(SbkType<T>()); + return BaseType::isExternalConvertible(shiboType, pyobj); } static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast<T*>(cppobj)); } static inline PyObject* toPython(const T& cppobj) @@ -233,9 +231,9 @@ struct ValueTypeConverter static inline T toCpp(PyObject* pyobj) { if (!PyObject_TypeCheck(pyobj, SbkType<T>())) { - SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType<T>()); - if (shiboType->ext_tocpp && isConvertible(pyobj)) { - T* cptr = reinterpret_cast<T*>(shiboType->ext_tocpp(pyobj)); + SbkBaseType* shiboType = reinterpret_cast<SbkBaseType*>(SbkType<T>()); + if (BaseType::hasExternalCppConversions(shiboType) && isConvertible(pyobj)) { + T* cptr = reinterpret_cast<T*>(BaseType::callExternalCppConversion(shiboType, pyobj)); std::auto_ptr<T> cptr_auto_ptr(cptr); return *cptr; } @@ -273,11 +271,9 @@ struct ObjectTypeConverter { if (pyobj == Py_None) return 0; - SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(pyobj->ob_type); - if (shiboType->mi_specialcast) - return (T*) shiboType->mi_specialcast( - Wrapper::cppPointer(reinterpret_cast<SbkObject*>(pyobj), SbkType<T>()), - reinterpret_cast<SbkObjectType*>(SbkType<T>())); + SbkBaseType* shiboType = reinterpret_cast<SbkBaseType*>(pyobj->ob_type); + if (BaseType::hasCast(shiboType)) + return reinterpret_cast<T*>(BaseType::cast(shiboType, reinterpret_cast<SbkObject*>(pyobj), SbkType<T>())); return (T*) Wrapper::cppPointer(reinterpret_cast<SbkObject*>(pyobj), SbkType<T>()); } }; @@ -564,7 +560,7 @@ struct StdListConverter // binded types implementing sequence protocol, otherwise this will // cause a mess like QBitArray being accepted by someone expecting a // QStringList. - if ((SbkType<StdList>() && isShibokenType(pyObj)) || !PySequence_Check(pyObj)) + if ((SbkType<StdList>() && Wrapper::checkType(pyObj)) || !PySequence_Check(pyObj)) return false; for (int i = 0, max = PySequence_Length(pyObj); i < max; ++i) { AutoDecRef item(PySequence_GetItem(pyObj, i)); @@ -610,7 +606,7 @@ struct StdPairConverter { if (PyObject_TypeCheck(pyObj, SbkType<StdPair>())) return true; - if ((SbkType<StdPair>() && isShibokenType(pyObj)) || !PySequence_Check(pyObj) || PySequence_Length(pyObj) != 2) + if ((SbkType<StdPair>() && Wrapper::checkType(pyObj)) || !PySequence_Check(pyObj) || PySequence_Length(pyObj) != 2) return false; AutoDecRef item1(PySequence_GetItem(pyObj, 0)); @@ -655,7 +651,7 @@ struct StdMapConverter { if (PyObject_TypeCheck(pyObj, SbkType<StdMap>())) return true; - if ((SbkType<StdMap>() && isShibokenType(pyObj)) || !PyDict_Check(pyObj)) + if ((SbkType<StdMap>() && Wrapper::checkType(pyObj)) || !PyDict_Check(pyObj)) return false; PyObject* key; |