diff options
Diffstat (limited to 'libshiboken/basewrapper.h')
-rw-r--r-- | libshiboken/basewrapper.h | 193 |
1 files changed, 106 insertions, 87 deletions
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index f723a7a9b..aa1301dff 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -51,7 +51,7 @@ struct LIBSHIBOKEN_API SbkObject LIBSHIBOKEN_API void SbkDeallocWrapper(PyObject* pyObj); LIBSHIBOKEN_API void SbkDeallocWrapperWithPrivateDtor(PyObject* self); -struct SbkObjectType; +struct SbkBaseType; /// Function signature for the multiple inheritance information initializers that should be provided by classes with multiple inheritance. typedef int* (*MultipleInheritanceInitFunction)(const void*); @@ -61,9 +61,9 @@ typedef int* (*MultipleInheritanceInitFunction)(const void*); * part of a multiple inheritance hierarchy. * The implementation of this function is auto generated by the generator and you don't need to care about it. */ -typedef void* (*SpecialCastFunction)(void*, SbkObjectType*); +typedef void* (*SpecialCastFunction)(void*, SbkBaseType*); typedef void* (*ObjectCopierFunction)(const void*); -typedef SbkObjectType* (*TypeDiscoveryFunc)(void*, SbkObjectType*); +typedef SbkBaseType* (*TypeDiscoveryFunc)(void*, SbkBaseType*); typedef void* (*ExtendedToCppFunc)(PyObject*); typedef bool (*ExtendedIsConvertibleFunc)(PyObject*); @@ -71,34 +71,18 @@ typedef bool (*ExtendedIsConvertibleFunc)(PyObject*); // Used in userdata dealloc function typedef void (*DeleteUserDataFunc)(void*); -extern LIBSHIBOKEN_API PyTypeObject SbkObjectType_Type; -extern LIBSHIBOKEN_API SbkObjectType SbkObject_Type; +typedef void (*ObjectDestructor)(void*); +extern LIBSHIBOKEN_API PyTypeObject SbkBaseType_Type; +extern LIBSHIBOKEN_API SbkBaseType SbkObject_Type; + + +struct SbkBaseTypePrivate; /// PyTypeObject extended with C++ multiple inheritance information. -struct LIBSHIBOKEN_API SbkObjectType +struct LIBSHIBOKEN_API SbkBaseType { PyHeapTypeObject super; - int* mi_offsets; - MultipleInheritanceInitFunction mi_init; - /// Special cast function, null if this class doesn't have multiple inheritance. - SpecialCastFunction mi_specialcast; - TypeDiscoveryFunc type_discovery; - ObjectCopierFunction obj_copier; - /// Extended "isConvertible" function to be used when a conversion operator is defined in another module. - ExtendedIsConvertibleFunc ext_isconvertible; - /// Extended "toCpp" function to be used when a conversion operator is defined in another module. - ExtendedToCppFunc ext_tocpp; - /// Pointer to a function responsible for deletetion of the C++ instance calling the proper destructor. - void (*cpp_dtor)(void*); - /// True if this type holds two or more C++ instances, e.g.: a Python class which inherits from two C++ classes. - int is_multicpp:1; - /// True if this type was definied by the user. - int is_user_type:1; - /// C++ name - const char* original_name; - /// Type user data - void *user_data; - DeleteUserDataFunc d_func; + SbkBaseTypePrivate* d; }; LIBSHIBOKEN_API PyObject* SbkObjectTpNew(PyTypeObject* subtype, PyObject*, PyObject*); @@ -111,94 +95,109 @@ namespace Shiboken /** * Init shiboken library. */ -LIBSHIBOKEN_API void initShiboken(); +LIBSHIBOKEN_API void init(); -/** -* Returns true if the object is an instance of a type created by the Shiboken generator. -*/ -inline bool isShibokenType(PyObject*& pyObj) + +/// Delete the class T allocated on \p cptr. +template<typename T> +void callCppDestructor(void* cptr) { - return pyObj->ob_type->ob_type == &SbkObjectType_Type; + delete reinterpret_cast<T*>(cptr); } +LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr); +LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject* args, const char* funcName, const char** cppOverloads); + +namespace BaseType { + /** -* Returns true if this object is an instance of an user defined type derived from an Shiboken type. +* Returns true if the object is an instance of a type created by the Shiboken generator. */ -inline bool isUserType(PyObject*& pyObj) -{ - return isShibokenType(pyObj) && reinterpret_cast<SbkObjectType*>(pyObj->ob_type)->is_user_type; -} +LIBSHIBOKEN_API bool checkType(PyTypeObject* pyObj); /** - * Get/Set Userdata in type class - */ -LIBSHIBOKEN_API void setTypeUserData(SbkObject* wrapper, void* user_data, DeleteUserDataFunc d_func); -LIBSHIBOKEN_API void* getTypeUserData(SbkObject* wrapper); +* Returns true if this object is an instance of an user defined type derived from an Shiboken type. +*/ +LIBSHIBOKEN_API bool isUserType(PyTypeObject* pyObj); /** * Returns true if the constructor of \p ctorType can be called for a instance of type \p myType. * \note This function set a python error when returning false. */ -LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType); +LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType); /** - * Increments the reference count of the referred Python object. - * A previous Python object in the same position identified by the 'key' parameter - * will have its reference counter decremented automatically when replaced. - * All the kept references should be decremented when the Python wrapper indicated by - * 'self' dies. - * No checking is done for any of the passed arguments, since it is meant to be used - * by generated code it is supposed that the generator is correct. - * \param self the wrapper instance that keeps references to other objects. - * \param key a key that identifies the C++ method signature and argument where the referredObject came from. - * \parem referredObject the object whose reference is used by the self object. - */ -LIBSHIBOKEN_API void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append=false); + * Call copy function for the object type + **/ +LIBSHIBOKEN_API void* copy(SbkBaseType* self, const void *obj); +LIBSHIBOKEN_API void setCopyFunction(SbkBaseType* self, ObjectCopierFunction func); -/// Delete the class T allocated on \p cptr. -template<typename T> -void callCppDestructor(void* cptr) -{ - delete reinterpret_cast<T*>(cptr); -} +LIBSHIBOKEN_API void setExternalCppConversionFunction(SbkBaseType* self, ExtendedToCppFunc func); +LIBSHIBOKEN_API void setExternalIsConvertibleFunction(SbkBaseType* self, ExtendedIsConvertibleFunc func); +LIBSHIBOKEN_API bool hasExternalCppConversions(SbkBaseType* self); +LIBSHIBOKEN_API bool isExternalConvertible(SbkBaseType* self, PyObject* obj); +LIBSHIBOKEN_API void* callExternalCppConversion(SbkBaseType* self, PyObject* obj); + +LIBSHIBOKEN_API bool hasCast(SbkBaseType* self); +LIBSHIBOKEN_API void* cast(SbkBaseType* self, SbkObject* obj, PyTypeObject* target); +LIBSHIBOKEN_API void setCastFunction(SbkBaseType* self, SpecialCastFunction func); + +LIBSHIBOKEN_API void setOriginalName(SbkBaseType* self, const char* name); +LIBSHIBOKEN_API const char* getOriginalName(SbkBaseType* self); + +LIBSHIBOKEN_API void setTypeDiscoveryFunction(SbkBaseType* self, TypeDiscoveryFunc func); +LIBSHIBOKEN_API TypeDiscoveryFunc getTypeDiscoveryFunction(SbkBaseType* self); + +LIBSHIBOKEN_API void copyMultimpleheritance(SbkBaseType* self, SbkBaseType* other); +LIBSHIBOKEN_API void setMultipleIheritanceFunction(SbkBaseType* self, MultipleInheritanceInitFunction func); +LIBSHIBOKEN_API MultipleInheritanceInitFunction getMultipleIheritanceFunction(SbkBaseType* self); -LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr); -LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject* args, const char* funcName, const char** cppOverloads); +LIBSHIBOKEN_API void setDestructorFunction(SbkBaseType* self, ObjectDestructor func); + +LIBSHIBOKEN_API void initPrivateData(SbkBaseType* self); +} namespace Wrapper { -LIBSHIBOKEN_API PyObject* newObject(SbkObjectType* instanceType, - void* cptr, - bool hasOwnership = true, - bool isExactType = false, - const char* typeName = 0); +/** +* Returns true if the object is an instance of a type created by the Shiboken generator. +*/ +LIBSHIBOKEN_API bool checkType(PyObject* pyObj); +LIBSHIBOKEN_API bool isUserType(PyObject* pyObj); + -LIBSHIBOKEN_API void setValidCpp(SbkObject* pyObj, bool value); -LIBSHIBOKEN_API void setHasCppWrapper(SbkObject* pyObj, bool value); -LIBSHIBOKEN_API bool hasCppWrapper(SbkObject* pyObj); +LIBSHIBOKEN_API PyObject* newObject(SbkBaseType* instanceType, + void* cptr, + bool hasOwnership = true, + bool isExactType = false, + const char* typeName = 0); -LIBSHIBOKEN_API bool hasOwnership(SbkObject* pyObj); -LIBSHIBOKEN_API void getOwnership(PyObject* pyObj); -LIBSHIBOKEN_API void getOwnership(SbkObject* pyObj); -LIBSHIBOKEN_API void releaseOwnership(PyObject* pyObj); -LIBSHIBOKEN_API void releaseOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API void setValidCpp(SbkObject* pyObj, bool value); +LIBSHIBOKEN_API void setHasCppWrapper(SbkObject* pyObj, bool value); +LIBSHIBOKEN_API bool hasCppWrapper(SbkObject* pyObj); -LIBSHIBOKEN_API bool hasParentInfo(SbkObject* pyObj); +LIBSHIBOKEN_API bool hasOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API void getOwnership(PyObject* pyObj); +LIBSHIBOKEN_API void getOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API void releaseOwnership(PyObject* pyObj); +LIBSHIBOKEN_API void releaseOwnership(SbkObject* pyObj); + +LIBSHIBOKEN_API bool hasParentInfo(SbkObject* pyObj); /** * Get the C++ pointer of type \p desiredType from a Python object. */ -LIBSHIBOKEN_API void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType); +LIBSHIBOKEN_API void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType); /** * Set the C++ pointer of type \p desiredType of a Python object. */ -LIBSHIBOKEN_API bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr); +LIBSHIBOKEN_API bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr); /** * Returns false and sets a Python RuntimeError if the Python wrapper is not marked as valid. */ -LIBSHIBOKEN_API bool isValid(PyObject* wrapper); +LIBSHIBOKEN_API bool isValid(PyObject* wrapper); /** * Set the parent of \p child to \p parent. @@ -206,39 +205,59 @@ LIBSHIBOKEN_API bool isValid(PyObject* wrapper); * \param parent the parent object, if null, the child will have no parents. * \param child the child. */ -LIBSHIBOKEN_API void setParent(PyObject* parent, PyObject* child); +LIBSHIBOKEN_API void setParent(PyObject* parent, PyObject* child); /** * Remove this child from their parent, if any. * \param child the child. */ -LIBSHIBOKEN_API void removeParent(SbkObject* child, bool giveOwnershipBack = true, bool keepReferenc = false); +LIBSHIBOKEN_API void removeParent(SbkObject* child, bool giveOwnershipBack = true, bool keepReferenc = false); /** * \internal This is an internal function called by SbkBaseWrapper_Dealloc, it's exported just for techinical reasons. * \note Do not call this function inside your bindings. */ -LIBSHIBOKEN_API void destroyParentInfo(SbkObject* obj, bool removeFromParent = true); +LIBSHIBOKEN_API void destroyParentInfo(SbkObject* obj, bool removeFromParent = true); /** * Mark the object as invalid */ -LIBSHIBOKEN_API void invalidate(SbkObject* self); +LIBSHIBOKEN_API void invalidate(SbkObject* self); /** * Help function can be used to invalida a sequence of object **/ -LIBSHIBOKEN_API void invalidate(PyObject* pyobj); +LIBSHIBOKEN_API void invalidate(PyObject* pyobj); /** * Make the object valid again */ -LIBSHIBOKEN_API void makeValid(SbkObject* self); +LIBSHIBOKEN_API void makeValid(SbkObject* self); /** * Destroy any data in Shiboken structure and c++ pointer if the pyboject has the ownership **/ -LIBSHIBOKEN_API void destroy(SbkObject* self); +LIBSHIBOKEN_API void destroy(SbkObject* self); + +/** + * Get/Set Userdata in type class + */ +LIBSHIBOKEN_API void setTypeUserData(SbkObject* wrapper, void* user_data, DeleteUserDataFunc d_func); +LIBSHIBOKEN_API void* getTypeUserData(SbkObject* wrapper); + +/** + * Increments the reference count of the referred Python object. + * A previous Python object in the same position identified by the 'key' parameter + * will have its reference counter decremented automatically when replaced. + * All the kept references should be decremented when the Python wrapper indicated by + * 'self' dies. + * No checking is done for any of the passed arguments, since it is meant to be used + * by generated code it is supposed that the generator is correct. + * \param self the wrapper instance that keeps references to other objects. + * \param key a key that identifies the C++ method signature and argument where the referredObject came from. + * \parem referredObject the object whose reference is used by the self object. + */ +LIBSHIBOKEN_API void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append=false); } // namespace Wrapper |