24 #ifndef PXR_USD_SDF_PY_MAP_EDIT_PROXY_H
25 #define PXR_USD_SDF_PY_MAP_EDIT_PROXY_H
35 #include <hboost/python.hpp>
52 TfPyWrapOnce<Type>(&This::_Wrap);
56 typedef std::pair<key_type, mapped_type> pair_type;
61 return hboost::python::make_tuple(i->first, i->second);
72 struct _ExtractValue {
84 _owner(hboost::python::
extract<const
Type&>(object)),
91 _Iterator<E> GetCopy()
const
115 using namespace hboost::python;
120 class_<Type>(
name.c_str())
121 .def(
"__repr__", &This::_GetRepr)
122 .def(
"__str__", &This::_GetStr)
124 .def(
"__getitem__", &This::_GetItem)
125 .def(
"__setitem__", &This::_SetItem)
126 .def(
"__delitem__", &This::_DelItem)
127 .def(
"__contains__", &This::_HasKey)
128 .def(
"__iter__", &This::_GetKeyIterator)
129 .def(
"values", &This::_GetValueIterator)
130 .def(
"keys", &This::_GetKeyIterator)
131 .def(
"items", &This::_GetItemIterator)
132 .def(
"clear", &Type::clear)
133 .def(
"get", &This::_PyGet)
134 .def(
"get", &This::_PyGetDefault)
135 .def(
"pop", &This::_Pop)
136 .def(
"popitem", &This::_PopItem)
137 .def(
"setdefault", &This::_SetDefault)
138 .def(
"update", &This::_UpdateDict)
139 .def(
"update", &This::_UpdateList)
140 .def(
"copy", &This::_Copy)
141 .add_property(
"expired", &Type::IsExpired)
142 .def(
"__bool__", &This::_IsValid)
147 class_<_Iterator<_ExtractItem> >
148 ((
name +
"_Iterator").c_str(), no_init)
149 .def(
"__iter__", &This::template _Iterator<_ExtractItem>::GetCopy)
150 .def(
"__next__", &This::template _Iterator<_ExtractItem>::GetNext)
153 class_<_Iterator<_ExtractKey> >
154 ((
name +
"_KeyIterator").c_str(), no_init)
155 .def(
"__iter__", &This::template _Iterator<_ExtractKey>::GetCopy)
156 .def(
"__next__", &This::template _Iterator<_ExtractKey>::GetNext)
159 class_<_Iterator<_ExtractValue> >
160 ((
name +
"_ValueIterator").c_str(), no_init)
161 .def(
"__iter__", &This::template _Iterator<_ExtractValue>::GetCopy)
162 .def(
"__next__", &This::template _Iterator<_ExtractValue>::GetNext)
169 ArchGetDemangled<typename Type::Type>();
193 if (x && ! x.empty()) {
218 std::pair<typename Type::iterator, bool> i =
220 if (! i.second && i.first !=
typename Type::iterator()) {
221 i.first->second =
value;
232 return x.count(key) != 0;
235 static _Iterator<_ExtractItem>
238 return _Iterator<_ExtractItem>(
x);
241 static _Iterator<_ExtractKey>
244 return _Iterator<_ExtractKey>(
x);
247 static _Iterator<_ExtractValue>
250 return _Iterator<_ExtractValue>(
x);
257 hboost::python::
object(i->second);
264 return i == x.end() ? def : i->second;
268 static hboost::python::list _Get(
const Type& x)
270 hboost::python::list
result;
272 result.append(E::Get(i));
291 static hboost::python::tuple _PopItem(
Type& x)
295 return hboost::python::tuple();
301 return hboost::python::make_tuple(result.first, result.second);
317 static void _Update(
Type& x,
const std::vector<pair_type>&
values)
321 x[i->first] = i->second;
325 static void _UpdateDict(
Type& x,
const hboost::python::dict& d)
327 _UpdateList(x, d.items());
330 static void _UpdateList(
Type& x,
const hboost::python::list& pairs)
332 using namespace hboost::python;
334 std::vector<pair_type>
values;
335 for (
int i = 0,
n = len(pairs); i !=
n; ++i) {
336 values.push_back(pair_type(
337 extract<key_type>(pairs[i][0])(),
338 extract<mapped_type>(pairs[i][1])()));
348 static bool _IsValid(
const Type& x)
350 return static_cast<bool>(
x);
356 #endif // PXR_USD_SDF_PY_MAP_EDIT_PROXY_H
TF_API std::string TfStringPrintf(const char *fmt,...)
Type::mapped_type mapped_type
SdfPyWrapMapEditProxy< Type > This
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
TF_API void TfPyThrowStopIteration(const char *msg)
**But if you need a result
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
std::string TfPyRepr(T const &t)
OIIO_FORCEINLINE bool extract(const vbool4 &a)
GLuint const GLchar * name
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
GLenum GLsizei GLsizei GLint * values
Type::const_iterator const_iterator
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API void TfPyThrowKeyError(const char *msg)
#define TF_FOR_ALL(iter, c)
#define TF_PY_REPR_PREFIX
Type::value_type value_type
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.