24 #ifndef PXR_USD_SDF_CHILDREN_PROXY_H
25 #define PXR_USD_SDF_CHILDREN_PROXY_H
42 template <
class _View>
51 typedef std::pair<const key_type, mapped_type>
value_type;
52 typedef std::map<key_type, mapped_type>
map_type;
57 typedef typename View::const_iterator _inner_iterator;
61 _ValueProxy() : _owner(NULL) { }
62 _ValueProxy(
This* owner, _inner_iterator i) : _owner(owner), _pos(i)
75 _owner->_Set(*_pos, x);
81 return *_pos == other;
92 first(owner->_view.key(i)), second(owner, i) { }
106 static value_type Dereference(
const This* owner, _inner_iterator i)
117 template <
class _Owner,
class _Iter,
class _Value>
121 _Value* operator->() {
return &_value; }
123 friend class _Iterator;
124 explicit _PtrProxy(
const _Value&
value) : _value(value) {}
130 "_Value cannot be a pointer or reference type.");
131 using iterator_category = std::bidirectional_iterator_tag;
135 using difference_type = std::ptrdiff_t;
137 _Iterator() =
default;
138 _Iterator(_Owner owner, _inner_iterator i) : _owner(owner), _pos(i) { }
139 template <
class O2,
class I2,
class V2>
140 _Iterator(
const _Iterator<O2, I2, V2>& other) :
141 _owner(other._owner), _pos(other._pos) { }
146 _Iterator& operator++() {
151 _Iterator& operator--() {
156 _Iterator operator++(
int) {
162 _Iterator operator--(
int) {
168 template <
class O2,
class I2,
class V2>
169 bool operator==(
const _Iterator<O2, I2, V2>& other)
const {
173 template <
class O2,
class I2,
class V2>
174 bool operator!=(
const _Iterator<O2, I2, V2>& other)
const {
175 return !
equal(other);
179 _Value dereference()
const
181 return _Traits::Dereference(_owner, _pos);
184 template <
class O2,
class I2,
class V2>
185 bool equal(
const _Iterator<O2, I2, V2>& other)
const
187 return _pos == other._pos;
200 _inner_iterator _pos;
202 template <
class O2,
class I2,
class V2>
203 friend class _Iterator;
208 typedef _Iterator<This*, _inner_iterator, _PairProxy>
iterator;
219 _view(view), _type(type), _permission(permission)
226 _view(other._view), _type(other._type), _permission(other._permission)
233 if (other._Validate()) {
234 _Copy(other._view.values());
242 if (other._Validate()) {
243 _Copy(other._view.values());
261 return _Validate() ? _view.template items_as<map_type>() :
map_type();
266 return iterator(_GetThis(), _view.begin());
270 return iterator(_GetThis(), _view.end());
300 return _Validate() ? _view.size() : 0;
305 return _view.max_size();
310 return _Validate() ? _view.empty() :
true;
318 if (_PrimInsert(value,
size())) {
319 return std::make_pair(
find(_view.key(value)),
true);
322 return std::make_pair(
end(),
false);
326 return std::make_pair(i,
false);
330 return std::make_pair(
iterator(),
false);
336 return insert(value).first;
339 template <
class InputIterator>
345 _PrimInsert(*first,
size());
357 return _Erase(key) ? 1 : 0;
364 while (first != last) {
390 return _Validate() ? _view.count(key) : 0;
395 return _view == other._view;
400 return !(*
this == other);
405 explicit operator bool()
const
407 return _view.IsValid();
416 int _GetPermission()
const
423 return _Validate() ?
this : NULL;
426 const This* _GetThis()
const
428 return _Validate() ?
this : NULL;
431 bool _Validate()
const
433 if (_view.IsValid()) {
442 bool _Validate(
int permission)
447 if ((_permission & permission) == permission) {
450 const char* op =
"edit";
451 if (~_permission & permission &
CanSet) {
454 else if (~_permission & permission &
CanInsert) {
457 else if (~_permission & permission &
CanErase) {
466 return _Validate(CanSet) ? _PrimCopy(values) : false;
471 return _Validate(CanInsert) ? _PrimInsert(value, index) : false;
476 return _Validate(CanErase) ? _PrimErase(key) : false;
481 typedef std::vector<typename ChildPolicy::ValueType>
484 ChildrenValueVector
v;
485 for (
size_t i = 0; i < values.size(); ++i)
486 v.push_back(Adapter::Convert(values[i]));
488 return _view.GetChildren().Copy(v, _type);
491 bool _PrimInsert(
const mapped_type& value,
size_t index)
493 return _view.GetChildren().Insert(
494 Adapter::Convert(value), index, _type);
497 bool _PrimErase(
const key_type& key)
499 return _view.GetChildren().Erase(key, _type);
512 template <
typename _View>
518 template <
class _View>
525 #endif // PXR_USD_SDF_CHILDREN_PROXY_H
const_iterator end() const
_Iterator< const This *, _inner_iterator, value_type > const_iterator
This & operator=(const This &other)
size_type erase(const key_type &key)
const_reverse_iterator rbegin() const
reverse_iterator rbegin()
SdfChildrenProxy(const SdfChildrenProxy< U > &other)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
This & operator=(const SdfChildrenProxy< U > &other)
bool operator==(const This &other) const
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
SdfChildrenProxy(const View &view, const std::string &type, int permission=CanSet|CanInsert|CanErase)
size_type max_size() const
**But if you need a result
View::size_type size_type
View::ChildPolicy ChildPolicy
std::map< key_type, mapped_type > map_type
static const int CanErase
SdfChildrenProxy< View > This
const_iterator begin() const
bool operator!=(const This &other) const
Tf_ProxyReferenceReverseIterator< iterator > reverse_iterator
std::pair< iterator, bool > insert(const mapped_type &value)
iterator find(const key_type &key)
iterator insert(iterator pos, const mapped_type &value)
IMATH_HOSTDEVICE constexpr Color4< T > operator*(S a, const Color4< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Color4.
std::vector< mapped_type > mapped_vector_type
View::value_type mapped_type
void erase(iterator first, iterator last)
__hostdev__ uint64_t last(uint32_t i) const
_Iterator< This *, _inner_iterator, _PairProxy > iterator
void insert(InputIterator first, InputIterator last)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
GLenum GLsizei GLsizei GLint * values
Tf_ProxyReferenceReverseIterator< const_iterator > const_reverse_iterator
#define PXR_NAMESPACE_CLOSE_SCOPE
size_type count(const key_type &key) const
This & operator=(const mapped_vector_type &values)
std::pair< const key_type, mapped_type > value_type
static const int CanInsert
const_reverse_iterator rend() const
static Vt_DefaultValueHolder Invoke()
const_iterator find(const key_type &key) const