HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wrapTypeHelpers.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_WRAP_TYPE_HELPERS_H
8 #define PXR_BASE_TF_WRAP_TYPE_HELPERS_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/base/tf/api.h"
14 #include "pxr/base/tf/type.h"
15 #include "pxr/external/boost/python/class.hpp"
16 #include "pxr/external/boost/python/def_visitor.hpp"
17 
19 
20 // Private implementation namespace; public types are exposed below.
21 namespace TfType_WrapHelpers {
22 
23  using namespace pxr_boost::python;
24 
25  struct _PythonClass : def_visitor<_PythonClass>
26  {
27  friend class def_visitor_access;
28 
29  private:
30  template <class CLS, class T>
31  void _Visit(CLS &c, T *) const {
32  if (TfType t = TfType::Find<T>())
33  t.DefinePythonClass(c);
34  }
35 
36  public:
37  template <class CLS>
38  void visit(CLS &c) const {
39  // Use function template resolution to wrap the type
40  // appropriately depending on whether it is a polymorphic
41  // wrapper<> type.
42  typedef typename CLS::wrapped_type Type;
43  _Visit(c, detail::unwrap_wrapper((Type*)0));
44  }
45  };
46 
47 } // namespace TfType_WrapHelpers
48 
49 
50 /// \struct TfTypePythonClass
51 /// A boost.python visitor that associates the Python class object created by
52 /// the wrapping with the TfType of the C++ type being wrapped.
53 ///
54 /// Example use:
55 /// \code
56 /// class_<Foo, ...>("Foo", ...)
57 /// .def( TfTypePythonClass() )
58 /// \endcode
59 ///
61 
62 /// A helper for wrapping C++ types.
63 /// This method defines a TfType for the given python class object, and also
64 /// recursively defines TfTypes for all the Python bases if necessary.
66 
68 
69 #endif // PXR_BASE_TF_WRAP_TYPE_HELPERS_H
#define TF_API
Definition: api.h:23
TF_API TfType TfType_DefinePythonTypeAndBases(const pxr_boost::python::object &classObj)
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47