24 #ifndef PXR_USD_SDF_LIST_PROXY_H
25 #define PXR_USD_SDF_LIST_PROXY_H
38 #include <hboost/iterator/iterator_facade.hpp>
39 #include <hboost/iterator/reverse_iterator.hpp>
40 #include <hboost/operators.hpp>
41 #include <hboost/optional.hpp>
42 #include <hboost/type_traits/is_base_of.hpp>
43 #include <hboost/type_traits/remove_cv.hpp>
44 #include <hboost/type_traits/remove_reference.hpp>
56 template <
class _TypePolicy>
58 hboost::totally_ordered<SdfListProxy<_TypePolicy>,
59 std::vector<typename _TypePolicy::value_type> > {
68 class _ItemProxy : hboost::totally_ordered<_ItemProxy> {
71 _owner(owner), _index(index)
87 return _owner->_Get(_index);
91 return _owner->_Get(_index) ==
x;
95 return _owner->_Get(_index) <
x;
108 result_type operator()(
This* owner,
size_t index)
const {
116 result_type operator()(
const This* owner,
size_t index)
const {
117 return owner->_Get(index);
123 template <
class Owner,
class GetItem>
125 public hboost::iterator_facade<
126 _Iterator<Owner, GetItem>,
127 typename hboost::remove_cv<
128 typename hboost::remove_reference<
129 typename GetItem::result_type
132 std::random_access_iterator_tag,
133 typename GetItem::result_type> {
135 typedef _Iterator<Owner, GetItem>
This;
137 hboost::iterator_facade<
138 _Iterator<Owner, GetItem>,
139 typename hboost::remove_cv<
140 typename hboost::remove_reference<
141 typename GetItem::result_type
144 std::random_access_iterator_tag,
145 typename GetItem::result_type> Parent;
147 typedef typename Parent::difference_type difference_type;
149 _Iterator() : _owner(NULL), _index(0)
154 _Iterator(Owner owner,
size_t index) : _owner(owner), _index(index)
160 friend class hboost::iterator_core_access;
163 return _getItem(_owner, _index);
167 if (_owner != other._owner) {
169 "different proxies!");
172 return _index == other._index;
183 void advance(difference_type
n) {
187 difference_type distance_to(
const This& other)
const {
188 return other._index - _index;
227 return iterator(_GetThis(), _GetSize());
260 return _Validate() ? _GetSize() : 0;
285 return reference(_GetThis(), _GetSize() - 1);
295 return _Get(_GetSize() - 1);
316 template <
class InputIterator>
341 size_t s = _GetSize();
359 _Edit(0, _GetSize(), static_cast<value_vector_type>(other));
365 _Edit(0, _GetSize(), other);
385 return !(*
this ==
y);
390 bool operator<(const SdfListProxy<T2>&
y)
const {
396 bool operator<=(const SdfListProxy<T2>&
y)
const {
403 return !(*
this <=
y);
429 explicit operator bool()
const
431 return _listEditor && _listEditor->IsValid() && _IsRelevant();
439 return _listEditor ? _listEditor->GetLayer() : SdfLayerHandle();
445 return _listEditor ? _listEditor->GetPath() :
SdfPath();
451 return _listEditor && _listEditor->IsExpired();
456 return (_Validate() ? _listEditor->Count(_op, value) : 0);
461 return (_Validate() ? _listEditor->Find(_op, value) : size_t(-1));
467 index =
static_cast<int>(_GetSize());
475 if (index !=
size_t(-1)) {
488 if (index !=
size_t(-1)) {
506 if (_Validate() && list._Validate()) {
507 _listEditor->ApplyList(_op, *list._listEditor);
515 _listEditor->ApplyEditsToList(vec);
533 bool _Validate()
const
548 return _Validate() ?
this : NULL;
551 const This* _GetThis()
const
553 return _Validate() ?
this : NULL;
556 bool _IsRelevant()
const
558 if (_listEditor->IsExplicit()) {
561 else if (_listEditor->IsOrderedOnly()) {
569 size_t _GetSize()
const
571 return _listEditor ? _listEditor->GetSize(_op) : 0;
576 return _Validate() ? _listEditor->Get(_op, n) :
value_type();
584 if (n == 0 && elems.empty()) {
585 SdfAllowed canEdit = _listEditor->PermissionToEdit(_op);
594 _listEditor->ReplaceEdits(_op, index, n, elems);
602 hboost::shared_ptr<Sdf_ListEditor<TypePolicy> > _listEditor;
609 template <
typename T>
616 #endif // PXR_USD_SDF_LIST_PROXY_H
reverse_iterator rend()
Return a reverse iterator past the start item of the sequence.
void resize(size_t n, const value_type &t=value_type())
SdfLayerHandle GetLayer() const
Returns the layer that this list editor belongs to.
bool operator==(const value_vector_type &y) const
Equality comparison.
This & operator=(const value_vector_type &other)
Replace all elements in this sequence with the given vector.
size_t size() const
Return the size of the sequence.
SdfListProxy(const hboost::shared_ptr< Sdf_ListEditor< TypePolicy > > &editor, SdfListOpType op)
_Iterator< This *, _GetHelper > iterator
std::vector< value_type > value_vector_type
GLenum const void GLuint GLint reference
_Iterator< const This *, _ConstGetHelper > const_iterator
hboost::reverse_iterator< iterator > reverse_iterator
This & operator=(const std::vector< Y > &v)
Replace all elements in this sequence with the given vector.
value_type front() const
Return a copy of the item at the front of the sequence.
SdfListProxy(SdfListOpType op)
bool empty() const
Return true if size() == 0.
value_type operator[](size_t n) const
Return a copy of the item at index n.
void ApplyList(const SdfListProxy &list)
Applies the edits in the given list to this one.
bool operator!=(const SdfListProxy< T2 > &y) const
Inequality comparison.
void erase(iterator f, iterator l)
Erase all the elements in the range [f, l).
hboost::reverse_iterator< const_iterator > const_reverse_iterator
void pop_back()
Remove the last element from this sequence.
friend class _ConstGetHelper
This & operator=(const SdfListProxy< T2 > &other)
SdfPath GetPath() const
Returns the path to this list editor's value.
reference operator[](size_t n)
Return a reference to the item at index n.
void push_back(const value_type &elem)
Append elem to this sequence.
SDF_API const std::string & GetWhyNot() const
GLint GLint GLsizei GLint GLenum GLenum type
bool operator<(const SdfListProxy< T2 > &y) const
Less-than comparison.
const_reverse_iterator rend() const
iterator insert(iterator pos, const value_type &x)
Insert x into this sequence at position pos.
const_reverse_iterator rbegin() const
Return a const reverse iterator to the last item of the sequence.
void Insert(int index, const value_type &value)
reference front()
Return a reference to the item at the front of the sequence.
value_type back() const
Return a copy of the item at the back of the sequence.
void Replace(const value_type &oldValue, const value_type &newValue)
bool operator>(const value_vector_type &y) const
Greater-than comparison.
void ApplyEditsToList(value_vector_type *vec)
Apply the edits in this list to the given vec.
iterator begin()
Return an iterator to the start of the sequence.
size_t Count(const value_type &value) const
const_iterator begin() const
Return a const iterator to the start of the sequence.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
bool operator<(const value_vector_type &y) const
Less-than comparison.
reverse_iterator rbegin()
Return a reverse iterator to the last item of the sequence.
reference back()
Return a reference to the item at the back of the sequence.
SdfListProxy< TypePolicy > This
#define PXR_NAMESPACE_CLOSE_SCOPE
GLsizei const GLfloat * value
bool equal(T1 a, T2 b, T3 t)
TypePolicy::value_type value_type
bool operator>=(const SdfListProxy< T2 > &y) const
Greater-than-or-equal comparison.
const_iterator end() const
Return a const iterator to the end of the sequence.
void erase(iterator pos)
Erase the element at pos.
void clear()
Clear the contents of the sequence.
bool IsExpired() const
Returns true if the list editor is expired.
iterator end()
Return an iterator to the end of the sequence.
bool operator==(const SdfListProxy< T2 > &y) const
Equality comparison.
void insert(iterator pos, InputIterator f, InputIterator l)
void Remove(const value_type &value)
size_t Find(const value_type &value) const
bool operator>(const SdfListProxy< T2 > &y) const
Greater-than comparison.