Shiboken::Object Namespace
namespace Shiboken::ObjectNamespace for object instance related things. More...
| Header: | #include <basewrapper.h> |
Functions
| void | callCppDestructors(SbkObject *pyObj) |
| bool | checkType(PyObject *pyObj) |
| void * | cppPointer(SbkObject *pyObj) |
| void * | cppPointer(SbkObject *pyObj, PyTypeObject *desiredType) |
| std::vector<void *> | cppPointers(SbkObject *pyObj) |
| void | destroy(SbkObject *self, void *cppData) |
| std::string | dumpTree(SbkObject *self) |
| SbkObject * | findColocatedChild(SbkObject *wrapper, const PyTypeObject *instanceType) |
| void | getOwnership(PyObject *pyObj) |
| void | getOwnership(SbkObject *sbkObj) |
| void * | getTypeUserData(SbkObject *wrapper) |
| bool | hasCppWrapper(SbkObject *pyObj) |
| bool | hasOwnership(SbkObject *pyObj) |
| Py_hash_t | hash(PyObject *pyObj) |
| std::string | info(SbkObject *self) |
| void | invalidate(PyObject *pyobj) |
| void | invalidate(SbkObject *self) |
| bool | isUserType(PyObject *pyObj) |
| bool | isValid(PyObject *pyObj) |
| bool | isValid(SbkObject *pyObj, bool throwPyError = true) |
| bool | isValid(PyObject *pyObj, bool throwPyError) |
| void | keepReference(SbkObject *self, const char *keyC, PyObject *referredObject, bool append = false) |
| void | makeValid(SbkObject *self) |
| PyObject * | newObject(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, bool isExactType = false, const char *typeName = nullptr) |
| PyObject * | newObjectForPointer(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, const char *typeName = nullptr) |
| PyObject * | newObjectForType(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true) |
| PyObject * | newObjectWithHeuristics(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, const char *typeName = nullptr) |
| void | releaseOwnership(PyObject *pyObj) |
| void | releaseOwnership(SbkObject *sbkObj) |
| void | removeParent(SbkObject *child, bool giveOwnershipBack = true, bool keepReference = false) |
| void | removeReference(SbkObject *self, const char *key, PyObject *referredObject) |
| bool | setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) |
| void | setHasCppWrapper(SbkObject *pyObj, bool value) |
| void | setParent(PyObject *parent, PyObject *child) |
| void | setParentReturnValueHeuristics(PyObject *parent, PyObject *child) |
| void | setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func) |
| void | setValidCpp(SbkObject *pyObj, bool value) |
| bool | wasCreatedByPython(SbkObject *pyObj) |
Detailed Description
Function Documentation
void Object::callCppDestructors(SbkObject *pyObj)
Calls the C++ object destructor and invalidates the Python object pyObj.
Note: This function was added to libshiboken only to be used by shiboken.delete()
bool Object::checkType(PyObject *pyObj)
Returns true if the object pyObj is an instance of a type created by the Shiboken generator.
void *Object::cppPointer(SbkObject *pyObj)
Get the C++ pointer from the Python object pyObj.
See also setCppPointer().
void *Object::cppPointer(SbkObject *pyObj, PyTypeObject *desiredType)
Get the C++ pointer of type desiredType from the Python object pyObj.
std::vector<void *> Object::cppPointers(SbkObject *pyObj)
Return a list with all C++ pointers held from the Python object pyObj.
Note: This function was added to libshiboken only to be used by shiboken.getCppPointer()
void Object::destroy(SbkObject *self, void *cppData)
Destroys any data in the Shiboken structure of self and the C++ pointer cppData if the Python object has the ownership.
std::string Object::dumpTree(SbkObject *self)
Like info(), but creates a dump of the entire object tree starting from self.
SbkObject *Object::findColocatedChild(SbkObject *wrapper, const PyTypeObject *instanceType)
Finds a child of the given wrapper having the same address and the type instanceType.
void Object::getOwnership(PyObject *pyObj)
Sets python as responsible to delete the underlying C++ object of pyObj.
Note: Use this overload only when the PyObject can be a sequence and you want to call this function for every item in the sequence.
See also getOwnership(SbkObject *).
void Object::getOwnership(SbkObject *sbkObj)
Sets python as responsible to delete the underlying C++ object of sbkObj.
void *Object::getTypeUserData(SbkObject *wrapper)
Returns the user data of the type of wrapper previously set by Shiboken::Object::setTypeUserData().
bool Object::hasCppWrapper(SbkObject *pyObj)
Return true if the Python object pyObj has a C++ wrapper used to intercept virtual method calls.
See also setHasCppWrapper().
bool Object::hasOwnership(SbkObject *pyObj)
Return true if Python is responsible for deleting the underlying C++ object of pyObj.
Py_hash_t Object::hash(PyObject *pyObj)
Generic function used to make ObjectType hashable; the C++ pointer of pyObj is used as hash value.
std::string Object::info(SbkObject *self)
Returns a string with information about the internal state of the instance object self, useful for debug purposes.
void Object::invalidate(PyObject *pyobj)
Helper function that can be used to invalidate a sequence of objects pyobj.
void Object::invalidate(SbkObject *self)
Marks the object self as invalid.
bool Object::isUserType(PyObject *pyObj)
Returns true if the type of the object pyObj is a user-defined type derived from a Shiboken type.
bool Object::isValid(PyObject *pyObj)
Returns false and sets a Python RuntimeError if the Python wrapper of pyObj is not marked as valid.
bool Object::isValid(SbkObject *pyObj, bool throwPyError = true)
Returns false if the Python wrapper of pyObj is not marked as valid. If throwPyError is true, a Python RuntimeError is set when the object isn't valid.
bool Object::isValid(PyObject *pyObj, bool throwPyError)
Returns false if the Python wrapper of pyObj is not marked as valid. If throwPyError is true, a Python RuntimeError is set when the object isn't valid.
This is an overloaded function.
void Object::keepReference(SbkObject *self, const char *keyC, PyObject *referredObject, bool append = false)
Increments the reference count of the referred Python object. A previous Python object in the same position identified by keyC will have its reference counter decremented automatically when replaced unless append is true. 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.
| Parameter | Meaning |
|---|---|
| self | The wrapper instance that keeps references to other objects. |
| keyC | A key that identifies the C++ method signature and argument where the referred object came from. |
| referredObject | The object whose reference is used by the self object. |
| append | If true, referredObject is appended to the list of references kept under keyC instead of replacing them. |
void Object::makeValid(SbkObject *self)
Makes the object self valid again.
PyObject *Object::newObject(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, bool isExactType = false, const char *typeName = nullptr)
Bind a C++ object to Python. Forwards to newObjectWithHeuristics(), newObjectForType() depending on isExactType.
| Parameter | Meaning |
|---|---|
| instanceType | equivalent Python type for the C++ object. |
| cptr | C++ instance. |
| hasOwnership | If true, Python will try to delete the underlying C++ object when there are no more references. |
| isExactType | If false, Shiboken will use some heuristics to detect the correct Python type of this C++ object. In any case, instanceType must be provided; it'll be used as search starting point and as fallback. |
| typeName | If non-null, this will be used as helper to find the correct Python type for this object. |
PyObject *Object::newObjectForPointer(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, const char *typeName = nullptr)
Bind a C++ object to Python for polymorphic pointers. Calls newObjectWithHeuristics() with an additional check for multiple inheritance, in which case it will fall back to instanceType.
| Parameter | Meaning |
|---|---|
| instanceType | Equivalent Python type for the C++ object. |
| cptr | C++ instance. |
| hasOwnership | If true, Python will try to delete the underlying C++ object when there are no more references. |
| typeName | If non-null, this will be used as helper to find the correct Python type for this object (obtained by typeid().name()). |
PyObject *Object::newObjectForType(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true)
Bind a C++ object to Python using the given type.
| Parameter | Meaning |
|---|---|
| instanceType | Equivalent Python type for the C++ object. |
| cptr | C++ instance. |
| hasOwnership | If true, Python will try to delete the underlying C++ object when there are no more references. |
PyObject *Object::newObjectWithHeuristics(PyTypeObject *instanceType, void *cptr, bool hasOwnership = true, const char *typeName = nullptr)
Bind a C++ object to Python using some heuristics to detect the correct Python type of this C++ object. In any case instanceType must be provided; it'll be used as search starting point and as fallback.
| Parameter | Meaning |
|---|---|
| instanceType | Equivalent Python type for the C++ object. |
| cptr | C++ instance. |
| hasOwnership | If true, Python will try to delete the underlying C++ object when there are no more references. |
| typeName | If non-null, this will be used as helper to find the correct Python type for this object (obtained by typeid().name()). |
void Object::releaseOwnership(PyObject *pyObj)
Release the ownership, so Python will not delete the underlying C++ object of pyObj.
Note: Use this overload only when the PyObject can be a sequence and you want to call this function for every item in the sequence.
See also releaseOwnership(SbkObject *).
void Object::releaseOwnership(SbkObject *sbkObj)
Release the ownership, so Python will not delete the underlying C++ object of sbkObj.
void Object::removeParent(SbkObject *child, bool giveOwnershipBack = true, bool keepReference = false)
Removes child from its parent, if any. If giveOwnershipBack is true, Python takes the ownership of child. If keepReference is true, the reference to child is kept.
void Object::removeReference(SbkObject *self, const char *key, PyObject *referredObject)
Removes any reference previously added by keepReference().
| Parameter | Meaning |
|---|---|
| self | The wrapper instance that keeps references to other objects. |
| key | A key that identifies the C++ method signature and argument where the referred object came from. |
| referredObject | The object whose reference is used by the self object. |
bool Object::setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr)
Sets the C++ pointer of type desiredType of the Python object sbkObj to cptr. Returns true on success, false if the pointer was already set or desiredType is not in the class hierarchy.
See also cppPointer().
void Object::setHasCppWrapper(SbkObject *pyObj, bool value)
Tells shiboken whether the Python object pyObj has a C++ wrapper used to intercept virtual method calls (value).
See also hasCppWrapper().
void Object::setParent(PyObject *parent, PyObject *child)
Sets the parent of child to parent. If parent is null, child will have no parent. When an object dies, all its children, grandchildren, etc, are tagged as invalid.
void Object::setParentReturnValueHeuristics(PyObject *parent, PyObject *child)
Like setParent(), but for use by the generator heuristics. It will not change an existing parent.
See also setParent().
void Object::setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func)
Sets the user data userData on the type of the instance object wrapper. d_func is a function used to delete the user data.
void Object::setValidCpp(SbkObject *pyObj, bool value)
Changes the valid flag of a PyObject pyObj to value; invalid objects will raise an exception when someone tries to access it.
bool Object::wasCreatedByPython(SbkObject *pyObj)
Return true if the Python object pyObj was created by Python, false otherwise.