7 #ifndef PXR_BASE_TF_PY_IDENTITY_H
8 #define PXR_BASE_TF_PY_IDENTITY_H
23 #include "pxr/external/boost/python/handle.hpp"
29 namespace PXR_BOOST_NAMESPACE {
namespace python {
32 template <
template <
class>
class X,
class Y>
52 static void Set(
void const *
id, PyObject *obj);
57 static PyObject *
Get(
void const *
id);
60 static void Erase(
void const *
id);
65 static void Acquire(
void const *
id);
70 static void Release(
void const *
id);
107 template <
class Ptr,
typename Enable =
void>
109 template <
typename U>
110 static void Add(U
const &,
const void *, PyObject *) {}
111 template <
typename U>
112 static void Remove(U
const &, PyObject *) {}
115 template <
typename Ptr>
118 std::is_same<TfRefPtr<typename Ptr::DataType>, Ptr>::value &&
119 std::is_base_of<TfRefBase, typename Ptr::DataType>::value>>
121 static void Add(Ptr
ptr,
const void *uniqueId, PyObject *
self) {
128 pxr_boost::python::handle<> capsule(
130 new Ptr(ptr),
"refptr",
131 +[](PyObject* capsule) {
132 void* heldPtr = PyCapsule_GetPointer(capsule,
"refptr");
133 delete static_cast<Ptr*
>(heldPtr);
136 int ret = PyObject_SetAttrString(
self,
"__owner", capsule.get());
139 TF_WARN(
"Could not set __owner attribute on python object!");
159 if (PyObject_HasAttrString(obj,
"__owner")) {
170 if (PyObject_DelAttrString(obj,
"__owner") == -1) {
172 TF_WARN(
"Undeletable __owner attribute on python object!");
180 #endif // doxygen -- see comment above.
183 template <
typename Ptr>
188 template <
typename T>
204 if (ptr.GetUniqueIdentifier()) {
208 ptr.EnableExtraNotification();
233 #endif // PXR_BASE_TF_PY_IDENTITY_H
typename std::enable_if< B, T >::type enable_if_t
Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
static void Add(U const &, const void *, PyObject *)
GLsizei const GLfloat * value
static TF_API void const * Lookup(TfRefBase const *refBase)
static TF_API void Release(void const *id)
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
static TF_API void Erase(TfRefBase *refBase)
TfHashMap< TfRefBase const *, void const *, TfHash > _CacheType
void Tf_PyRemovePythonOwnership(Ptr const &t, PyObject *obj)
std::enable_if_t< Tf_PyIsRefPtr< Ptr >::value > Tf_PySetPythonIdentity(Ptr const &, PyObject *)
static void Add(Ptr ptr, const void *uniqueId, PyObject *self)
static TF_API void Acquire(void const *id)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static void Remove(U const &, PyObject *)
void Tf_PyReleasePythonIdentity(Ptr const &ptr, PyObject *obj)
void Tf_PyAddPythonOwnership(Ptr const &t, const void *uniqueId, PyObject *obj)
#define PXR_NAMESPACE_CLOSE_SCOPE
static TF_API void Set(void const *id, PyObject *obj)
static TF_API void Erase(void const *id)
PyObject * Tf_PyGetPythonIdentity(Ptr const &ptr)
void Tf_PyOwnershipRefBaseUniqueChanged(TfRefBase const *refBase, bool isNowUnique)
static TF_API PyObject * Get(void const *id)
static void Remove(Ptr ptr, PyObject *obj)
static TF_API void Insert(TfRefBase *refBase, void const *uniqueId)