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>
37PXR_NAMESPACE_OPEN_SCOPE
39struct Tf_PyObjectFinderBase {
40 TF_API
virtual ~Tf_PyObjectFinderBase();
41 virtual boost::python::object Find(
void const *objPtr)
const = 0;
44template <
class T,
class PtrType>
45struct 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();
57void Tf_RegisterPythonObjectFinderInternal(std::type_info
const &type,
58 Tf_PyObjectFinderBase
const *finder);
60template <
class T,
class PtrType>
61void Tf_RegisterPythonObjectFinder() {
62 Tf_RegisterPythonObjectFinderInternal(
typeid(T),
63 new Tf_PyObjectFinder<T, PtrType>());
66TF_API boost::python::object
67Tf_FindPythonObject(
void const *objPtr, std::type_info
const &type);
69PXR_NAMESPACE_CLOSE_SCOPE
Convenience class for accessing the Python Global Interpreter Lock.