All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyListOp.h
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/pyUtils.h"
32 #include <boost/python.hpp>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
42 template <class T>
44 public:
45  typedef typename T::ItemType ItemType;
46  typedef typename T::ItemVector ItemVector;
47 
48  typedef SdfPyWrapListOp<T> This;
49 
50  SdfPyWrapListOp(const std::string& name)
51  {
52  TfPyWrapOnce<T>([name]() { SdfPyWrapListOp::_Wrap(name); });
53  }
54 
55 private:
56  static ItemVector _ApplyOperations1(const T& listOp, ItemVector input) {
57  ItemVector result = input;
58  listOp.ApplyOperations(&result);
59  return result;
60  }
61  static boost::python::object
62  _ApplyOperations2(const T& outer, const T& inner) {
63  if (boost::optional<T> r = outer.ApplyOperations(inner)) {
64  return boost::python::object(*r);
65  } else {
66  return boost::python::object();
67  }
68  }
69 
70  static void _Wrap(const std::string& name)
71  {
72  using namespace boost::python;
73 
74  using ItemVector = typename T::ItemVector;
75 
76  class_<T>(name.c_str())
77  .def("__str__", &This::_GetStr)
78 
79  .def("Create", &T::Create,
80  (arg("prependedItems") = ItemVector(),
81  arg("appendedItems") = ItemVector(),
82  arg("deletedItems") = ItemVector()))
83  .staticmethod("Create")
84 
85  .def("CreateExplicit", &T::CreateExplicit,
86  (arg("explicitItems") = ItemVector()))
87  .staticmethod("CreateExplicit")
88 
89  .def(self == self)
90  .def(self != self)
91 
92  .def("HasItem", &T::HasItem)
93 
94  .def("Clear", &T::Clear)
95  .def("ClearAndMakeExplicit", &T::ClearAndMakeExplicit)
96  .def("ApplyOperations", &This::_ApplyOperations1)
97  .def("ApplyOperations", &This::_ApplyOperations2)
98 
99  .add_property("explicitItems",
100  make_function(&T::GetExplicitItems,
101  return_value_policy<return_by_value>()),
102  &T::SetExplicitItems)
103  .add_property("addedItems",
104  make_function(&T::GetAddedItems,
105  return_value_policy<return_by_value>()),
106  &T::SetAddedItems)
107  .add_property("prependedItems",
108  make_function(&T::GetPrependedItems,
109  return_value_policy<return_by_value>()),
110  &T::SetPrependedItems)
111  .add_property("appendedItems",
112  make_function(&T::GetAppendedItems,
113  return_value_policy<return_by_value>()),
114  &T::SetAppendedItems)
115  .add_property("deletedItems",
116  make_function(&T::GetDeletedItems,
117  return_value_policy<return_by_value>()),
118  &T::SetDeletedItems)
119  .add_property("orderedItems",
120  make_function(&T::GetOrderedItems,
121  return_value_policy<return_by_value>()),
122  &T::SetOrderedItems)
123  .def("GetAddedOrExplicitItems",
124  &This::_GetAddedOrExplicitItems)
125 
126  .add_property("isExplicit", &T::IsExplicit)
127 
128  ;
129 
130  }
131 
132  static std::string _GetStr(const T& listOp)
133  {
134  return TfStringify(listOp);
135  }
136 
137  static
138  ItemVector _GetAddedOrExplicitItems(const T& listOp)
139  {
140  ItemVector result;
141  listOp.ApplyOperations(&result);
142  return result;
143  }
144 
145 };
146 
147 PXR_NAMESPACE_CLOSE_SCOPE
148 
149 #endif // PXR_USD_SDF_PY_LIST_OP_H
Definitions of basic string utilities in tf.
Miscellaneous Utilities for dealing with script.
Demangle C++ typenames generated by the typeid() facility.
Helper class for wrapping SdfListOp objects for Python.
Definition: pyListOp.h:43
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Convert an arbitrary type into a string.
Definition: stringUtils.h:527