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>
38 #include <hboost/operators.hpp>
45 template <
class _View>
54 typedef std::pair<const key_type, mapped_type>
value_type;
55 typedef std::map<key_type, mapped_type>
map_type;
60 typedef typename View::const_iterator _inner_iterator;
64 _ValueProxy() : _owner(NULL) { }
65 _ValueProxy(
This* owner, _inner_iterator i) : _owner(owner), _pos(i)
78 _owner->_Set(*_pos, x);
84 return *_pos == other;
95 first(owner->_view.key(i)), second(owner, i) { }
109 static value_type Dereference(
const This* owner, _inner_iterator i)
120 template <
class _Owner,
class _Iter,
class _Value>
122 public hboost::iterator_facade<
123 _Iterator<_Owner, _Iter, _Value>,
125 std::bidirectional_iterator_tag,
129 _Iterator(_Owner owner, _inner_iterator i) : _owner(owner), _pos(i) { }
130 template <
class O2,
class I2,
class V2>
131 _Iterator(
const _Iterator<O2, I2, V2>& other) :
132 _owner(other._owner), _pos(other._pos) { }
135 friend class hboost::iterator_core_access;
137 _Value dereference()
const
139 return _Traits::Dereference(_owner, _pos);
142 template <
class O2,
class I2,
class V2>
143 bool equal(
const _Iterator<O2, I2, V2>& other)
const
145 return _pos == other._pos;
158 _inner_iterator _pos;
160 template <
class O2,
class I2,
class V2>
161 friend class _Iterator;
166 typedef _Iterator<This*, _inner_iterator, _PairProxy>
iterator;
177 _view(view), _type(type), _permission(permission)
184 _view(other._view), _type(other._type), _permission(other._permission)
191 if (other._Validate()) {
192 _Copy(other._view.values());
200 if (other._Validate()) {
201 _Copy(other._view.values());
219 return _Validate() ? _view.template items_as<map_type>() :
map_type();
224 return iterator(_GetThis(), _view.begin());
228 return iterator(_GetThis(), _view.end());
258 return _Validate() ? _view.size() : 0;
263 return _view.max_size();
268 return _Validate() ? _view.empty() :
true;
276 if (_PrimInsert(value,
size())) {
277 return std::make_pair(
find(_view.key(value)),
true);
280 return std::make_pair(
end(),
false);
284 return std::make_pair(i,
false);
288 return std::make_pair(
iterator(),
false);
294 return insert(value).first;
297 template <
class InputIterator>
302 for (; first != last; ++
first) {
303 _PrimInsert(*first,
size());
315 return _Erase(key) ? 1 : 0;
322 while (first != last) {
348 return _Validate() ? _view.count(key) : 0;
353 return _view == other._view;
358 explicit operator bool()
const
360 return _view.IsValid();
369 int _GetPermission()
const
376 return _Validate() ?
this : NULL;
379 const This* _GetThis()
const
381 return _Validate() ?
this : NULL;
384 bool _Validate()
const
386 if (_view.IsValid()) {
395 bool _Validate(
int permission)
400 if ((_permission & permission) == permission) {
403 const char* op =
"edit";
404 if (~_permission & permission &
CanSet) {
407 else if (~_permission & permission &
CanInsert) {
410 else if (~_permission & permission &
CanErase) {
419 return _Validate(CanSet) ? _PrimCopy(values) : false;
424 return _Validate(CanInsert) ? _PrimInsert(value, index) : false;
429 return _Validate(CanErase) ? _PrimErase(key) : false;
434 typedef std::vector<typename ChildPolicy::ValueType>
437 ChildrenValueVector
v;
438 for (
size_t i = 0; i < values.size(); ++i)
439 v.push_back(Adapter::Convert(values[i]));
441 return _view.GetChildren().Copy(v, _type);
444 bool _PrimInsert(
const mapped_type& value,
size_t index)
446 return _view.GetChildren().Insert(
447 Adapter::Convert(value), index, _type);
450 bool _PrimErase(
const key_type& key)
452 return _view.GetChildren().Erase(key, _type);
465 template <
typename _View>
471 template <
class _View>
478 #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)
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
GLenum GLsizei GLsizei GLint * values
View::ChildPolicy ChildPolicy
std::map< key_type, mapped_type > map_type
static const int CanErase
SdfChildrenProxy< View > This
const_iterator begin() const
std::pair< iterator, bool > insert(const mapped_type &value)
GLsizei const GLchar *const * string
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
#define PXR_NAMESPACE_CLOSE_SCOPE
static Vt_DefaultValueHolder Invoke()
This function must return an object of type T.
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
const_iterator find(const key_type &key) const