7 #ifndef PXR_USD_SDF_PY_LIST_PROXY_H
8 #define PXR_USD_SDF_PY_LIST_PROXY_H
21 #include "pxr/external/boost/python.hpp"
22 #include "pxr/external/boost/python/slice.hpp"
37 TfPyWrapOnce<Type>(&This::_Wrap);
43 using namespace pxr_boost::python;
45 class_<Type>(_GetName().c_str(), no_init)
46 .def(
"__str__", &This::_GetStr)
48 .def(
"__getitem__", &This::_GetItemIndex)
49 .def(
"__getitem__", &This::_GetItemSlice)
50 .def(
"__setitem__", &This::_SetItemIndex)
51 .def(
"__setitem__", &This::_SetItemSlice)
52 .def(
"__delitem__", &This::_DelItemIndex)
53 .def(
"__delitem__", &This::_DelItemSlice)
54 .def(
"__delitem__", &Type::Remove)
55 .def(
"count", &Type::Count)
57 return_value_policy<TfPySequenceToList>())
58 .def(
"index", &This::_FindIndex)
59 .def(
"clear", &Type::clear)
60 .def(
"insert", &This::_Insert)
61 .def(
"append", &Type::push_back)
62 .def(
"remove", &Type::Remove)
63 .def(
"replace", &Type::Replace)
64 .def(
"ApplyList", &Type::ApplyList)
65 .def(
"ApplyEditsToList", &This::_ApplyEditsToList)
66 .add_property(
"expired", &This::_IsExpired)
67 .add_static_property(
"invalidIndex", &This::_GetInvalidIndex)
74 .def(
self == other<value_vector_type>())
75 .def(
self != other<value_vector_type>())
76 .def(
self < other<value_vector_type>())
77 .def(
self <= other<value_vector_type>())
78 .def(
self > other<value_vector_type>())
79 .def(
self >= other<value_vector_type>())
83 static std::string _GetName()
85 std::string
name =
"ListProxy_" +
86 ArchGetDemangled<TypePolicy>();
95 static std::string _GetStr(
const Type&
x)
97 return TfPyRepr(static_cast<value_vector_type>(x));
105 static pxr_boost::python::list _GetItemSlice(
const Type& x,
106 const pxr_boost::python::slice& index)
108 using namespace pxr_boost::python;
114 slice::range<typename Type::const_iterator>
range =
115 index.get_indicies(x.begin(), x.end());
116 for (; range.start != range.stop; range.start += range.step) {
117 result.append(*range.start);
119 result.append(*range.start);
121 catch (
const std::invalid_argument&) {
134 static void _SetItemSlice(
Type& x,
const pxr_boost::python::slice& index,
135 const value_vector_type&
values)
137 using namespace pxr_boost::python;
139 if (! x._Validate()) {
146 slice::range<typename Type::iterator> range =
147 index.get_indicies(x.begin(), x.end());
148 start = range.start - x.begin();
150 count = 1 + (range.stop - range.start) / range.step;
152 catch (
const std::invalid_argument&) {
154 extract<int> e(index.start());
162 x._Edit(start,
count, values);
166 if (
count != values.size()) {
169 "to extended slice of size %zd",
172 else if (step == 1) {
173 x._Edit(start,
count, values);
177 for (
size_t i = 0,
j = start; i !=
count;
j += step, ++i) {
184 static void _DelItemIndex(
Type& x,
int i)
190 static void _DelItemSlice(
Type& x,
const pxr_boost::python::slice& index)
192 using namespace pxr_boost::python;
197 slice::range<typename Type::iterator> range =
198 index.get_indicies(x.begin(), x.end());
199 size_t start = range.start - x.begin();
200 size_t step = range.step;
201 size_t count = 1 + (range.stop - range.start) / range.step;
209 value_vector_type empty;
210 for (
size_t j = start; count > 0;
j += step - 1, --
count) {
211 x._Edit(
j, 1, empty);
215 catch (
const std::invalid_argument&) {
221 static int _GetInvalidIndex()
232 const size_t index = x.Find(value);
233 return index == Type::invalidIndex
235 : static_cast<
int>(index);
238 return _GetInvalidIndex();
245 index += x._GetSize();
253 static bool _IsExpired(
const Type& x)
255 return x.IsExpired();
258 static value_vector_type _ApplyEditsToList(
Type& x,
259 const value_vector_type& values)
261 value_vector_type newValues =
values;
262 x.ApplyEditsToList(&newValues);
269 #endif // PXR_USD_SDF_PY_LIST_PROXY_H
TF_API std::string TfStringPrintf(const char *fmt,...)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
Type::TypePolicy TypePolicy
Type::value_vector_type value_vector_type
GLsizei const GLfloat * value
Type::value_type value_type
TF_API void TfPyThrowValueError(const char *msg)
**But if you need a result
SdfPyWrapListProxy< Type > This
std::string TfPyRepr(T const &t)
TF_API bool TfPyIsNone(pxr_boost::python::object const &obj)
Return true iff obj is None.
GLuint const GLchar * name
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
GLenum GLsizei GLsizei GLint * values
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API void TfPyThrowIndexError(const char *msg)
OIIO_UTIL_API const char * c_str(string_view str)
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)