7#ifndef PXR_BASE_TF_PY_NOTICE_WRAPPER_H
8#define PXR_BASE_TF_PY_NOTICE_WRAPPER_H
14#include "pxr/base/tf/type.h"
15#include "pxr/base/tf/pyLock.h"
16#include "pxr/base/tf/pyObjectFinder.h"
17#include "pxr/base/tf/wrapTypeHelpers.h"
19#include "pxr/external/boost/python/bases.hpp"
20#include "pxr/external/boost/python/class.hpp"
21#include "pxr/external/boost/python/extract.hpp"
22#include "pxr/external/boost/python/handle.hpp"
28PXR_NAMESPACE_OPEN_SCOPE
30struct Tf_PyNoticeObjectGenerator {
31 typedef Tf_PyNoticeObjectGenerator This;
32 typedef pxr_boost::python::object (*MakeObjectFunc)(
TfNotice const &);
36 static void Register() {
38 (*_generators)[
typeid(T).name()] = This::_Generate<T>;
42 TF_API
static pxr_boost::python::object Invoke(
TfNotice const &n);
47 static pxr_boost::python::object _Generate(
TfNotice const &n) {
49 return pxr_boost::python::object(
static_cast<T
const &
>(n));
52 static MakeObjectFunc _Lookup(
TfNotice const &n);
58struct TfPyNoticeWrapperBase :
public TfType::PyPolymorphicBase {
59 TF_API
virtual ~TfPyNoticeWrapperBase();
60 virtual pxr_boost::python::handle<> GetNoticePythonObject()
const = 0;
63template <
class Notice>
64struct Tf_PyNoticeObjectFinder :
public Tf_PyObjectFinderBase {
65 virtual ~Tf_PyNoticeObjectFinder() {}
66 virtual pxr_boost::python::object Find(
void const *objPtr)
const {
67 using namespace pxr_boost::python;
69 Notice
const *wrapper =
static_cast<Notice
const *
>(objPtr);
70 return wrapper ? object(wrapper->GetNoticePythonObject()) : object();
74template <
typename NoticeType,
typename BaseType>
75struct TfPyNoticeWrapper :
public NoticeType,
public TfPyNoticeWrapperBase {
77 static_assert(std::is_base_of<TfNotice, NoticeType>::value
78 || std::is_same<TfNotice, NoticeType>::value,
79 "Notice type must be derived from or equal to TfNotice.");
81 static_assert(std::is_base_of<TfNotice, BaseType>::value
82 || std::is_same<TfNotice, BaseType>::value,
83 "BaseType type must be derived from or equal to TfNotice.");
85 static_assert(std::is_base_of<BaseType, NoticeType>::value
86 || (std::is_same<NoticeType, TfNotice>::value
87 && std::is_same<BaseType, TfNotice>::value),
88 "BaseType type must be a base of notice, unless both "
89 "BaseType and Notice type are equal to TfNotice.");
93 typedef TfPyNoticeWrapper<NoticeType, BaseType> This;
97 using Bases = std::conditional_t<std::is_same<NoticeType, TfNotice>::value,
98 pxr_boost::python::bases<>,
99 pxr_boost::python::bases<BaseType>>;
101 typedef pxr_boost::python::class_<NoticeType, This, Bases> ClassType;
103 static ClassType Wrap(std::string
const &name = std::string()) {
104 std::string wrappedName = name;
105 if (wrappedName.empty()) {
107 wrappedName = TfType::Find<NoticeType>().GetTypeName();
111 Tf_PyNoticeObjectGenerator::Register<NoticeType>();
112 Tf_RegisterPythonObjectFinderInternal
113 (
typeid(TfPyNoticeWrapper),
114 new Tf_PyNoticeObjectFinder<TfPyNoticeWrapper>);
115 return ClassType(wrappedName.c_str(), pxr_boost::python::no_init)
120 virtual pxr_boost::python::handle<> GetNoticePythonObject()
const {
122 return pxr_boost::python::handle<>(pxr_boost::python::borrowed(_self));
127 template <
typename... Args>
128 TfPyNoticeWrapper(PyObject *self, Args... args)
129 : NoticeType(args...)
137#define TF_INSTANTIATE_NOTICE_WRAPPER(T, Base) \
138TF_REGISTRY_FUNCTION(TfType) \
140 TfType::Define< TfPyNoticeWrapper<T, Base>, \
141 TfType::Bases<Base> >(); \
144PXR_NAMESPACE_CLOSE_SCOPE
The base class for objects used to notify interested parties (listeners) when events have occurred.
Convenience class for accessing the Python Global Interpreter Lock.
Create or return a previously created object instance of global data.
TF_API std::string TfStringGetSuffix(const std::string &name, char delimiter='.')
Returns the suffix of a string.
Definitions of basic string utilities in tf.
A boost.python visitor that associates the Python class object created by the wrapping with the TfTyp...