7 #ifndef PXR_USD_SDF_LIST_PROXY_H
8 #define PXR_USD_SDF_LIST_PROXY_H
24 #include <type_traits>
36 template <
class _TypePolicy>
53 _owner(owner), _index(index)
69 return _owner->_Get(_index);
75 return _owner->_Get(_index) ==
x;
83 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>
127 std::add_pointer_t<typename GetItem::result_type> operator->() {
128 return std::addressof(_result);
131 friend class _Iterator;
134 std::add_lvalue_reference_t<
135 typename GetItem::result_type>
137 typename GetItem::result_type _result;
140 using This = _Iterator<Owner, GetItem>;
141 using iterator_category = std::random_access_iterator_tag;
144 typename GetItem::result_type
147 using reference =
typename GetItem::result_type;
149 using difference_type = std::ptrdiff_t;
152 "reference is an lvalue_reference and usage of "
153 "this class unnecessarily instantiates a _PtrProxy.");
155 _Iterator() =
default;
157 _Iterator(Owner owner,
size_t index) : _owner(owner), _index(index)
165 This advanced(*
this);
166 advanced.advance(index);
167 return advanced.dereference();
171 return -distance_to(other);
184 This operator++(
int) {
190 This operator--(
int) {
198 result.advance(increment);
204 result.advance(-decrement);
223 return !
equal(other);
228 return _index < other._index;
233 return _index <= other._index;
238 return _index > other._index;
243 return _index >= other._index;
249 return _getItem(_owner, _index);
253 if (_owner != other._owner) {
255 "different proxies!");
258 return _index == other._index;
269 void advance(difference_type
n) {
273 difference_type distance_to(
const This& other)
const {
274 return other._index - _index;
279 Owner _owner =
nullptr;
313 return iterator(_GetThis(), _GetSize());
346 return _Validate() ? _GetSize() : 0;
371 return reference(_GetThis(), _GetSize() - 1);
381 return _Get(_GetSize() - 1);
402 template <
class InputIterator>
427 size_t s = _GetSize();
445 _Edit(0, _GetSize(), static_cast<value_vector_type>(other));
451 _Edit(0, _GetSize(), other);
471 return !(*
this ==
y);
476 bool operator<(const SdfListProxy<T2>&
y)
const {
482 bool operator<=(const SdfListProxy<T2>&
y)
const {
489 return !(*
this <=
y);
510 return !(*
this ==
y);
562 return _listEditor && _listEditor->IsValid() && _IsRelevant();
570 return _listEditor ? _listEditor->GetLayer() : SdfLayerHandle();
576 return _listEditor ? _listEditor->GetPath() :
SdfPath();
582 return _listEditor && _listEditor->IsExpired();
587 return (_Validate() ? _listEditor->Count(_op, value) : 0);
594 return (_Validate() ? _listEditor->Find(_op, value) :
invalidIndex);
600 index =
static_cast<int>(_GetSize());
607 size_t index =
Find(value);
620 size_t index =
Find(oldValue);
621 if (index !=
size_t(-1)) {
639 if (_Validate() && list._Validate()) {
640 _listEditor->ApplyList(_op, *list._listEditor);
648 _listEditor->ApplyEditsToList(vec);
666 _listEditor->ModifyItemEdits(std::forward<CB>(callback));
684 bool _Validate()
const
699 return _Validate() ?
this : NULL;
702 const This* _GetThis()
const
704 return _Validate() ?
this : NULL;
707 bool _IsRelevant()
const
709 if (_listEditor->IsExplicit()) {
712 else if (_listEditor->IsOrderedOnly()) {
720 size_t _GetSize()
const
722 return _listEditor ? _listEditor->GetSize(_op) : 0;
727 return _Validate() ? _listEditor->Get(_op, n) :
value_type();
735 if (n == 0 && elems.empty()) {
736 SdfAllowed canEdit = _listEditor->PermissionToEdit(_op);
745 _listEditor->ReplaceEdits(_op, index, n, elems);
753 std::shared_ptr<Sdf_ListEditor<TypePolicy> > _listEditor;
760 template <
typename T>
767 #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
GLsizei const GLfloat * value
std::vector< value_type > value_vector_type
Tf_ProxyReferenceReverseIterator< const_iterator > const_reverse_iterator
IMATH_HOSTDEVICE constexpr Plane3< T > operator-(const Plane3< T > &plane) IMATH_NOEXCEPT
Reflect the pla.
_Iterator< const This *, _ConstGetHelper > const_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.
**But if you need a result
bool operator!=(const SdfListProxy< T2 > &y) const
Inequality comparison.
void erase(iterator f, iterator l)
Erase all the elements in the range [f, l).
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.
#define TF_DEV_AXIOM(cond)
SDF_API const std::string & GetWhyNot() const
bool operator<(const SdfListProxy< T2 > &y) const
Less-than comparison.
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
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)
IMATH_HOSTDEVICE constexpr Color4< T > operator*(S a, const Color4< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Color4.
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.
IMATH_HOSTDEVICE constexpr Quat< T > operator+(const Quat< T > &q1, const Quat< T > &q2) IMATH_NOEXCEPT
Quaterion addition.
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.
Tf_ProxyReferenceReverseIterator< iterator > reverse_iterator
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.
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
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.
static const size_t invalidIndex
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.