7#ifndef PXR_BASE_TF_PY_OBJECT_FINDER_H
8#define PXR_BASE_TF_PY_OBJECT_FINDER_H
12#include "pxr/base/tf/api.h"
13#include "pxr/base/tf/pyIdentity.h"
15#include "pxr/external/boost/python/handle.hpp"
16#include "pxr/external/boost/python/object.hpp"
20PXR_NAMESPACE_OPEN_SCOPE
22struct Tf_PyObjectFinderBase {
23 TF_API
virtual ~Tf_PyObjectFinderBase();
24 virtual pxr_boost::python::object Find(
void const *objPtr)
const = 0;
27template <
class T,
class PtrType>
28struct Tf_PyObjectFinder :
public Tf_PyObjectFinderBase {
29 virtual ~Tf_PyObjectFinder() {}
30 virtual pxr_boost::python::object Find(
void const *objPtr)
const {
31 using namespace pxr_boost::python;
33 void *p =
const_cast<void *
>(objPtr);
34 PyObject *obj = Tf_PyGetPythonIdentity(PtrType(
static_cast<T *
>(p)));
35 return obj ? object(handle<>(obj)) : object();
40void Tf_RegisterPythonObjectFinderInternal(std::type_info
const &type,
41 Tf_PyObjectFinderBase
const *finder);
43template <
class T,
class PtrType>
44void Tf_RegisterPythonObjectFinder() {
45 Tf_RegisterPythonObjectFinderInternal(
typeid(T),
46 new Tf_PyObjectFinder<T, PtrType>());
49TF_API pxr_boost::python::object
50Tf_FindPythonObject(
void const *objPtr, std::type_info
const &type);
52PXR_NAMESPACE_CLOSE_SCOPE
Convenience class for accessing the Python Global Interpreter Lock.