HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyListOp.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_USD_SDF_PY_LIST_OP_H
8 #define PXR_USD_SDF_PY_LIST_OP_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/listOp.h"
12 #include "pxr/base/arch/demangle.h"
13 #include "pxr/base/tf/hash.h"
14 #include "pxr/base/tf/pyUtils.h"
16 #include "pxr/external/boost/python.hpp"
17 
19 
20 /// \class SdfPyWrapListOp
21 ///
22 /// Helper class for wrapping SdfListOp objects for Python. The template
23 /// parameter is the specific SdfListOp type being wrapped (e.g.,
24 /// SdfPathListOp)
25 ///
26 template <class T>
28 public:
29  typedef typename T::ItemType ItemType;
30  typedef typename T::ItemVector ItemVector;
31 
33 
34  SdfPyWrapListOp(const std::string& name)
35  {
36  TfPyWrapOnce<T>([name]() { SdfPyWrapListOp::_Wrap(name); });
37  }
38 
39 private:
40  static ItemVector _ApplyOperations1(const T& listOp, ItemVector input) {
41  ItemVector result = input;
42  listOp.ApplyOperations(&result);
43  return result;
44  }
46  _ApplyOperations2(const T& outer, const T& inner) {
47  if (std::optional<T> r = outer.ApplyOperations(inner)) {
49  } else {
51  }
52  }
53 
54  static size_t _Hash(const T &self){
55  return TfHash()(self);
56  }
57 
58  static void _Wrap(const std::string& name)
59  {
60  using namespace pxr_boost::python;
61 
62  using ItemVector = typename T::ItemVector;
63 
64  class_<T>(name.c_str())
65  .def("__str__", &This::_GetStr)
66  .def("__hash__", &This::_Hash)
67 
68  .def("Create", &T::Create,
69  (arg("prependedItems") = ItemVector(),
70  arg("appendedItems") = ItemVector(),
71  arg("deletedItems") = ItemVector()))
72  .staticmethod("Create")
73 
74  .def("CreateExplicit", &T::CreateExplicit,
75  (arg("explicitItems") = ItemVector()))
76  .staticmethod("CreateExplicit")
77 
78  .def(self == self)
79  .def(self != self)
80 
81  .def("HasItem", &T::HasItem)
82 
83  .def("Clear", &T::Clear)
84  .def("ClearAndMakeExplicit", &T::ClearAndMakeExplicit)
85  .def("ApplyOperations", &This::_ApplyOperations1)
86  .def("ApplyOperations", &This::_ApplyOperations2)
87 
88  .add_property("explicitItems",
89  make_function(&T::GetExplicitItems,
90  return_value_policy<return_by_value>()),
91  +[](T& t, const ItemVector& items){t.SetExplicitItems(items);})
92  .add_property("addedItems",
93  make_function(&T::GetAddedItems,
94  return_value_policy<return_by_value>()),
95  &T::SetAddedItems)
96  .add_property("prependedItems",
97  make_function(&T::GetPrependedItems,
98  return_value_policy<return_by_value>()),
99  +[](T& t, const ItemVector& items){t.SetPrependedItems(items);})
100  .add_property("appendedItems",
101  make_function(&T::GetAppendedItems,
102  return_value_policy<return_by_value>()),
103  +[](T& t, const ItemVector& items){t.SetAppendedItems(items);})
104  .add_property("deletedItems",
105  make_function(&T::GetDeletedItems,
106  return_value_policy<return_by_value>()),
107  +[](T& t, const ItemVector& items){t.SetDeletedItems(items);})
108  .add_property("orderedItems",
109  make_function(&T::GetOrderedItems,
110  return_value_policy<return_by_value>()),
111  &T::SetOrderedItems)
112  .def("GetAddedOrExplicitItems",
113  &T::GetAppliedItems) //deprecated
114  .def("GetAppliedItems",
115  &T::GetAppliedItems)
116 
117  .add_property("isExplicit", &T::IsExplicit)
118 
119  ;
120 
121  }
122 
123  static std::string _GetStr(const T& listOp)
124  {
125  return TfStringify(listOp);
126  }
127 
128 };
129 
131 
132 #endif // PXR_USD_SDF_PY_LIST_OP_H
T::ItemType ItemType
Definition: pyListOp.h:29
**But if you need a result
Definition: thread.h:622
T::ItemVector ItemVector
Definition: pyListOp.h:30
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1859
Definition: hash.h:472
std::string TfStringify(const T &v)
Definition: stringUtils.h:556
SdfPyWrapListOp< T > This
Definition: pyListOp.h:32
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
SdfPyWrapListOp(const std::string &name)
Definition: pyListOp.h:34
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLboolean r
Definition: glcorearb.h:1222