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/optional.hpp>
43 #include <type_traits>
55 template <
class _TypePolicy>
68 _owner(owner), _index(index)
84 return _owner->_Get(_index);
90 return _owner->_Get(_index) ==
x;
98 return _owner->_Get(_index) <
x;
123 result_type operator()(
This* owner,
size_t index)
const {
131 result_type operator()(
const This* owner,
size_t index)
const {
132 return owner->_Get(index);
138 template <
class Owner,
class GetItem>
140 public hboost::iterator_facade<
141 _Iterator<Owner, GetItem>,
143 std::remove_reference_t<
144 typename GetItem::result_type
147 std::random_access_iterator_tag,
148 typename GetItem::result_type> {
150 typedef _Iterator<Owner, GetItem>
This;
152 hboost::iterator_facade<
153 _Iterator<Owner, GetItem>,
156 typename GetItem::result_type
159 std::random_access_iterator_tag,
160 typename GetItem::result_type> Parent;
161 typedef typename Parent::reference
reference;
162 typedef typename Parent::difference_type difference_type;
164 _Iterator() : _owner(NULL), _index(0)
169 _Iterator(Owner owner,
size_t index) : _owner(owner), _index(index)
175 friend class hboost::iterator_core_access;
178 return _getItem(_owner, _index);
182 if (_owner != other._owner) {
184 "different proxies!");
187 return _index == other._index;
198 void advance(difference_type
n) {
202 difference_type distance_to(
const This& other)
const {
203 return other._index - _index;
242 return iterator(_GetThis(), _GetSize());
275 return _Validate() ? _GetSize() : 0;
300 return reference(_GetThis(), _GetSize() - 1);
310 return _Get(_GetSize() - 1);
331 template <
class InputIterator>
356 size_t s = _GetSize();
374 _Edit(0, _GetSize(), static_cast<value_vector_type>(other));
380 _Edit(0, _GetSize(), other);
400 return !(*
this ==
y);
405 bool operator<(const SdfListProxy<T2>&
y)
const {
411 bool operator<=(const SdfListProxy<T2>&
y)
const {
418 return !(*
this <=
y);
439 return !(*
this ==
y);
489 explicit operator bool()
const
491 return _listEditor && _listEditor->IsValid() && _IsRelevant();
499 return _listEditor ? _listEditor->GetLayer() : SdfLayerHandle();
505 return _listEditor ? _listEditor->GetPath() :
SdfPath();
511 return _listEditor && _listEditor->IsExpired();
516 return (_Validate() ? _listEditor->Count(_op, value) : 0);
521 return (_Validate() ? _listEditor->Find(_op, value) : size_t(-1));
527 index =
static_cast<int>(_GetSize());
535 if (index !=
size_t(-1)) {
548 if (index !=
size_t(-1)) {
566 if (_Validate() && list._Validate()) {
567 _listEditor->ApplyList(_op, *list._listEditor);
575 _listEditor->ApplyEditsToList(vec);
593 _listEditor->ModifyItemEdits(std::forward<CB>(callback));
611 bool _Validate()
const
626 return _Validate() ?
this : NULL;
629 const This* _GetThis()
const
631 return _Validate() ?
this : NULL;
634 bool _IsRelevant()
const
636 if (_listEditor->IsExplicit()) {
639 else if (_listEditor->IsOrderedOnly()) {
647 size_t _GetSize()
const
649 return _listEditor ? _listEditor->GetSize(_op) : 0;
654 return _Validate() ? _listEditor->Get(_op, n) :
value_type();
662 if (n == 0 && elems.empty()) {
663 SdfAllowed canEdit = _listEditor->PermissionToEdit(_op);
672 _listEditor->ReplaceEdits(_op, index, n, elems);
680 std::shared_ptr<Sdf_ListEditor<TypePolicy> > _listEditor;
687 template <
typename T>
694 #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.
_Iterator< This *, _GetHelper > iterator
std::vector< value_type > value_vector_type
_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.
bool operator!=(const value_vector_type &y) const
Inequality comparison.
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.
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
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 bool operator==(const value_vector_type &x, const SdfListProxy &y)
Equality comparision.
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
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)
typename std::remove_reference< T >::type remove_reference_t
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.
friend bool operator>=(const value_vector_type &x, const SdfListProxy &y)
Greater-than or equal to comparison.
SdfListProxy(const std::shared_ptr< Sdf_ListEditor< TypePolicy > > &editor, SdfListOpType op)
bool operator>=(const value_vector_type &y) const
Greater-than or equal to 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.
friend bool operator<=(const value_vector_type &x, const SdfListProxy &y)
Less-than or equal to comparison.
friend bool operator>(const value_vector_type &x, const SdfListProxy &y)
Greater-than comparison.
friend bool operator<(const value_vector_type &x, const SdfListProxy &y)
Less-than comparison.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
bool operator<(const value_vector_type &y) const
Less-than comparison.
void ModifyItemEdits(CB callback)
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.
bool operator<=(const value_vector_type &y) const
Less-than or equal to comparison.
SdfListProxy< TypePolicy > This
#define PXR_NAMESPACE_CLOSE_SCOPE
friend bool operator!=(const value_vector_type &x, const SdfListProxy &y)
Inequality comparision.
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
Less-than-or-equal comparison.
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.