24 #ifndef PXR_USD_SDF_MAP_EDIT_PROXY_H
25 #define PXR_USD_SDF_MAP_EDIT_PROXY_H
38 #include "pxr/base/tf/mallocTag.h"
39 #include <hboost/iterator/iterator_facade.hpp>
40 #include <hboost/iterator/reverse_iterator.hpp>
41 #include <hboost/operators.hpp>
119 template <
class T,
class _ValuePolicy = SdfIdentityMapEditProxyValuePolicy<T> >
121 hboost::totally_ordered<SdfMapEditProxy<T, _ValuePolicy>, T> {
150 typedef typename Type::iterator inner_iterator;
151 typedef typename Type::const_iterator const_inner_iterator;
155 _ValueProxy(
This* owner,
const Type*
data, inner_iterator i) :
156 _owner(owner), _data(data), _pos(i)
167 _owner->_Set(_data, _pos, other);
184 return _owner->_Get(_data, _pos);
195 explicit _PairProxy(
This* owner,
const Type*
data, inner_iterator i) :
196 first(i->
first), second(_ValueProxy(owner, data, i)) { }
214 static _PairProxy Dereference(
This* owner,
220 return _PairProxy(owner, data, i);
225 const_inner_iterator i)
230 return owner->_Get(data, i);
234 template <
class Owner,
class I,
class R>
236 public hboost::iterator_facade<_Iterator<Owner, I, R>, R,
237 std::bidirectional_iterator_tag, R> {
240 _owner(NULL), _data(NULL) { }
242 _Iterator(Owner owner,
const Type* data, I i) :
243 _owner(owner), _data(data), _pos(i)
248 template <
class Owner2,
class I2,
class R2>
249 _Iterator(
const _Iterator<Owner2, I2, R2>& other) :
250 _owner(other._owner), _data(other._data), _pos(other._pos)
255 const I& base()
const
261 R dereference()
const
263 return Traits::Dereference(_owner, _data, _pos);
266 template <
class Owner2,
class I2,
class R2>
267 bool equal(
const _Iterator<Owner2, I2, R2>& other)
const
269 if (_owner == other._owner && _pos == other._pos) {
274 return atEnd() && other.atEnd();
288 return !_owner || _pos == _owner->_ConstData()->end();
296 friend class hboost::iterator_core_access;
297 template <
class Owner2,
class I2,
class R2>
friend class _Iterator;
305 typedef _Iterator<This*, inner_iterator, _PairProxy>
iterator;
306 typedef _Iterator<
const This*, const_inner_iterator,
324 if (other._Validate()) {
325 _Copy(*other._ConstData());
330 template <
class U,
class UVP>
333 if (other._Validate()) {
334 _Copy(
Type(other._ConstData()->begin(), other._ConstData()->end()));
348 return _Validate() ? *_ConstData() :
Type();
353 return _Validate() ?
iterator(
this, _Data(), _Data()->
begin()) :
358 return _Validate() ?
iterator(
this, _Data(), _Data()->
end()) :
393 return _Validate() ? _ConstData()->size() : 0;
398 return _Validate() ? _ConstData()->max_size() : 0;
403 return _Validate() ? _ConstData()->empty() :
true;
408 return _Insert(value);
413 return _Insert(value).first;
416 template <
class InputIterator>
421 for (; first != last; ++
first) {
423 ValuePolicy::CanonicalizePair(_Owner(), *first);
425 if (_ValidateInsert(v)) {
434 if (_Validate() && _ValidateErase(pos->first)) {
442 const key_type& k = ValuePolicy::CanonicalizeKey(_Owner(), key);
443 if (_ValidateErase(k)) {
444 return _editor->Erase(k) ? 1 : 0;
454 while (first != last) {
457 if (_ValidateErase(key)) {
474 _Data()->
find(ValuePolicy::CanonicalizeKey(_Owner(), key))) :
484 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
493 ValuePolicy::CanonicalizeKey(_Owner(), key)) :
503 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
513 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
523 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
533 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
540 std::pair<inner_iterator, inner_iterator>
result =
541 _Data()->equal_range(
542 ValuePolicy::CanonicalizeKey(_Owner(), key));
543 return std::make_pair(
iterator(
this, _Data(), result.first),
544 iterator(
this, _Data(), result.second));
551 std::pair<const_iterator,const_iterator>
555 std::pair<const_inner_iterator, const_inner_iterator>
result =
556 _ConstData()->equal_range(
557 ValuePolicy::CanonicalizeKey(_Owner(), key));
558 return std::make_pair(
571 return reference(failed ?
nullptr :
this,
572 failed ?
nullptr : _Data(),
578 return _Validate() ? _CompareEqual(other) :
false;
583 return _Validate() ? _Compare(other) < 0 :
false;
588 return _Validate() ? _Compare(other) > 0 :
false;
591 template <
class U,
class UVP>
594 return _Validate() && other._Validate() ?
595 _CompareEqual(*other._ConstData()) :
false;
598 template <
class U,
class UVP>
601 return !(*
this == other);
604 template <
class U,
class UVP>
605 bool operator<(const SdfMapEditProxy<U, UVP>& other)
const
607 return _Validate() && other._Validate() ?
608 _Compare(*other._ConstData()) < 0 :
false;
611 template <
class U,
class UVP>
612 bool operator<=(const SdfMapEditProxy<U, UVP>& other)
const
614 return _Validate() && other._Validate() ?
615 _Compare(*other._ConstData()) <= 0 :
false;
618 template <
class U,
class UVP>
621 return !(*
this <= other);
624 template <
class U,
class UVP>
627 return !(*
this < other);
634 return _editor && _editor->IsExpired();
639 explicit operator bool()
const
656 bool _Validate()
const
669 return _editor ? _editor->GetData() : NULL;
672 const Type* _ConstData()
const
674 return _editor ? _editor->GetData() : NULL;
677 SdfSpecHandle _Owner()
const
679 return _editor ? _editor->GetOwner() : SdfSpecHandle();
684 return _editor ? _editor->GetLocation() :
std::string();
687 bool _CompareEqual(
const Type& other)
const
689 if (_ConstData()->
size() < other.size()) {
692 if (_ConstData()->size() > other.size()) {
697 const Type&
x = ValuePolicy::CanonicalizeType(_Owner(), other);
698 std::pair<const_inner_iterator, const_inner_iterator>
result =
699 std::mismatch(_ConstData()->
begin(), _ConstData()->
end(),
701 return result.first == _ConstData()->end();
704 int _Compare(
const Type& other)
const
706 if (_ConstData()->
size() < other.size()) {
709 if (_ConstData()->size() > other.size()) {
714 const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
715 std::pair<const_inner_iterator, const_inner_iterator> result =
716 std::mismatch(_ConstData()->
begin(), _ConstData()->
end(),
718 if (*result.first < *result.second) {
721 else if (*result.first > *result.second) {
730 bool _CompareEqual(
const D& other)
const
733 return _CompareEqual(
Type(other.begin(), other.end()));
737 int _Compare(
const D& other)
const
740 return _Compare(
Type(other.begin(), other.end()));
746 if (data == _ConstData()) {
752 return _ConstData()->find(i->first)->second;
759 const const_inner_iterator& i)
const
763 return (data == _ConstData()) ? *i : *_ConstData()->find(i->first);
766 void _Copy(
const Type& other)
777 ValuePolicy::CanonicalizePair(_Owner(), *it);
778 if (!canonicalOther.insert(canonicalValue).second) {
787 if (_ValidateCopy(canonicalOther)) {
788 _editor->Copy(canonicalOther);
793 bool _ValidateCopy(
const Type& other)
795 SdfSpecHandle owner = _Owner();
796 if (owner && !owner->PermissionToEdit()) {
798 _Location().c_str());
807 if (!_ValidateInsert(*it)) {
816 void _Set(
const Type* data,
const inner_iterator& i,
const U&
value)
820 ValuePolicy::CanonicalizeValue(_Owner(), value);
821 if (_ValidateSet(i->first, x)) {
822 _editor->Set(i->first, x);
829 SdfSpecHandle owner = _Owner();
830 if (owner && !owner->PermissionToEdit()) {
832 _Location().c_str());
836 if (
SdfAllowed allowed = _editor->IsValidValue(value)) {
842 allowed.GetWhyNot().c_str());
849 std::pair<iterator, bool> _Insert(
const value_type& value)
852 const value_type&
v = ValuePolicy::CanonicalizePair(_Owner(), value);
853 if (_ValidateInsert(v)) {
854 std::pair<inner_iterator, bool> status = _editor->Insert(v);
855 return std::make_pair(
iterator(
this, _Data(), status.first),
859 return std::make_pair(
iterator(),
false);
862 return std::make_pair(
iterator(),
false);
867 SdfSpecHandle owner = _Owner();
868 if (owner && !owner->PermissionToEdit()) {
870 _Location().c_str());
874 if (
SdfAllowed allowed = _editor->IsValidKey(value.first)) {
880 allowed.GetWhyNot().c_str());
884 if (
SdfAllowed allowed = _editor->IsValidValue(value.second)) {
890 allowed.GetWhyNot().c_str());
899 if (_Validate() && _ValidateErase(key)) {
904 bool _ValidateErase(
const key_type& key)
906 SdfSpecHandle owner = _Owner();
907 if (owner && !owner->PermissionToEdit()) {
909 _Location().c_str());
919 std::shared_ptr<Sdf_MapEditor<T> > _editor;
923 template <
class T,
class _ValuePolicy>
930 #endif // PXR_USD_SDF_MAP_EDIT_PROXY_H
void insert(InputIterator first, InputIterator last)
static const key_type & CanonicalizeKey(const SdfSpecHandle &, const key_type &x)
hboost::reverse_iterator< const_iterator > const_reverse_iterator
bool operator>=(const SdfMapEditProxy< U, UVP > &other) const
Type::value_type value_type
size_type erase(const key_type &key)
bool operator<(const Type &other) const
GLsizei const GLchar *const * string
ptrdiff_t difference_type
static const value_type & CanonicalizePair(const SdfSpecHandle &, const value_type &x)
std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
**But if you need a result
Type::value_type value_type
bool operator>(const Type &other) const
const_iterator lower_bound(const key_type &key) const
const_iterator begin() const
Type::mapped_type mapped_type
const_reverse_iterator rend() const
size_type max_size() const
const_reverse_iterator rbegin() const
iterator lower_bound(const key_type &key)
iterator insert(iterator pos, const value_type &value)
SDF_DECLARE_HANDLES(SdfSpec)
const_iterator upper_bound(const key_type &key) const
void erase(iterator first, iterator last)
bool operator==(const SdfMapEditProxy< U, UVP > &other) const
SdfMapEditProxy< Type, ValuePolicy > This
std::pair< iterator, bool > insert(const value_type &value)
_Iterator< const This *, const_inner_iterator, const value_type & > const_iterator
std::pair< iterator, iterator > equal_range(const key_type &key)
reference operator[](const key_type &key)
_Iterator< This *, inner_iterator, _PairProxy > iterator
SdfMapEditProxy(const SdfSpecHandle &owner, const TfToken &field)
const_iterator end() const
iterator find(const key_type &key)
static const mapped_type & CanonicalizeValue(const SdfSpecHandle &, const mapped_type &x)
size_type count(const key_type &key) const
bool operator!=(const SdfMapEditProxy< U, UVP > &other) const
bool operator==(const Type &other) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
hboost::reverse_iterator< iterator > reverse_iterator
const_iterator find(const key_type &key) const
This & operator=(const SdfMapEditProxy< U, UVP > &other)
This & operator=(const Type &data)
#define PXR_NAMESPACE_CLOSE_SCOPE
std::unique_ptr< Sdf_MapEditor< T > > Sdf_CreateMapEditor(const SdfSpecHandle &owner, const TfToken &field)
bool operator>(const SdfMapEditProxy< U, UVP > &other) const
This & operator=(const This &other)
#define TF_FOR_ALL(iter, c)
static const Type & CanonicalizeType(const SdfSpecHandle &, const Type &x)
iterator upper_bound(const key_type &key)
reverse_iterator rbegin()
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Type::mapped_type mapped_type
static Vt_DefaultValueHolder Invoke()
const value_type & const_reference