ShlubluLib
v0.5
ShlubluLib is a lightweight, modular, general purpose, open-source C++ library for Linux and Windows.
|
Handler of CPython object pointers used by Python to handle references counts. More...
#include <Python_ObjectHandler.h>
Classes | |
class | Hasher |
Key hasher to be used with unordered containers such as std::unordered_map or std::unordered_set . More... | |
Public Member Functions | |
ObjectHandler () | |
Empty constructor. More... | |
ObjectHandler (ObjectHandler const &src) | |
Copy constructor. More... | |
ObjectHandler (ObjectHandler &&src) noexcept | |
Move constructor. More... | |
ObjectHandler (PyObject *pyObj) | |
PyObject* constructor. More... | |
ObjectHandler & | operator= (ObjectHandler src) noexcept |
Assignment operator. More... | |
void | swap (ObjectHandler &other) noexcept |
Exchanges two instances. More... | |
PyObject * | get () const |
Returns the object pointer this handler encapsulates. More... | |
uint64_t | id () const |
Returns the ID of the use case represented by this handler. More... | |
operator PyObject * () const | |
PyObject* cast operator. More... | |
Handler of CPython object pointers used by Python to handle references counts.
An instance represents a specific use of a given CPython object and is identified by an ID unique to this use case.
A given CPython object can be involved in several instances should it have several use cases at a given point of time.
Two copies of a same handler have the same object pointers and the same ID as they refer to the same use case.
ID is never zero but for empty instances.
Conversion from and to PyObject *
is silent.
Typical examples of use
shlublu::Python::ObjectHandler::ObjectHandler | ( | ) |
Empty constructor.
Sets both object pointer and ID to zero.
shlublu::Python::ObjectHandler::ObjectHandler | ( | ObjectHandler const & | src | ) |
Copy constructor.
Both object pointer and ID are copied.
src | the instance to be copied. |
|
noexcept |
Move constructor.
Both object pointer and ID are moved.
src | the instance to move in. |
shlublu::Python::ObjectHandler::ObjectHandler | ( | PyObject * | pyObj | ) |
PyObject*
constructor.
Typically used as an implicit constructor for objects returned by the CPython API. An ID is allocated automatically at creation time.
pyObj | the CPython object pointer this instance will be assigned. |
|
noexcept |
Assignment operator.
Should src
be another instance, both object pointer and ID are copied. Should src be an object pointer, this pointer is copied and an ID is allocated automatically by an implied ObjectHandler.
src | other instance or PyObject * |
*this
|
noexcept |
Exchanges two instances.
Both object pointer and ID are swaped. Should src be an object pointer, an implied ObjectHandler is created and assigned an ID.
other | other instance to swap with |
PyObject* shlublu::Python::ObjectHandler::get | ( | ) | const |
Returns the object pointer this handler encapsulates.
uint64_t shlublu::Python::ObjectHandler::id | ( | ) | const |
Returns the ID of the use case represented by this handler.
shlublu::Python::ObjectHandler::operator PyObject * | ( | ) | const |
PyObject*
cast operator.
Typically used as an implicit cast operator to pass instances of ObjectHandler to functions of the CPython API.