7 #ifndef PXR_BASE_TF_PY_CLASS_METHOD_H
8 #define PXR_BASE_TF_PY_CLASS_METHOD_H
12 #include "pxr/external/boost/python/class.hpp"
13 #include "pxr/external/boost/python/dict.hpp"
14 #include "pxr/external/boost/python/object.hpp"
15 #include "pxr/external/boost/python/def_visitor.hpp"
19 namespace Tf_PyClassMethod {
21 using namespace pxr_boost::python;
29 friend class def_visitor_access;
32 _methodName(methodName) {}
34 _methodName(methodName) {}
36 template <
typename CLS>
39 PyTypeObject*
self = downcast<PyTypeObject>( c.ptr() );
40 dict d((handle<>(borrowed(self->tp_dict))));
42 object method(d[_methodName]);
44 c.attr(_methodName.c_str()) =
object(
45 handle<>( PyClassMethod_New((_CallableCheck)(method.ptr()) )));
50 PyObject* _CallableCheck(PyObject* callable)
const
52 if (PyCallable_Check(expect_non_null(callable)))
55 PyErr_Format( PyExc_TypeError,
56 "classmethod expects callable object; got an object of type %s, "
57 "which is not callable",
58 callable->ob_type->tp_name);
60 throw_error_already_set();
64 const std::string _methodName;
85 #endif // PXR_BASE_TF_PY_CLASS_METHOD_H
Tf_PyClassMethod::_TfPyClassMethod TfPyClassMethod
_TfPyClassMethod(const std::string &methodName)
_TfPyClassMethod(const char *methodName)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE