125 typedef _ValuePolicy ValuePolicy;
127 typedef typename Type::key_type key_type;
128 typedef typename Type::mapped_type mapped_type;
129 typedef typename Type::value_type value_type;
151 typedef typename Type::iterator inner_iterator;
152 typedef typename Type::const_iterator const_inner_iterator;
156 _ValueProxy(
This* owner,
const Type* data, inner_iterator i) :
157 _owner(owner), _data(data), _pos(i)
163 _ValueProxy& operator=(
const U& other)
168 _owner->_Set(_data, _pos, other);
173 operator mapped_type()
const
179 mapped_type Get()
const
183 return mapped_type();
185 return _owner->_Get(_data, _pos);
196 explicit _PairProxy(
This* owner,
const Type* data, inner_iterator i) :
197 first(i->first), second(_ValueProxy(owner, data, i)) { }
199 const key_type first;
202 operator value_type()
const
209 return value_type(first, second.Get());
215 static _PairProxy Dereference(
This* owner,
216 const Type* data, inner_iterator i)
221 return _PairProxy(owner, data, i);
224 static const value_type& Dereference(
const This* owner,
226 const_inner_iterator i)
231 return owner->_Get(data, i);
235 template <
class Owner,
class I,
class R>
239 std::add_pointer_t<R> operator->() {
240 return std::addressof(_result);
243 friend class _Iterator;
244 explicit _PtrProxy(
const R& result) : _result(result) {}
248 using iterator_category = std::bidirectional_iterator_tag;
249 using value_type = R;
251 using pointer = std::conditional_t<std::is_lvalue_reference<R>::value,
252 std::add_pointer_t<R>, _PtrProxy>;
253 using difference_type = std::ptrdiff_t;
255 _Iterator() =
default;
257 _Iterator(Owner owner,
const Type* data, I i) :
258 _owner(owner), _data(data), _pos(i)
263 template <
class Owner2,
class I2,
class R2>
264 _Iterator(
const _Iterator<Owner2, I2, R2>& other) :
265 _owner(other._owner), _data(other._data), _pos(other._pos)
270 reference operator*()
const {
return dereference(); }
276 template <
typename PointerType=pointer,
277 typename std::enable_if_t<
278 std::is_pointer<PointerType>::value,
int> = 0>
279 pointer operator->()
const {
return std::addressof(dereference()); }
280 template <
typename PointerType=pointer,
281 typename std::enable_if_t<
282 !std::is_pointer<PointerType>::value,
int> = 0>
283 pointer operator->()
const {
return pointer(dereference()); }
286 const I& base()
const
291 _Iterator& operator++() {
296 _Iterator& operator--() {
301 _Iterator operator++(
int) {
302 _Iterator result(*
this);
307 _Iterator operator--(
int) {
308 _Iterator result(*
this);
313 template <
class Owner2,
class I2,
class R2>
314 bool operator==(
const _Iterator<Owner2, I2, R2>& other)
const {
318 template <
class Owner2,
class I2,
class R2>
319 bool operator!=(
const _Iterator<Owner2, I2, R2>& other)
const {
320 return !equal(other);
324 R dereference()
const
326 return Traits::Dereference(_owner, _data, _pos);
329 template <
class Owner2,
class I2,
class R2>
330 bool equal(
const _Iterator<Owner2, I2, R2>& other)
const
332 if (_owner == other._owner && _pos == other._pos) {
337 return atEnd() && other.atEnd();
351 return !_owner || _pos == _owner->_ConstData()->end();
355 Owner _owner =
nullptr;
356 const Type* _data =
nullptr;
359 template <
class Owner2,
class I2,
class R2>
friend class _Iterator;
363 typedef _ValueProxy reference;
364 typedef const value_type& const_reference;
365 typedef size_t size_type;
366 typedef ptrdiff_t difference_type;
367 typedef _Iterator<This*, inner_iterator, _PairProxy> iterator;
368 typedef _Iterator<
const This*, const_inner_iterator,
369 const value_type&> const_iterator;
370 typedef Tf_ProxyReferenceReverseIterator<iterator> reverse_iterator;
371 typedef Tf_ProxyReferenceReverseIterator<const_iterator> const_reverse_iterator;
376 const VtValue& dataVal = _owner->GetField(_field);
382 _Location().c_str());
390 if (other._Validate()) {
391 _Copy(*other._ConstData());
396 template <
class U,
class UVP>
399 if (other._Validate()) {
400 _Copy(Type(other._ConstData()->begin(), other._ConstData()->end()));
405 This& operator=(
const Type& data)
412 operator Type()
const
414 return _Validate() ? *_ConstData() : Type();
419 return _Validate() ? iterator(
this, _Data(), _Data()->begin()) :
424 return _Validate() ? iterator(
this, _Data(), _Data()->end()) :
427 const_iterator begin()
const
430 const_iterator(
this, _ConstData(), _ConstData()->begin()) :
433 const_iterator end()
const
436 const_iterator(
this, _ConstData(), _ConstData()->end()) :
440 reverse_iterator rbegin()
442 return reverse_iterator(end());
444 reverse_iterator rend()
446 return reverse_iterator(begin());
448 const_reverse_iterator rbegin()
const
450 return const_reverse_iterator(end());
452 const_reverse_iterator rend()
const
454 return const_reverse_iterator(begin());
457 size_type size()
const
459 return _Validate() ? _ConstData()->size() : 0;
462 size_type max_size()
const
464 return _Validate() ? _ConstData()->max_size() : 0;
469 return _Validate() ? _ConstData()->empty() :
true;
472 std::pair<iterator, bool> insert(
const value_type& value)
474 return _Insert(value);
477 iterator insert(iterator pos,
const value_type& value)
479 return _Insert(value).first;
482 template <
class InputIterator>
483 void insert(InputIterator first, InputIterator last)
487 for (; first != last; ++first) {
488 const value_type& v =
489 ValuePolicy::CanonicalizePair(_Owner(), *first);
491 if (_ValidateInsert(v) && _data.insert(v).second) {
498 void erase(iterator pos)
500 if (_Validate() && _ValidateErase(pos->first)) {
505 size_type erase(
const key_type& key)
508 const key_type& k = ValuePolicy::CanonicalizeKey(_Owner(), key);
509 if (_ValidateErase(k) && _data.erase(k) != 0) {
517 void erase(iterator first, iterator last)
521 while (first != last) {
522 const key_type& key = first->first;
524 if (_ValidateErase(key) && _data.erase(key) != 0) {
536 iterator find(
const key_type& key)
540 iterator(
this, _Data(),
541 _Data()->find(ValuePolicy::CanonicalizeKey(_Owner(), key))) :
545 const_iterator find(
const key_type& key)
const
549 const_iterator(
this, _ConstData(),
551 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
555 size_type count(
const key_type& key)
const
560 ValuePolicy::CanonicalizeKey(_Owner(), key)) :
564 iterator lower_bound(
const key_type& key)
568 iterator(
this, _Data(),
569 _Data()->lower_bound(
570 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
574 const_iterator lower_bound(
const key_type& key)
const
578 const_iterator(
this, _ConstData(),
579 _ConstData()->lower_bound(
580 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
584 iterator upper_bound(
const key_type& key)
588 iterator(
this, _Data(),
589 _Data()->upper_bound(
590 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
594 const_iterator upper_bound(
const key_type& key)
const
598 const_iterator(
this, _ConstData(),
599 _ConstData()->upper_bound(
600 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
604 std::pair<iterator, iterator> equal_range(
const key_type& key)
607 std::pair<inner_iterator, inner_iterator> result =
608 _Data()->equal_range(
609 ValuePolicy::CanonicalizeKey(_Owner(), key));
610 return std::make_pair(iterator(
this, _Data(), result.first),
611 iterator(
this, _Data(), result.second));
614 return std::make_pair(iterator(), iterator());
618 std::pair<const_iterator,const_iterator>
619 equal_range(
const key_type& key)
const
622 std::pair<const_inner_iterator, const_inner_iterator> result =
623 _ConstData()->equal_range(
624 ValuePolicy::CanonicalizeKey(_Owner(), key));
625 return std::make_pair(
626 const_iterator(
this, _ConstData(), result.first),
627 const_iterator(
this, _ConstData(), result.second));
630 return std::make_pair(const_iterator(), const_iterator());
634 reference operator[](
const key_type& key)
636 auto iter = _Insert(value_type(key, mapped_type())).first;
637 bool failed = iter == iterator();
638 return reference(failed ?
nullptr :
this,
639 failed ?
nullptr : _Data(),
643 bool operator==(
const Type& other)
const
645 return _Validate() ? _CompareEqual(other) : false;
648 bool operator!=(
const Type& other)
const
650 return !(*
this == other);
667 return !_Validate() || _Compare(other) < 0;
670 bool operator>(
const Type& other)
const
672 return _Validate() ? _Compare(other) > 0 :
false;
675 bool operator>=(
const Type& other)
const
677 return !(*
this < other);
680 bool operator<=(
const Type& other)
const
682 return !(*
this > other);
707 template <
class U,
class UVP>
710 const bool isValid = _Validate();
711 const bool otherIsValid = other._Validate();
713 return isValid && otherIsValid ?
714 _CompareEqual(*other._ConstData()) : isValid == otherIsValid;
717 template <
class U,
class UVP>
720 return !(*
this == other);
723 template <
class U,
class UVP>
726 return _Validate() && other._Validate() ?
727 _Compare(*other._ConstData()) < 0 :
false;
730 template <
class U,
class UVP>
733 return _Validate() && other._Validate() ?
734 _Compare(*other._ConstData()) <= 0 :
false;
737 template <
class U,
class UVP>
740 return !(*
this <= other);
743 template <
class U,
class UVP>
746 return !(*
this < other);
758 explicit operator bool()
const
775 bool _Validate()
const
788 return _owner ? &_data :
nullptr;
791 const Type* _ConstData()
const
793 return _owner ? &_data :
nullptr;
796 SdfSpecHandle _Owner()
const
801 bool _CompareEqual(
const Type& other)
const
803 if (_ConstData()->size() < other.size()) {
806 if (_ConstData()->size() > other.size()) {
811 const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
812 std::pair<const_inner_iterator, const_inner_iterator> result =
813 std::mismatch(_ConstData()->begin(), _ConstData()->end(),
815 return result.first == _ConstData()->end();
818 int _Compare(
const Type& other)
const
820 if (_ConstData()->size() < other.size()) {
823 if (_ConstData()->size() > other.size()) {
828 const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
829 std::pair<const_inner_iterator, const_inner_iterator> result =
830 std::mismatch(_ConstData()->begin(), _ConstData()->end(),
832 if (*result.first < *result.second) {
835 else if (*result.first > *result.second) {
844 bool _CompareEqual(
const D& other)
const
847 return _CompareEqual(Type(other.begin(), other.end()));
851 int _Compare(
const D& other)
const
854 return _Compare(Type(other.begin(), other.end()));
857 mapped_type _Get(
const Type* data,
const inner_iterator& i)
860 if (data == _ConstData()) {
866 return _ConstData()->find(i->first)->second;
869 return mapped_type();
872 const value_type& _Get(
const Type* data,
873 const const_inner_iterator& i)
const
877 return (data == _ConstData()) ? *i : *_ConstData()->find(i->first);
880 void _Copy(
const Type& other)
890 const value_type canonicalValue =
891 ValuePolicy::CanonicalizePair(_Owner(), *it);
892 if (!canonicalOther.insert(canonicalValue).second) {
901 if (_ValidateCopy(canonicalOther)) {
902 _data = canonicalOther;
908 bool _ValidateCopy(
const Type& other)
910 SdfSpecHandle owner = _Owner();
911 if (owner && !owner->PermissionToEdit()) {
913 _Location().c_str());
922 if (!_ValidateInsert(*it)) {
931 void _Set(
const Type* data,
const inner_iterator& i,
const U& value)
934 const mapped_type& x =
935 ValuePolicy::CanonicalizeValue(_Owner(), value);
936 if (_ValidateSet(i->first, x)) {
943 bool _ValidateSet(
const key_type& key,
const mapped_type& value)
945 SdfSpecHandle owner = _Owner();
946 if (owner && !owner->PermissionToEdit()) {
948 _Location().c_str());
958 allowed.GetWhyNot().c_str());
965 std::pair<iterator, bool> _Insert(
const value_type& value)
968 const value_type& v = ValuePolicy::CanonicalizePair(_Owner(), value);
969 if (_ValidateInsert(v)) {
970 std::pair<inner_iterator, bool> status = _data.insert(v);
974 return std::make_pair(iterator(
this, _Data(), status.first),
978 return std::make_pair(iterator(),
false);
981 return std::make_pair(iterator(),
false);
984 bool _ValidateInsert(
const value_type& value)
986 SdfSpecHandle owner = _Owner();
987 if (owner && !owner->PermissionToEdit()) {
989 _Location().c_str());
999 allowed.GetWhyNot().c_str());
1008 _Location().c_str(),
1009 allowed.GetWhyNot().c_str());
1016 void _Erase(
const key_type& key)
1018 if (_Validate() && _ValidateErase(key) && _data.erase(key) != 0) {
1019 _UpdateDataInSpec();
1023 bool _ValidateErase(
const key_type& key)
1025 SdfSpecHandle owner = _Owner();
1026 if (owner && !owner->PermissionToEdit()) {
1028 _Location().c_str());
1035 void _UpdateDataInSpec()
1041 template <
class ProxyT>
friend class SdfPyWrapMapEditProxy;