24 #ifndef PXR_BASE_TF_PY_OBJECT_FINDER_H 25 #define PXR_BASE_TF_PY_OBJECT_FINDER_H 29 #include "pxr/base/tf/api.h" 30 #include "pxr/base/tf/pyIdentity.h" 32 #include <boost/python/handle.hpp> 33 #include <boost/python/object.hpp> 37 PXR_NAMESPACE_OPEN_SCOPE
39 struct Tf_PyObjectFinderBase {
40 TF_API
virtual ~Tf_PyObjectFinderBase();
41 virtual boost::python::object Find(
void const *objPtr)
const = 0;
44 template <
class T,
class PtrType>
45 struct Tf_PyObjectFinder :
public Tf_PyObjectFinderBase {
46 virtual ~Tf_PyObjectFinder() {}
47 virtual boost::python::object Find(
void const *objPtr)
const {
48 using namespace boost::python;
50 void *p = const_cast<void *>(objPtr);
51 PyObject *obj = Tf_PyGetPythonIdentity(PtrType(static_cast<T *>(p)));
52 return obj ? object(handle<>(obj)) : object();
57 void Tf_RegisterPythonObjectFinderInternal(std::type_info
const &type,
58 Tf_PyObjectFinderBase
const *finder);
60 template <
class T,
class PtrType>
61 void Tf_RegisterPythonObjectFinder() {
62 Tf_RegisterPythonObjectFinderInternal(
typeid(T),
63 new Tf_PyObjectFinder<T, PtrType>());
66 TF_API boost::python::object
67 Tf_FindPythonObject(
void const *objPtr, std::type_info
const &type);
69 PXR_NAMESPACE_CLOSE_SCOPE
71 #endif // PXR_BASE_TF_PY_OBJECT_FINDER_H Convenience class for accessing the Python Global Interpreter Lock.