24 #ifndef PXR_BASE_TF_PY_POLYMORPHIC_H
25 #define PXR_BASE_TF_PY_POLYMORPHIC_H
40 #include <hboost/python/object/class_detail.hpp>
41 #include <hboost/python/wrapper.hpp>
42 #include <hboost/python/has_back_reference.hpp>
45 #include <type_traits>
51 template <
typename Derived>
53 public TfType::PyPolymorphicBase,
54 public hboost::python::wrapper<Derived>
62 using namespace hboost::python;
68 PyObject * m_self = detail::wrapper_base_::get_owner(*
this);
76 PyObject_GetAttrString(
77 m_self, const_cast<char*>(func))))
82 type_handle typeHandle =
83 objects::registered_class_object(
85 PyTypeObject* class_object = typeHandle.get();
87 PyObject* func_object = 0;
90 PyMethod_Check(m.get())
91 && ((PyMethodObject*)m.get())->im_self == m_self
92 && class_object->tp_dict != 0
98 PyObject_GetAttrString(
99 (PyObject *)class_object,
100 const_cast<char*>(func))));
106 if (borrowed_f && PyCallable_Check(borrowed_f.get())) {
107 func_object = borrowed_f.get();
115 if (func_object != ((PyMethodObject*)m.get())->im_func)
133 (
"Pure virtual method '%s' called -- "
134 "must provide a python implementation.",
141 template <
typename Ret>
147 template <
class Ret,
class Cls,
typename... Arg>
148 std::function<Ret (Arg...)>
151 Ret (Cls::*defaultImpl)(Arg...));
153 template <
class Ret,
class Cls,
typename... Arg>
154 std::function<Ret (Arg...)>
157 Ret (Cls::*defaultImpl)(Arg...)
const)
const;
166 template <
class Ret,
class Cls,
typename... Args>
169 using MemFn =
typename std::conditional<
171 Ret (Cls::*)(Args...)
const, Ret (Cls::*)(Args...)>
::type;
173 _BindMemFn(MemFn memFn, Cls *obj)
179 operator()(Args...
args)
const
181 return (_obj->*_memFn)(
args...);
190 template <
typename Derived>
195 template <
typename Derived>
196 template <
class Ret,
class Cls,
typename... Args>
198 std::function<Ret (Args...)>
201 Ret (Cls::*defaultImpl)(Args...))
204 "This must be a base of Cls.");
208 return _BindMemFn<Ret, Cls, Args...>(
209 defaultImpl,
static_cast<Cls *
>(
this));
212 template <
typename Derived>
213 template <
class Ret,
class Cls,
typename... Args>
215 std::function<Ret (Args...)>
218 Ret (Cls::*defaultImpl)(Args...)
const)
const
221 "This must be a base of Cls.");
225 return _BindMemFn<Ret, Cls
const, Args...>(
226 defaultImpl,
static_cast<Cls
const *
>(
this));
233 namespace hboost {
namespace python {
234 template <
typename T>
242 template <
typename Base,
typename Fn>
245 template <
typename Base,
typename Derived,
246 typename Ret,
typename... Args>
249 typedef Ret (Base::*
Type)(Args...);
252 template <
typename Base,
typename Derived,
253 typename Ret,
typename... Args>
256 typedef Ret (Base::*
Type)(Args...)
const;
259 template <
typename Base,
typename Fn>
265 return static_cast<Ret
>(fn);
270 #endif // PXR_BASE_TF_PY_POLYMORPHIC_H
TF_API std::string TfStringPrintf(const char *fmt,...)
virtual ~TfPyPolymorphic()
GLsizei const GLfloat * value
TfPyCall< Ret > CallPureVirtual(char const *func) const
TfPyPolymorphic< Derived > This
TF_API void TfPyConvertPythonExceptionToTfErrors()
Override GetOverride(char const *func) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
std::function< Ret(Arg...)> CallVirtual(char const *fname, Ret(Cls::*defaultImpl)(Arg...))
Tf_PyMemberFunctionPointerUpcast< Base, Fn >::Type TfPyProtectedVirtual(Fn fn)
Override GetPureOverride(char const *func) const