pySpec.h File Reference

SdfSpec Python wrapping utilities. More...

+ Include dependency graph for pySpec.h:

Go to the source code of this file.


template<typename T >
Sdf_PySpecDetail::NewVisitor< typename Sdf_PySpecDetail::NewCtor< T > > SdfMakePySpecConstructor (T *func, const std::string &doc=std::string())
Sdf_PySpecDetail::SpecVisitor< false > SdfPySpec ()
Sdf_PySpecDetail::SpecVisitor< true > SdfPyAbstractSpec ()
Sdf_PySpecDetail::SpecVisitor< false > SdfPySpecNoRepr ()
Sdf_PySpecDetail::SpecVisitor< true > SdfPyAbstractSpecNoRepr ()

Detailed Description

SdfSpec Python wrapping utilities.

An SdfSpec subclass is not the representation of scene data. An SdfSpec simply provides an interface to data stored in some internal representation. SdfSpec subclasses are value types and their lifetimes don't reflect the lifetime of the scene data. However, clients still create scene data using the New methods on SdfSpec subclasses.

When wrapping to Python we need to wrap the New methods as the constructors. This used to look like this:

class_<MyClass, MyClassHandle>("MyClass", no_init)

But we can't use TfMakePyConstructor() because an SdfSpec handle is not a weak pointer. Furthermore, we don't have the problem of needing to store a ref pointer in the Python object. But we do still need conversion of spec types to yield the most-derived type in python.

This file introduces a few boost::python::class_ def visitors to make wrapping specs easy. Spec wrapping should now look like:

class_<MyClass, SdfHandle<MyClass>, bases<SdfSpec>, boost::noncopyable>
("MyClass", no_init)
.def(SdfPySpec()) // or SdfPyAbstractSpec()

If you need a custom repr you can use SdfPySpecNoRepr() or SdfPyAbstractSpecNoRepr() and def("__repr__", ...).

Definition in file pySpec.h.