ShlubluLib  v0.5
ShlubluLib is a lightweight, modular, general purpose, open-source C++ library for Linux and Windows.
Python_ObjectHandler.h
Go to the documentation of this file.
1 #pragma once
2 
9 #define PY_SSIZE_T_CLEAN
10 #include <Python.h>
11 
12 
13 namespace shlublu
14 {
15 
16 namespace Python
17 {
18 
71 {
72 public:
83  class Hasher
84  {
85  public:
90  int64_t operator()(ObjectHandler const& key) const;
91  };
92 
93 
94 public:
100 
108 
115  ObjectHandler(ObjectHandler&& src) noexcept;
116 
125  ObjectHandler(PyObject* pyObj);
126 
137 
145  void swap(ObjectHandler& other) noexcept;
146 
151  PyObject* get() const;
152 
157  uint64_t id() const;
158 
166  operator PyObject* () const;
167 
168 private:
170  PyObject* mPyObj;
171  uint64_t mId;
172 
173 private:
174  uint64_t nextId();
175 
176  static uint64_t sSequence;
178 };
179 
180 
188 bool operator == (ObjectHandler const& lhs, ObjectHandler const& rhs);
189 
197 bool operator != (ObjectHandler const& lhs, ObjectHandler const& rhs);
198 
199 }
200 
201 }
202 
203 
shlublu::Python::operator!=
bool operator!=(ObjectHandler const &lhs, ObjectHandler const &rhs)
Inequality operator.
shlublu::Python::ObjectHandler
Handler of CPython object pointers used by Python to handle references counts.
Definition: Python_ObjectHandler.h:71
shlublu::Python::ObjectHandler::id
uint64_t id() const
Returns the ID of the use case represented by this handler.
shlublu::Python::ObjectHandler::Hasher
Key hasher to be used with unordered containers such as std::unordered_map or std::unordered_set.
Definition: Python_ObjectHandler.h:84
shlublu::Python::ObjectHandler::swap
void swap(ObjectHandler &other) noexcept
Exchanges two instances.
shlublu::Python::ObjectHandler::ObjectHandler
ObjectHandler(ObjectHandler const &src)
Copy constructor.
shlublu
shlublu::Python::operator==
bool operator==(ObjectHandler const &lhs, ObjectHandler const &rhs)
Equality operator.
shlublu::Python::ObjectHandler::operator=
ObjectHandler & operator=(ObjectHandler src) noexcept
Assignment operator.
shlublu::Python::ObjectHandler::ObjectHandler
ObjectHandler(ObjectHandler &&src) noexcept
Move constructor.
shlublu::Python::ObjectHandler::ObjectHandler
ObjectHandler()
Empty constructor.
shlublu::Python::ObjectHandler::ObjectHandler
ObjectHandler(PyObject *pyObj)
PyObject* constructor.
Python.h
shlublu::Python::ObjectHandler::get
PyObject * get() const
Returns the object pointer this handler encapsulates.
shlublu::Python::ObjectHandler::Hasher::operator()
int64_t operator()(ObjectHandler const &key) const
Returns the key hash of an instance of ObjectHandler.