This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pyListOp.h
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"
13#include "pxr/base/tf/hash.h"
14#include "pxr/base/tf/pyUtils.h"
16#include "pxr/external/boost/python.hpp"
17
18PXR_NAMESPACE_OPEN_SCOPE
19
26template <class T>
28public:
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
39private:
40 static ItemVector _ApplyOperations1(const T& listOp, ItemVector input) {
41 ItemVector result = input;
42 listOp.ApplyOperations(&result);
43 return result;
44 }
45 static pxr_boost::python::object
46 _ApplyOperations2(const T& outer, const T& inner) {
47 if (std::optional<T> r = outer.ApplyOperations(inner)) {
48 return pxr_boost::python::object(*r);
49 } else {
50 return pxr_boost::python::object();
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::SetExplicitItems)
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::SetPrependedItems)
100 .add_property("appendedItems",
101 make_function(&T::GetAppendedItems,
102 return_value_policy<return_by_value>()),
103 &T::SetAppendedItems)
104 .add_property("deletedItems",
105 make_function(&T::GetDeletedItems,
106 return_value_policy<return_by_value>()),
107 &T::SetDeletedItems)
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
130PXR_NAMESPACE_CLOSE_SCOPE
131
132#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:27
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:460
Demangle C++ typenames generated by the typeid() facility.
std::string TfStringify(const T &v)
Convert an arbitrary type into a string.
Definition: stringUtils.h:555
Definitions of basic string utilities in tf.