24 #ifndef PXR_BASE_TF_PY_CLASS_METHOD_H
25 #define PXR_BASE_TF_PY_CLASS_METHOD_H
29 #include <hboost/python/class.hpp>
30 #include <hboost/python/dict.hpp>
31 #include <hboost/python/object.hpp>
32 #include <hboost/python/def_visitor.hpp>
36 namespace Tf_PyClassMethod {
38 using namespace hboost::python;
46 friend class def_visitor_access;
49 _methodName(methodName) {}
51 _methodName(methodName) {}
53 template <
typename CLS>
56 PyTypeObject*
self = downcast<PyTypeObject>( c.ptr() );
57 dict d((
handle<>(borrowed(self->tp_dict))));
59 object method(d[_methodName]);
61 c.attr(_methodName.c_str()) =
object(
62 handle<>( PyClassMethod_New((_CallableCheck)(method.ptr()) )));
67 PyObject* _CallableCheck(PyObject* callable)
const
69 if (PyCallable_Check(expect_non_null(callable)))
72 PyErr_Format( PyExc_TypeError,
73 "classmethod expects callable object; got an object of type %s, "
74 "which is not callable",
75 callable->ob_type->tp_name);
77 throw_error_already_set();
102 #endif // PXR_BASE_TF_PY_CLASS_METHOD_H
GLsizei const GLchar *const * string
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