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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_SDF_PY_LIST_OP_H
25 #define PXR_USD_SDF_PY_LIST_OP_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/listOp.h"
29 #include "pxr/base/arch/demangle.h"
30 #include "pxr/base/tf/hash.h"
31 #include "pxr/base/tf/pyUtils.h"
33 #include <hboost/python.hpp>
34 
36 
37 /// \class SdfPyWrapListOp
38 ///
39 /// Helper class for wrapping SdfListOp objects for Python. The template
40 /// parameter is the specific SdfListOp type being wrapped (e.g.,
41 /// SdfPathListOp)
42 ///
43 template <class T>
45 public:
46  typedef typename T::ItemType ItemType;
47  typedef typename T::ItemVector ItemVector;
48 
50 
52  {
53  TfPyWrapOnce<T>([name]() { SdfPyWrapListOp::_Wrap(name); });
54  }
55 
56 private:
57  static ItemVector _ApplyOperations1(const T& listOp, ItemVector input) {
58  ItemVector result = input;
59  listOp.ApplyOperations(&result);
60  return result;
61  }
63  _ApplyOperations2(const T& outer, const T& inner) {
64  if (std::optional<T> r = outer.ApplyOperations(inner)) {
65  return hboost::python::object(*r);
66  } else {
67  return hboost::python::object();
68  }
69  }
70 
71  static size_t _Hash(const T &self){
72  return TfHash()(self);
73  }
74 
75  static void _Wrap(const std::string& name)
76  {
77  using namespace hboost::python;
78 
79  using ItemVector = typename T::ItemVector;
80 
81  class_<T>(name.c_str())
82  .def("__str__", &This::_GetStr)
83  .def("__hash__", &This::_Hash)
84 
85  .def("Create", &T::Create,
86  (arg("prependedItems") = ItemVector(),
87  arg("appendedItems") = ItemVector(),
88  arg("deletedItems") = ItemVector()))
89  .staticmethod("Create")
90 
91  .def("CreateExplicit", &T::CreateExplicit,
92  (arg("explicitItems") = ItemVector()))
93  .staticmethod("CreateExplicit")
94 
95  .def(self == self)
96  .def(self != self)
97 
98  .def("HasItem", &T::HasItem)
99 
100  .def("Clear", &T::Clear)
101  .def("ClearAndMakeExplicit", &T::ClearAndMakeExplicit)
102  .def("ApplyOperations", &This::_ApplyOperations1)
103  .def("ApplyOperations", &This::_ApplyOperations2)
104 
105  .add_property("explicitItems",
106  make_function(&T::GetExplicitItems,
107  return_value_policy<return_by_value>()),
108  &T::SetExplicitItems)
109  .add_property("addedItems",
110  make_function(&T::GetAddedItems,
111  return_value_policy<return_by_value>()),
112  &T::SetAddedItems)
113  .add_property("prependedItems",
114  make_function(&T::GetPrependedItems,
115  return_value_policy<return_by_value>()),
116  &T::SetPrependedItems)
117  .add_property("appendedItems",
118  make_function(&T::GetAppendedItems,
119  return_value_policy<return_by_value>()),
120  &T::SetAppendedItems)
121  .add_property("deletedItems",
122  make_function(&T::GetDeletedItems,
123  return_value_policy<return_by_value>()),
124  &T::SetDeletedItems)
125  .add_property("orderedItems",
126  make_function(&T::GetOrderedItems,
127  return_value_policy<return_by_value>()),
128  &T::SetOrderedItems)
129  .def("GetAddedOrExplicitItems",
130  &T::GetAppliedItems) //deprecated
131  .def("GetAppliedItems",
132  &T::GetAppliedItems)
133 
134  .add_property("isExplicit", &T::IsExplicit)
135 
136  ;
137 
138  }
139 
140  static std::string _GetStr(const T& listOp)
141  {
142  return TfStringify(listOp);
143  }
144 
145 };
146 
148 
149 #endif // PXR_USD_SDF_PY_LIST_OP_H
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
T::ItemType ItemType
Definition: pyListOp.h:46
**But if you need a result
Definition: thread.h:613
T::ItemVector ItemVector
Definition: pyListOp.h:47
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1736
Definition: hash.h:477
std::string TfStringify(const T &v)
Definition: stringUtils.h:572
SdfPyWrapListOp< T > This
Definition: pyListOp.h:49
GLuint const GLchar * name
Definition: glcorearb.h:786
SdfPyWrapListOp(const std::string &name)
Definition: pyListOp.h:51
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLboolean r
Definition: glcorearb.h:1222