7 #ifndef PXR_USD_SDF_PY_CHILDREN_PROXY_H
8 #define PXR_USD_SDF_PY_CHILDREN_PROXY_H
18 #include "pxr/external/boost/python.hpp"
19 #include "pxr/external/boost/python/slice.hpp"
23 template <
class _View>
43 _proxy(view, type, permission)
50 return _proxy == other._proxy;
55 return _proxy != other._proxy;
60 typedef typename View::const_iterator _view_const_iterator;
65 return pxr_boost::python::make_tuple(i->first, i->second);
76 struct _ExtractValue {
88 _owner(pxr_boost::python::
extract<const
This&>(object)()._proxy)
90 _cur = _owner.begin();
93 _Iterator<E> GetCopy()
const
100 if (_cur == _owner.end()) {
111 _const_iterator _cur;
116 TfPyWrapOnce<This>(&This::_Wrap);
121 using namespace pxr_boost::python;
123 std::string
name = _GetName();
126 class_<This>(
name.c_str(), no_init)
152 class_<_Iterator<_ExtractItem> >
154 .def(
"__iter__", &This::template _Iterator<_ExtractItem>::GetCopy)
155 .def(
"__next__", &This::template _Iterator<_ExtractItem>::GetNext)
158 class_<_Iterator<_ExtractKey> >
159 ((
name +
"_KeyIterator").
c_str(), no_init)
160 .def(
"__iter__", &This::template _Iterator<_ExtractKey>::GetCopy)
161 .def(
"__next__", &This::template _Iterator<_ExtractKey>::GetNext)
164 class_<_Iterator<_ExtractValue> >
165 ((
name +
"_ValueIterator").
c_str(), no_init)
166 .def(
"__iter__", &This::template _Iterator<_ExtractValue>::GetCopy)
167 .def(
"__next__", &This::template _Iterator<_ExtractValue>::GetNext)
171 static std::string _GetName()
173 std::string
name =
"ChildrenProxy_" +
174 ArchGetDemangled<View>();
183 const View& _GetView()
const
193 std::string _GetRepr()
const
196 if (! _proxy.
empty()) {
197 _const_iterator i = _proxy.
begin(),
n = _proxy.
end();
210 return _proxy.
size();
215 _view_const_iterator i = _GetView().find(key);
216 if (i == _GetView().
end()) {
228 return _GetView()[
index];
234 _proxy._GetType().c_str());
237 void _SetItemBySlice(
const pxr_boost::python::slice& slice,
246 _proxy._Copy(values);
250 void _DelItemByKey(
const key_type& key)
252 if (_GetView().
find(key) == _GetView().
end()) {
258 void _DelItemByIndex(
int index)
260 _proxy._Erase(_GetView().key(_GetItemByIndex(index)));
270 _proxy._Insert(value, _proxy.
size());
273 void _InsertItemByIndex(
int index,
const mapped_type& value)
276 index = index < (
int)_proxy.
size()
280 _proxy._Insert(value, index);
285 _view_const_iterator i = _GetView().find(key);
287 pxr_boost::python::object(*i);
293 _view_const_iterator i = _GetView().find(key);
295 pxr_boost::python::object(*i);
298 bool _HasKey(
const key_type& key)
const
300 return _GetView().find(key) != _GetView().end();
305 return _GetView().find(value) != _GetView().end();
311 return _Iterator<_ExtractItem>(
x);
317 return _Iterator<_ExtractKey>(
x);
323 return _Iterator<_ExtractValue>(
x);
327 pxr_boost::python::list _Get()
const
329 pxr_boost::python::list
result;
330 for (_const_iterator i = _proxy.
begin(),
n = _proxy.
end(); i !=
n; ++i){
331 result.append(E::Get(i));
336 int _FindIndexByKey(
const key_type& key)
const
339 return i == _GetView().size() ? -1 : i;
342 int _FindIndexByValue(
const mapped_type& value)
const
345 return i == _GetView().size() ? -1 : i;
356 #endif // PXR_USD_SDF_PY_CHILDREN_PROXY_H
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
_Iterator< const This *, _inner_iterator, value_type > const_iterator
SdfPyChildrenProxy< View > This
GLsizei const GLfloat * value
Proxy::mapped_vector_type mapped_vector_type
bool operator!=(const This &other) const
Proxy::size_type size_type
TF_API void TfPyThrowStopIteration(const char *msg)
**But if you need a result
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
bool operator==(const This &other) const
View::size_type size_type
std::string TfPyRepr(T const &t)
OIIO_FORCEINLINE bool extract(const vbool4 &a)
GLint GLint GLsizei GLint GLenum GLenum type
static const int CanErase
TF_API bool TfPyIsNone(pxr_boost::python::object const &obj)
Return true iff obj is None.
SdfPyChildrenProxy(const Proxy &proxy)
GLuint const GLchar * name
std::vector< mapped_type > mapped_vector_type
View::value_type mapped_type
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)
Proxy::mapped_type mapped_type
SIM_API const UT_StringHolder distance
static const int CanInsert
SdfChildrenProxy< View > Proxy
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)
SdfPyChildrenProxy(const View &view, const std::string &type, int permission=Proxy::CanSet|Proxy::CanInsert|Proxy::CanErase)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.