24 #ifndef PXR_USD_SDF_PY_LIST_PROXY_H
25 #define PXR_USD_SDF_PY_LIST_PROXY_H
38 #include <hboost/python.hpp>
39 #include <hboost/python/slice.hpp>
54 TfPyWrapOnce<Type>(&This::_Wrap);
60 using namespace hboost::python;
62 class_<Type>(_GetName().c_str(), no_init)
63 .def(
"__str__", &This::_GetStr)
65 .def(
"__getitem__", &This::_GetItemIndex)
66 .def(
"__getitem__", &This::_GetItemSlice)
67 .def(
"__setitem__", &This::_SetItemIndex)
68 .def(
"__setitem__", &This::_SetItemSlice)
69 .def(
"__delitem__", &This::_DelItemIndex)
70 .def(
"__delitem__", &This::_DelItemSlice)
71 .def(
"__delitem__", &Type::Remove)
72 .def(
"count", &Type::Count)
74 return_value_policy<TfPySequenceToList>())
75 .def(
"index", &This::_FindIndex)
76 .def(
"clear", &Type::clear)
77 .def(
"insert", &This::_Insert)
78 .def(
"append", &Type::push_back)
79 .def(
"remove", &Type::Remove)
80 .def(
"replace", &Type::Replace)
81 .def(
"ApplyList", &Type::ApplyList)
82 .def(
"ApplyEditsToList", &This::_ApplyEditsToList)
83 .add_property(
"expired", &This::_IsExpired)
90 .def(
self == other<value_vector_type>())
91 .def(
self != other<value_vector_type>())
92 .def(
self < other<value_vector_type>())
93 .def(
self <= other<value_vector_type>())
94 .def(
self > other<value_vector_type>())
95 .def(
self >= other<value_vector_type>())
102 ArchGetDemangled<TypePolicy>();
113 return TfPyRepr(static_cast<value_vector_type>(x));
121 static hboost::python::list _GetItemSlice(
const Type& x,
122 const hboost::python::slice& index)
124 using namespace hboost::python;
130 slice::range<typename Type::const_iterator>
range =
131 index.get_indicies(x.begin(), x.end());
132 for (; range.start != range.stop; range.start += range.step) {
133 result.append(*range.start);
135 result.append(*range.start);
137 catch (
const std::invalid_argument&) {
150 static void _SetItemSlice(
Type& x,
const hboost::python::slice& index,
151 const value_vector_type&
values)
153 using namespace hboost::python;
155 if (! x._Validate()) {
162 slice::range<typename Type::iterator> range =
163 index.get_indicies(x.begin(), x.end());
164 start = range.start - x.begin();
166 count = 1 + (range.stop - range.start) / range.step;
168 catch (
const std::invalid_argument&) {
170 extract<int> e(index.start());
178 x._Edit(start,
count, values);
182 if (
count != values.size()) {
185 "to extended slice of size %zd",
186 values.size(),
count).c_str());
188 else if (step == 1) {
189 x._Edit(start,
count, values);
193 for (
size_t i = 0,
j = start; i !=
count;
j += step, ++i) {
200 static void _DelItemIndex(
Type& x,
int i)
206 static void _DelItemSlice(
Type& x,
const hboost::python::slice& index)
208 using namespace hboost::python;
213 slice::range<typename Type::iterator> range =
214 index.get_indicies(x.begin(), x.end());
215 size_t start = range.start - x.begin();
216 size_t step = range.step;
217 size_t count = 1 + (range.stop - range.start) / range.step;
225 value_vector_type empty;
226 for (
size_t j = start; count > 0;
j += step - 1, --
count) {
227 x._Edit(
j, 1, empty);
231 catch (
const std::invalid_argument&) {
240 return static_cast<int>(x.Find(value));
250 index += x._GetSize();
258 static bool _IsExpired(
const Type& x)
260 return x.IsExpired();
263 static value_vector_type _ApplyEditsToList(
Type& x,
264 const value_vector_type& values)
266 value_vector_type newValues =
values;
267 x.ApplyEditsToList(&newValues);
274 #endif // PXR_USD_SDF_PY_LIST_PROXY_H
TF_API std::string TfStringPrintf(const char *fmt,...)
Type::TypePolicy TypePolicy
Type::value_vector_type value_vector_type
GLsizei const GLchar *const * string
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)
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)
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
TF_API bool TfPyIsNone(hboost::python::object const &obj)
Return true iff obj is None.
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)