24 #ifndef PXR_USD_SDF_MAP_EDIT_PROXY_H
25 #define PXR_USD_SDF_MAP_EDIT_PROXY_H
39 #include "pxr/base/tf/mallocTag.h"
117 template <
class T,
class _ValuePolicy = SdfIdentityMapEditProxyValuePolicy<T> >
147 typedef typename Type::iterator inner_iterator;
148 typedef typename Type::const_iterator const_inner_iterator;
152 _ValueProxy(
This* owner,
const Type*
data, inner_iterator i) :
153 _owner(owner), _data(data), _pos(i)
164 _owner->_Set(_data, _pos, other);
181 return _owner->_Get(_data, _pos);
192 explicit _PairProxy(
This* owner,
const Type*
data, inner_iterator i) :
193 first(i->
first), second(_ValueProxy(owner, data, i)) { }
211 static _PairProxy Dereference(
This* owner,
217 return _PairProxy(owner, data, i);
222 const_inner_iterator i)
227 return owner->_Get(data, i);
231 template <
class Owner,
class I,
class R>
235 std::add_pointer_t<R> operator->() {
236 return std::addressof(_result);
239 friend class _Iterator;
240 explicit _PtrProxy(
const R&
result) : _result(result) {}
244 using iterator_category = std::bidirectional_iterator_tag;
248 std::add_pointer_t<R>, _PtrProxy>;
251 _Iterator() =
default;
253 _Iterator(Owner owner,
const Type* data, I i) :
254 _owner(owner), _data(data), _pos(i)
259 template <
class Owner2,
class I2,
class R2>
260 _Iterator(
const _Iterator<Owner2, I2, R2>& other) :
261 _owner(other._owner), _data(other._data), _pos(other._pos)
272 template <
typename PointerType=
pointer,
275 pointer operator->()
const {
return std::addressof(dereference()); }
276 template <
typename PointerType=
pointer,
282 const I& base()
const
287 _Iterator& operator++() {
292 _Iterator& operator--() {
297 _Iterator operator++(
int) {
303 _Iterator operator--(
int) {
309 template <
class Owner2,
class I2,
class R2>
310 bool operator==(
const _Iterator<Owner2, I2, R2>& other)
const {
314 template <
class Owner2,
class I2,
class R2>
315 bool operator!=(
const _Iterator<Owner2, I2, R2>& other)
const {
316 return !
equal(other);
320 R dereference()
const
322 return Traits::Dereference(_owner, _data, _pos);
325 template <
class Owner2,
class I2,
class R2>
326 bool equal(
const _Iterator<Owner2, I2, R2>& other)
const
328 if (_owner == other._owner && _pos == other._pos) {
333 return atEnd() && other.atEnd();
347 return !_owner || _pos == _owner->_ConstData()->end();
351 Owner _owner =
nullptr;
352 const Type* _data =
nullptr;
355 template <
class Owner2,
class I2,
class R2>
friend class _Iterator;
363 typedef _Iterator<This*, inner_iterator, _PairProxy>
iterator;
364 typedef _Iterator<
const This*, const_inner_iterator,
382 if (other._Validate()) {
383 _Copy(*other._ConstData());
388 template <
class U,
class UVP>
391 if (other._Validate()) {
392 _Copy(
Type(other._ConstData()->begin(), other._ConstData()->end()));
406 return _Validate() ? *_ConstData() :
Type();
411 return _Validate() ?
iterator(
this, _Data(), _Data()->
begin()) :
416 return _Validate() ?
iterator(
this, _Data(), _Data()->
end()) :
451 return _Validate() ? _ConstData()->size() : 0;
456 return _Validate() ? _ConstData()->max_size() : 0;
461 return _Validate() ? _ConstData()->empty() :
true;
466 return _Insert(value);
471 return _Insert(value).first;
474 template <
class InputIterator>
481 ValuePolicy::CanonicalizePair(_Owner(), *first);
483 if (_ValidateInsert(v)) {
492 if (_Validate() && _ValidateErase(pos->first)) {
500 const key_type& k = ValuePolicy::CanonicalizeKey(_Owner(), key);
501 if (_ValidateErase(k)) {
502 return _editor->Erase(k) ? 1 : 0;
512 while (first != last) {
515 if (_ValidateErase(key)) {
532 _Data()->
find(ValuePolicy::CanonicalizeKey(_Owner(), key))) :
542 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
551 ValuePolicy::CanonicalizeKey(_Owner(), key)) :
561 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
571 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
581 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
591 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
598 std::pair<inner_iterator, inner_iterator>
result =
599 _Data()->equal_range(
600 ValuePolicy::CanonicalizeKey(_Owner(), key));
601 return std::make_pair(
iterator(
this, _Data(), result.first),
602 iterator(
this, _Data(), result.second));
609 std::pair<const_iterator,const_iterator>
613 std::pair<const_inner_iterator, const_inner_iterator>
result =
614 _ConstData()->equal_range(
615 ValuePolicy::CanonicalizeKey(_Owner(), key));
616 return std::make_pair(
629 return reference(failed ?
nullptr :
this,
630 failed ?
nullptr : _Data(),
636 return _Validate() ? _CompareEqual(other) :
false;
641 return !(*
this == other);
658 return !_Validate() || _Compare(other) < 0;
663 return _Validate() ? _Compare(other) > 0 :
false;
668 return !(*
this < other);
673 return !(*
this > other);
698 template <
class U,
class UVP>
701 const bool isValid = _Validate();
702 const bool otherIsValid = other._Validate();
704 return isValid && otherIsValid ?
705 _CompareEqual(*other._ConstData()) : isValid == otherIsValid;
708 template <
class U,
class UVP>
711 return !(*
this == other);
714 template <
class U,
class UVP>
715 bool operator<(const SdfMapEditProxy<U, UVP>& other)
const
717 return _Validate() && other._Validate() ?
718 _Compare(*other._ConstData()) < 0 :
false;
721 template <
class U,
class UVP>
722 bool operator<=(const SdfMapEditProxy<U, UVP>& other)
const
724 return _Validate() && other._Validate() ?
725 _Compare(*other._ConstData()) <= 0 :
false;
728 template <
class U,
class UVP>
731 return !(*
this <= other);
734 template <
class U,
class UVP>
737 return !(*
this < other);
744 return _editor && _editor->IsExpired();
749 explicit operator bool()
const
766 bool _Validate()
const
779 return _editor ? _editor->GetData() : NULL;
782 const Type* _ConstData()
const
784 return _editor ? _editor->GetData() : NULL;
787 SdfSpecHandle _Owner()
const
789 return _editor ? _editor->GetOwner() : SdfSpecHandle();
794 return _editor ? _editor->GetLocation() :
std::string();
797 bool _CompareEqual(
const Type& other)
const
799 if (_ConstData()->
size() < other.size()) {
802 if (_ConstData()->size() > other.size()) {
807 const Type&
x = ValuePolicy::CanonicalizeType(_Owner(), other);
808 std::pair<const_inner_iterator, const_inner_iterator>
result =
809 std::mismatch(_ConstData()->
begin(), _ConstData()->
end(),
811 return result.first == _ConstData()->end();
814 int _Compare(
const Type& other)
const
816 if (_ConstData()->
size() < other.size()) {
819 if (_ConstData()->size() > other.size()) {
824 const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
825 std::pair<const_inner_iterator, const_inner_iterator> result =
826 std::mismatch(_ConstData()->
begin(), _ConstData()->
end(),
828 if (*result.first < *result.second) {
831 else if (*result.first > *result.second) {
840 bool _CompareEqual(
const D& other)
const
843 return _CompareEqual(
Type(other.begin(), other.end()));
847 int _Compare(
const D& other)
const
850 return _Compare(
Type(other.begin(), other.end()));
856 if (data == _ConstData()) {
862 return _ConstData()->find(i->first)->second;
869 const const_inner_iterator& i)
const
873 return (data == _ConstData()) ? *i : *_ConstData()->find(i->first);
876 void _Copy(
const Type& other)
887 ValuePolicy::CanonicalizePair(_Owner(), *it);
888 if (!canonicalOther.insert(canonicalValue).second) {
897 if (_ValidateCopy(canonicalOther)) {
898 _editor->Copy(canonicalOther);
903 bool _ValidateCopy(
const Type& other)
905 SdfSpecHandle owner = _Owner();
906 if (owner && !owner->PermissionToEdit()) {
908 _Location().c_str());
917 if (!_ValidateInsert(*it)) {
926 void _Set(
const Type* data,
const inner_iterator& i,
const U&
value)
930 ValuePolicy::CanonicalizeValue(_Owner(), value);
931 if (_ValidateSet(i->first, x)) {
932 _editor->Set(i->first, x);
939 SdfSpecHandle owner = _Owner();
940 if (owner && !owner->PermissionToEdit()) {
942 _Location().c_str());
946 if (
SdfAllowed allowed = _editor->IsValidValue(value)) {
952 allowed.GetWhyNot().c_str());
959 std::pair<iterator, bool> _Insert(
const value_type& value)
962 const value_type&
v = ValuePolicy::CanonicalizePair(_Owner(), value);
963 if (_ValidateInsert(v)) {
964 std::pair<inner_iterator, bool> status = _editor->Insert(v);
965 return std::make_pair(
iterator(
this, _Data(), status.first),
969 return std::make_pair(
iterator(),
false);
972 return std::make_pair(
iterator(),
false);
977 SdfSpecHandle owner = _Owner();
978 if (owner && !owner->PermissionToEdit()) {
980 _Location().c_str());
984 if (
SdfAllowed allowed = _editor->IsValidKey(value.first)) {
990 allowed.GetWhyNot().c_str());
994 if (
SdfAllowed allowed = _editor->IsValidValue(value.second)) {
1000 allowed.GetWhyNot().c_str());
1009 if (_Validate() && _ValidateErase(key)) {
1010 _editor->Erase(key);
1014 bool _ValidateErase(
const key_type& key)
1016 SdfSpecHandle owner = _Owner();
1017 if (owner && !owner->PermissionToEdit()) {
1019 _Location().c_str());
1029 std::shared_ptr<Sdf_MapEditor<T> > _editor;
1033 template <
class T,
class _ValuePolicy>
1040 #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)
typename std::enable_if< B, T >::type enable_if_t
Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
bool operator>=(const SdfMapEditProxy< U, UVP > &other) const
friend bool operator!=(const Type &lhs, const SdfMapEditProxy &rhs)
Type::value_type value_type
size_type erase(const key_type &key)
bool operator<(const Type &other) const
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
bool operator>=(const Type &other) const
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
friend bool operator<(const Type &lhs, const SdfMapEditProxy &rhs)
Type::value_type value_type
bool operator>(const Type &other) const
const_iterator lower_bound(const key_type &key) const
friend bool operator<=(const Type &lhs, const SdfMapEditProxy &rhs)
const_iterator begin() const
Type::mapped_type mapped_type
const_reverse_iterator rend() const
size_type max_size() const
friend bool operator>=(const Type &lhs, const SdfMapEditProxy &rhs)
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
bool operator<=(const Type &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)
friend bool operator==(const Type &lhs, const SdfMapEditProxy &rhs)
reference operator[](const key_type &key)
std::string TfStringify(const T &v)
IMATH_HOSTDEVICE constexpr Color4< T > operator*(S a, const Color4< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Color4.
_Iterator< This *, inner_iterator, _PairProxy > iterator
SdfMapEditProxy(const SdfSpecHandle &owner, const TfToken &field)
const_iterator end() const
iterator find(const key_type &key)
Tf_ProxyReferenceReverseIterator< const_iterator > const_reverse_iterator
__hostdev__ uint64_t last(uint32_t i) const
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
friend bool operator>(const Type &lhs, const SdfMapEditProxy &rhs)
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()
Type::mapped_type mapped_type
Tf_ProxyReferenceReverseIterator< iterator > reverse_iterator
bool operator!=(const Type &other) const
static Vt_DefaultValueHolder Invoke()
const value_type & const_reference