DiSMEC++
|
Utility class used to wrap all objects we provide to python. More...
#include <binding.h>
Public Member Functions | |
template<class U > | |
PyWrapper (U &&source, std::enable_if_t< std::is_convertible_v< U &, T & >> *a=nullptr) | |
PyWrapper (std::shared_ptr< T > d) | |
T * | operator-> () |
const T * | operator-> () const |
T & | access () |
const T & | access () const |
const std::shared_ptr< T > & | ptr () const |
std::shared_ptr< T > & | ptr () |
Private Attributes | |
std::shared_ptr< T > | m_Data |
Utility class used to wrap all objects we provide to python.
T |
In order to enable shared ownership of objects between python and C++, we put them into a shared_ptr
. One option would be to specify the HolderType
in the pybind bindings to use a shared_ptr
. Instead, we have introduced this wrapper class, for the following reasons: 1) Converting constructor: The wrapper allows us to define a converting constructor that that allows us to construct the internal shared_ptr
also from a derived class. This is very convenient. 2) Null checking: This wrapper by default checks that the wrapped shared_ptr
is not nullptr
, and otherwise throws an exception. This means we generally need not worry about which access is safe (in the sense of raising an error on the python side instead of crashing the application) , and in the glue code the checks do not account for any relevant performance decrease.
|
inline |
Definition at line 48 of file binding.h.
References PyWrapper< T >::m_Data.
Referenced by PyWrapper< T >::operator->(), and PYBIND11_MODULE().
|
inline |
Definition at line 55 of file binding.h.
References PyWrapper< T >::m_Data.
|
inline |
Definition at line 40 of file binding.h.
References PyWrapper< T >::access().
|
inline |
Definition at line 44 of file binding.h.
References PyWrapper< T >::access().
|
inline |
Definition at line 66 of file binding.h.
References PyWrapper< T >::m_Data.
|
inline |
Definition at line 62 of file binding.h.
References PyWrapper< T >::m_Data.
Referenced by PYBIND11_MODULE().
|
private |
Definition at line 70 of file binding.h.
Referenced by PyWrapper< T >::access(), and PyWrapper< T >::ptr().