24 #ifndef PXR_USD_SDF_PY_SPEC_H
25 #define PXR_USD_SDF_PY_SPEC_H
69 #include <hboost/python/def_visitor.hpp>
70 #include <hboost/python/dict.hpp>
71 #include <hboost/python/errors.hpp>
72 #include <hboost/python/raw_function.hpp>
73 #include <hboost/python/pointee.hpp>
74 #include <hboost/python/to_python_converter.hpp>
75 #include <hboost/python/tuple.hpp>
87 #include <type_traits>
103 namespace Sdf_PySpecDetail {
105 namespace bp = hboost::python;
109 template <
typename CTOR>
114 template <
typename CLS>
129 if (PyObject_HasAttrString(c.ptr(),
"__new__"))
130 c.attr(
"__new__") = c.attr(
"__new__");
131 c.def(
"__new__", CTOR::template __new__<CLS>, _doc.c_str());
132 c.staticmethod(
"__new__");
134 c.def(
"__init__", bp::raw_function(_DummyInit));
137 template <
class CLS,
class Options>
152 if (PyObject_HasAttrString(c.ptr(),
"__new__"))
153 c.attr(
"__new__") = c.attr(
"__new__");
154 c.def(
"__new__", CTOR::template __new__<CLS>,
160 c.staticmethod(
"__new__");
162 c.def(
"__init__", bp::raw_function(_DummyInit));
171 template <
typename SIG>
185 "Duplicate will be ignored.",
192 template <
typename SIG> SIG *CtorBase<SIG>::_func = 0;
198 template <
typename T>
207 namespace Sdf_PySpecDetail {
214 typedef PyObject* (*_HolderCreator)(
const SdfSpec&);
218 template <
class _SpecType>
224 bp::to_python_converter<ConstHandle, _ConstHandleToPython<SpecType> >();
227 return bp::incref(
bp::object(TfConst_cast<Handle>(p)).
ptr());
232 template <
class _SpecType,
class _Held,
class _Holder>
242 _originalConverter = _RegisterConverter<Handle>(&This::_Convert);
252 static PyObject* _Creator(
const SdfSpec& spec)
254 Handle x(Sdf_CastAccess::CastSpec<SpecType,SdfSpec>(spec));
255 return bp::objects::make_ptr_instance<SpecType, Holder>::execute(
x);
260 bp::converter::to_python_function_t
261 _RegisterConverter(bp::converter::to_python_function_t
f)
266 bp::converter::registration*
r =
267 const_cast<bp::converter::registration*
>(
270 bp::converter::to_python_function_t old = r->m_to_python;
283 static PyObject* _Convert(
const void* p)
290 static bp::converter::to_python_function_t _originalConverter;
292 template <
class SpecType,
class Held,
class Holder>
293 bp::converter::to_python_function_t
294 _HandleToPython<SpecType, Held, Holder>::_originalConverter = 0;
296 template <
class _SpecType>
304 bp::type_id<Handle>());
308 static void *convertible(PyObject *p)
313 bp::converter::get_lvalue_from_python(p,
314 bp::converter::registered<SpecType>::converters);
318 static void construct(PyObject*
source,
319 bp::converter::rvalue_from_python_stage1_data*
data)
322 ((bp::converter::rvalue_from_python_storage<Handle>*)
323 data)->storage.bytes;
325 if (data->convertible == source)
328 new (
storage)
Handle(*static_cast<SpecType*>(data->convertible));
335 template <
bool Abstract>
338 template<
typename CLS>
341 typedef typename CLS::metadata::held_type
HeldType;
348 const HeldType& held = bp::extract<const HeldType&>(
self);
401 template <
typename CLS>
404 typedef typename CLS::wrapped_type SpecType;
405 typedef typename CLS::metadata::held_type HeldType;
406 typedef typename CLS::metadata::held_type_arg HeldArgType;
407 typedef typename CLS::metadata::holder HolderType;
410 "HeldType must be SdfHandle<SpecType>.");
472 namespace Sdf_PySpecDetail
477 template <
typename R,
typename... Args>
485 typedef typename CLS::metadata::held_type HeldType;
487 HeldType specHandle(Base::_func(
args...));
489 bp::throw_error_already_set();
495 bp::detail::initialize_wrapper(result.ptr(),
get_pointer(specHandle));
497 bp::setattr(result,
"__class__", cls);
507 #endif // PXR_USD_SDF_PY_SPEC_H
SdfHandle< SpecType > Handle
Sdf_PySpecDetail::SpecVisitor< false > SdfPySpec()
static std::string Repr(const bp::object &self)
getFileOption("OpenEXR:storage") storage
static bool __gt__(const HeldType &a, const HeldType &b)
GLsizei const GLchar *const * string
SDF_API bp::object _DummyInit(bp::tuple const &, bp::dict const &)
CLS::wrapped_type SpecType
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
static bool __ne__(const HeldType &a, const HeldType &b)
GLboolean GLboolean GLboolean GLboolean a
SdfHandle< const SpecType > ConstHandle
**But if you need a result
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
PXR_NAMESPACE_OPEN_SCOPE TF_API bool TfPyConvertTfErrorsToPythonException(TfErrorMark const &m)
PyObject *(* _HolderCreator)(const SdfSpec &)
static bool IsValid(const HeldType &self)
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
static bool IsExpired(const HeldType &self)
SDF_API std::string _SpecRepr(const bp::object &, const SdfSpec *)
static bool __le__(const HeldType &a, const HeldType &b)
CLS::metadata::holder HolderType
CLS::metadata::held_type_arg HeldArgType
Sdf_PySpecDetail::SpecVisitor< true > SdfPyAbstractSpecNoRepr()
CLS::metadata::held_type HeldType
Sdf_PySpecDetail::NewVisitor< typename Sdf_PySpecDetail::NewCtor< T > > SdfMakePySpecConstructor(T *func, const std::string &doc=std::string())
SDF_API PyObject * _CreateHolder(const std::type_info &, const SdfSpec &)
GLsizei GLsizei GLchar * source
friend class bp::def_visitor_access
SDF_API void _RegisterHolderCreator(const std::type_info &, _HolderCreator)
hboost::python::object TfPyObject(T const &t, bool complainOnFailure=true)
void visit(CLS &c, char const *name, Options &options) const
GLuint const GLchar * name
static bool __eq__(const HeldType &a, const HeldType &b)
Sdf_PySpecDetail::SpecVisitor< true > SdfPyAbstractSpec()
GLboolean GLboolean GLboolean b
static size_t __hash__(const HeldType &self)
static bool __ge__(const HeldType &a, const HeldType &b)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
CtorBase< R(Args...)> Base
static bool __lt__(const HeldType &a, const HeldType &b)
static PyObject * convert(const Handle &x)
static bp::object __new__(bp::object &cls, Args...args)
_HandleToPython< SpecType, Handle, Holder > This
static PyObject * convert(ConstHandle const &p)
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
NewVisitor(const std::string &doc=std::string())
Sdf_PySpecDetail::SpecVisitor< false > SdfPySpecNoRepr()
SdfHandle< SpecType > Handle
size_t hash_value(const CH_ChannelRef &ref)
TF_API bool TfPyIsNone(hboost::python::object const &obj)
Return true iff obj is None.
static void SetFunc(Sig *func)
TF_API void TfPyThrowRuntimeError(const char *msg)
SpecVisitor(bool addRepr=true)