Loading...
Searching...
No Matches
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"
30#include "pxr/base/tf/hash.h"
31#include "pxr/base/tf/pyUtils.h"
33#include <boost/python.hpp>
34
35PXR_NAMESPACE_OPEN_SCOPE
36
43template <class T>
45public:
46 typedef typename T::ItemType ItemType;
47 typedef typename T::ItemVector ItemVector;
48
50
51 SdfPyWrapListOp(const std::string& name)
52 {
53 TfPyWrapOnce<T>([name]() { SdfPyWrapListOp::_Wrap(name); });
54 }
55
56private:
57 static ItemVector _ApplyOperations1(const T& listOp, ItemVector input) {
58 ItemVector result = input;
59 listOp.ApplyOperations(&result);
60 return result;
61 }
62 static boost::python::object
63 _ApplyOperations2(const T& outer, const T& inner) {
64 if (std::optional<T> r = outer.ApplyOperations(inner)) {
65 return boost::python::object(*r);
66 } else {
67 return boost::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 boost::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
147PXR_NAMESPACE_CLOSE_SCOPE
148
149#endif // PXR_USD_SDF_PY_LIST_OP_H
Miscellaneous Utilities for dealing with script.
Helper class for wrapping SdfListOp objects for Python.
Definition: pyListOp.h:44
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:477
Demangle C++ typenames generated by the typeid() facility.
std::string TfStringify(const T &v)
Convert an arbitrary type into a string.
Definition: stringUtils.h:572
Definitions of basic string utilities in tf.