7 #ifndef PXR_USD_SDF_PY_MAP_EDIT_PROXY_H
8 #define PXR_USD_SDF_PY_MAP_EDIT_PROXY_H
18 #include "pxr/external/boost/python.hpp"
35 TfPyWrapOnce<Type>(&This::_Wrap);
39 typedef std::pair<key_type, mapped_type> pair_type;
44 return pxr_boost::python::make_tuple(i->first, i->second);
55 struct _ExtractValue {
67 _owner(pxr_boost::python::
extract<const
Type&>(object)),
74 _Iterator<E> GetCopy()
const
98 using namespace pxr_boost::python;
100 std::string
name = _GetName();
103 class_<Type>(
name.c_str())
104 .def(
"__repr__", &This::_GetRepr)
105 .def(
"__str__", &This::_GetStr)
107 .def(
"__getitem__", &This::_GetItem)
108 .def(
"__setitem__", &This::_SetItem)
109 .def(
"__delitem__", &This::_DelItem)
110 .def(
"__contains__", &This::_HasKey)
111 .def(
"__iter__", &This::_GetKeyIterator)
112 .def(
"values", &This::_GetValueIterator)
113 .def(
"keys", &This::_GetKeyIterator)
114 .def(
"items", &This::_GetItemIterator)
115 .def(
"clear", &Type::clear)
116 .def(
"get", &This::_PyGet)
117 .def(
"get", &This::_PyGetDefault)
118 .def(
"pop", &This::_Pop)
119 .def(
"popitem", &This::_PopItem)
120 .def(
"setdefault", &This::_SetDefault)
121 .def(
"update", &This::_UpdateDict)
122 .def(
"update", &This::_UpdateList)
123 .def(
"copy", &This::_Copy)
124 .add_property(
"expired", &Type::IsExpired)
125 .def(
"__bool__", &This::_IsValid)
130 class_<_Iterator<_ExtractItem> >
132 .def(
"__iter__", &This::template _Iterator<_ExtractItem>::GetCopy)
133 .def(
"__next__", &This::template _Iterator<_ExtractItem>::GetNext)
136 class_<_Iterator<_ExtractKey> >
137 ((
name +
"_KeyIterator").
c_str(), no_init)
138 .def(
"__iter__", &This::template _Iterator<_ExtractKey>::GetCopy)
139 .def(
"__next__", &This::template _Iterator<_ExtractKey>::GetNext)
142 class_<_Iterator<_ExtractValue> >
143 ((
name +
"_ValueIterator").
c_str(), no_init)
144 .def(
"__iter__", &This::template _Iterator<_ExtractValue>::GetCopy)
145 .def(
"__next__", &This::template _Iterator<_ExtractValue>::GetNext)
149 static std::string _GetName()
151 std::string
name =
"MapEditProxy_" +
152 ArchGetDemangled<typename Type::Type>();
161 static std::string _GetRepr(
const Type&
x)
173 static std::string _GetStr(
const Type& x)
176 if (x && ! x.empty()) {
201 std::pair<typename Type::iterator, bool> i =
203 if (! i.second && i.first !=
typename Type::iterator()) {
204 i.first->second =
value;
215 return x.count(key) != 0;
218 static _Iterator<_ExtractItem>
221 return _Iterator<_ExtractItem>(
x);
224 static _Iterator<_ExtractKey>
227 return _Iterator<_ExtractKey>(
x);
230 static _Iterator<_ExtractValue>
233 return _Iterator<_ExtractValue>(
x);
240 pxr_boost::python::
object(i->second);
247 return i == x.end() ? def : i->second;
251 static pxr_boost::python::list _Get(
const Type& x)
253 pxr_boost::python::list
result;
255 result.append(E::Get(i));
274 static pxr_boost::python::tuple _PopItem(
Type& x)
278 return pxr_boost::python::tuple();
284 return pxr_boost::python::make_tuple(result.first, result.second);
300 static void _Update(
Type& x,
const std::vector<pair_type>&
values)
304 x[i->first] = i->second;
308 static void _UpdateDict(
Type& x,
const pxr_boost::python::dict& d)
310 _UpdateList(x, d.items());
313 static void _UpdateList(
Type& x,
const pxr_boost::python::list& pairs)
315 using namespace pxr_boost::python;
317 std::vector<pair_type>
values;
318 for (
int i = 0,
n = len(pairs); i !=
n; ++i) {
319 values.push_back(pair_type(
320 extract<key_type>(pairs[i][0])(),
321 extract<mapped_type>(pairs[i][1])()));
331 static bool _IsValid(
const Type& x)
333 return static_cast<bool>(
x);
339 #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 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)
OIIO_UTIL_API const char * c_str(string_view str)
#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.