24 #ifndef PXR_USD_SDF_CHILDREN_PROXY_H
25 #define PXR_USD_SDF_CHILDREN_PROXY_H
36 #include <hboost/iterator/iterator_facade.hpp>
37 #include <hboost/iterator/reverse_iterator.hpp>
44 template <
class _View>
53 typedef std::pair<const key_type, mapped_type>
value_type;
54 typedef std::map<key_type, mapped_type>
map_type;
59 typedef typename View::const_iterator _inner_iterator;
63 _ValueProxy() : _owner(NULL) { }
64 _ValueProxy(
This* owner, _inner_iterator i) : _owner(owner), _pos(i)
77 _owner->_Set(*_pos, x);
83 return *_pos == other;
94 first(owner->_view.key(i)), second(owner, i) { }
108 static value_type Dereference(
const This* owner, _inner_iterator i)
119 template <
class _Owner,
class _Iter,
class _Value>
121 public hboost::iterator_facade<
122 _Iterator<_Owner, _Iter, _Value>,
124 std::bidirectional_iterator_tag,
128 _Iterator(_Owner owner, _inner_iterator i) : _owner(owner), _pos(i) { }
129 template <
class O2,
class I2,
class V2>
130 _Iterator(
const _Iterator<O2, I2, V2>& other) :
131 _owner(other._owner), _pos(other._pos) { }
134 friend class hboost::iterator_core_access;
136 _Value dereference()
const
138 return _Traits::Dereference(_owner, _pos);
141 template <
class O2,
class I2,
class V2>
142 bool equal(
const _Iterator<O2, I2, V2>& other)
const
144 return _pos == other._pos;
157 _inner_iterator _pos;
159 template <
class O2,
class I2,
class V2>
160 friend class _Iterator;
165 typedef _Iterator<This*, _inner_iterator, _PairProxy>
iterator;
176 _view(view), _type(type), _permission(permission)
183 _view(other._view), _type(other._type), _permission(other._permission)
190 if (other._Validate()) {
191 _Copy(other._view.values());
199 if (other._Validate()) {
200 _Copy(other._view.values());
218 return _Validate() ? _view.template items_as<map_type>() :
map_type();
223 return iterator(_GetThis(), _view.begin());
227 return iterator(_GetThis(), _view.end());
257 return _Validate() ? _view.size() : 0;
262 return _view.max_size();
267 return _Validate() ? _view.empty() :
true;
275 if (_PrimInsert(value,
size())) {
276 return std::make_pair(
find(_view.key(value)),
true);
279 return std::make_pair(
end(),
false);
283 return std::make_pair(i,
false);
287 return std::make_pair(
iterator(),
false);
293 return insert(value).first;
296 template <
class InputIterator>
301 for (; first != last; ++
first) {
302 _PrimInsert(*first,
size());
314 return _Erase(key) ? 1 : 0;
321 while (first != last) {
347 return _Validate() ? _view.count(key) : 0;
352 return _view == other._view;
357 return !(*
this == other);
362 explicit operator bool()
const
364 return _view.IsValid();
373 int _GetPermission()
const
380 return _Validate() ?
this : NULL;
383 const This* _GetThis()
const
385 return _Validate() ?
this : NULL;
388 bool _Validate()
const
390 if (_view.IsValid()) {
399 bool _Validate(
int permission)
404 if ((_permission & permission) == permission) {
407 const char* op =
"edit";
408 if (~_permission & permission &
CanSet) {
411 else if (~_permission & permission &
CanInsert) {
414 else if (~_permission & permission &
CanErase) {
423 return _Validate(CanSet) ? _PrimCopy(values) : false;
428 return _Validate(CanInsert) ? _PrimInsert(value, index) : false;
433 return _Validate(CanErase) ? _PrimErase(key) : false;
438 typedef std::vector<typename ChildPolicy::ValueType>
441 ChildrenValueVector
v;
442 for (
size_t i = 0; i < values.size(); ++i)
443 v.push_back(Adapter::Convert(values[i]));
445 return _view.GetChildren().Copy(v, _type);
448 bool _PrimInsert(
const mapped_type& value,
size_t index)
450 return _view.GetChildren().Insert(
451 Adapter::Convert(value), index, _type);
454 bool _PrimErase(
const key_type& key)
456 return _view.GetChildren().Erase(key, _type);
469 template <
typename _View>
475 template <
class _View>
482 #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
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
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
std::pair< iterator, bool > insert(const mapped_type &value)
iterator find(const key_type &key)
hboost::reverse_iterator< iterator > reverse_iterator
iterator insert(iterator pos, const mapped_type &value)
hboost::reverse_iterator< const_iterator > const_reverse_iterator
std::vector< mapped_type > mapped_vector_type
View::value_type mapped_type
void erase(iterator first, iterator last)
_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
#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