7 #ifndef PXR_USD_SDF_PY_CHILDREN_VIEW_H
8 #define PXR_USD_SDF_PY_CHILDREN_VIEW_H
17 #include "pxr/external/boost/python.hpp"
21 template <
class _View>
34 TfPyWrapOnce<View>(&This::_Wrap);
41 return pxr_boost::python::make_tuple(x.key(i), *i);
52 struct _ExtractValue {
64 _owner(pxr_boost::python::
extract<const
View&>(object)),
71 _Iterator<E> GetCopy()
const
95 using namespace pxr_boost::python;
97 std::string
name = _GetName();
104 class_<View>(
name.c_str(), no_init)
105 .def(
"__repr__", &This::_GetRepr)
107 .def(
"__getitem__", &This::_GetItemByKey)
108 .def(
"__getitem__", &This::_GetItemByIndex)
109 .def(
"get", &This::_PyGet)
110 .def(
"__contains__", &This::_HasKey)
111 .def(
"__contains__", &This::_HasValue)
112 .def(
"__iter__", &This::_GetValueIterator)
113 .def(
"items", &This::_GetItemIterator)
114 .def(
"keys", &This::_GetKeyIterator)
115 .def(
"values", &This::_GetValueIterator)
116 .def(
"index", &This::_FindIndexByKey)
117 .def(
"index", &This::_FindIndexByValue)
122 class_<_Iterator<_ExtractItem> >
124 .def(
"__iter__", &This::template _Iterator<_ExtractItem>::GetCopy)
125 .def(
"__next__", &This::template _Iterator<_ExtractItem>::GetNext)
128 class_<_Iterator<_ExtractKey> >
129 ((
name +
"_KeyIterator").
c_str(), no_init)
130 .def(
"__iter__", &This::template _Iterator<_ExtractKey>::GetCopy)
131 .def(
"__next__", &This::template _Iterator<_ExtractKey>::GetNext)
134 class_<_Iterator<_ExtractValue> >
135 ((
name +
"_ValueIterator").
c_str(), no_init)
136 .def(
"__iter__", &This::template _Iterator<_ExtractValue>::GetCopy)
137 .def(
"__next__", &This::template _Iterator<_ExtractValue>::GetNext)
141 static std::string _GetName()
143 std::string
name =
"ChildrenView_" +
144 ArchGetDemangled<ChildPolicy>() +
"_" +
145 ArchGetDemangled<Predicate>();
154 static std::string _GetRepr(
const View&
x)
182 if (index >= x.size()) {
192 pxr_boost::python::
object(*i);
197 return x.find(key) != x.end();
202 return x.find(value) != x.end();
208 return _Iterator<_ExtractItem>(
x);
214 return _Iterator<_ExtractKey>(
x);
220 return _Iterator<_ExtractValue>(
x);
224 static pxr_boost::python::list _Get(
const View& x)
226 pxr_boost::python::list
result;
228 result.append(E::Get(x, i));
233 static int _FindIndexByKey(
const View& x,
const key_type& key)
236 return i == x.size() ? -1 : i;
239 static int _FindIndexByValue(
const View& x,
const value_type& value)
242 return i == x.size() ? -1 : i;
248 #endif // PXR_USD_SDF_PY_CHILDREN_VIEW_H
View::ChildPolicy ChildPolicy
GLsizei const GLfloat * value
View::const_iterator const_iterator
TF_API void TfPyThrowStopIteration(const char *msg)
**But if you need a result
View::value_type value_type
std::string TfPyRepr(T const &t)
OIIO_FORCEINLINE bool extract(const vbool4 &a)
View::Predicate Predicate
SdfPyWrapChildrenView< View > This
GLuint const GLchar * name
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API void TfPyThrowIndexError(const char *msg)
OIIO_UTIL_API const char * c_str(string_view str)
SIM_API const UT_StringHolder distance
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.