24 #ifndef PXR_BASE_TF_PY_IDENTITY_H
25 #define PXR_BASE_TF_PY_IDENTITY_H
40 #include <hboost/python/class.hpp>
41 #include <hboost/python/handle.hpp>
42 #include <hboost/python/object.hpp>
48 namespace hboost {
namespace python {
51 template <
template <
class>
class X,
class Y>
71 static void Set(
void const *
id, PyObject *obj);
76 static PyObject *
Get(
void const *
id);
79 static void Erase(
void const *
id);
84 static void Acquire(
void const *
id);
89 static void Release(
void const *
id);
126 template <
class Ptr,
typename Enable =
void>
128 template <
typename U>
129 static void Add(U
const &,
const void *, PyObject *) {}
130 template <
typename U>
131 static void Remove(U
const &, PyObject *) {}
134 template <
typename Ptr>
137 std::is_same<TfRefPtr<typename Ptr::DataType>, Ptr>::value &&
138 std::is_base_of<TfRefBase, typename Ptr::DataType>::value>>
140 struct _RefPtrHolder {
149 if (
TfPyIsNone(TfPyGetClassObject<_RefPtrHolder>())) {
156 hboost::python::class_<_RefPtrHolder>(name.c_str(),
157 hboost::python::no_init);
161 explicit _RefPtrHolder(Ptr
const &refptr) : _refptr(refptr) {}
165 static void Add(Ptr
ptr,
const void *uniqueId, PyObject *
self) {
170 int ret = PyObject_SetAttrString(
self,
"__owner",
171 _RefPtrHolder::Get(ptr).
ptr());
174 TF_WARN(
"Could not set __owner attribute on python object!");
194 if (PyObject_HasAttrString(obj,
"__owner")) {
205 if (PyObject_DelAttrString(obj,
"__owner") == -1) {
207 TF_WARN(
"Undeletable __owner attribute on python object!");
215 #endif // doxygen -- see comment above.
218 template <
typename Ptr>
223 template <
typename T>
239 if (ptr.GetUniqueIdentifier()) {
243 ptr.EnableExtraNotification();
268 #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.
GLsizei const GLchar *const * string
static void Add(U const &, const void *, PyObject *)
GLsizei const GLfloat * value
static TF_API void const * Lookup(TfRefBase const *refBase)
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
static TF_API void Release(void const *id)
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
static TF_API void Erase(TfRefBase *refBase)
static hboost::python::object Get(Ptr const &refptr)
static void _WrapIfNecessary()
TfHashMap< TfRefBase const *, void const *, TfHash > _CacheType
GLuint const GLchar * name
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)
TF_API bool TfPyIsNone(hboost::python::object const &obj)
Return true iff obj is None.
static void Remove(Ptr ptr, PyObject *obj)
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)
static TF_API void Insert(TfRefBase *refBase, void const *uniqueId)