7 #ifndef PXR_USD_SDF_MAP_EDIT_PROXY_H
8 #define PXR_USD_SDF_MAP_EDIT_PROXY_H
22 #include "pxr/base/tf/mallocTag.h"
100 template <
class T,
class _ValuePolicy = SdfIdentityMapEditProxyValuePolicy<T> >
130 typedef typename Type::iterator inner_iterator;
131 typedef typename Type::const_iterator const_inner_iterator;
135 _ValueProxy(
This* owner,
const Type*
data, inner_iterator i) :
136 _owner(owner), _data(data), _pos(i)
147 _owner->_Set(_data, _pos, other);
164 return _owner->_Get(_data, _pos);
175 explicit _PairProxy(
This* owner,
const Type*
data, inner_iterator i) :
176 first(i->
first), second(_ValueProxy(owner, data, i)) { }
194 static _PairProxy Dereference(
This* owner,
200 return _PairProxy(owner, data, i);
205 const_inner_iterator i)
210 return owner->_Get(data, i);
214 template <
class Owner,
class I,
class R>
218 std::add_pointer_t<R> operator->() {
219 return std::addressof(_result);
222 friend class _Iterator;
223 explicit _PtrProxy(
const R&
result) : _result(result) {}
227 using iterator_category = std::bidirectional_iterator_tag;
231 std::add_pointer_t<R>, _PtrProxy>;
234 _Iterator() =
default;
236 _Iterator(Owner owner,
const Type* data, I i) :
237 _owner(owner), _data(data), _pos(i)
242 template <
class Owner2,
class I2,
class R2>
243 _Iterator(
const _Iterator<Owner2, I2, R2>& other) :
244 _owner(other._owner), _data(other._data), _pos(other._pos)
255 template <
typename PointerType=
pointer,
258 pointer operator->()
const {
return std::addressof(dereference()); }
259 template <
typename PointerType=
pointer,
265 const I& base()
const
270 _Iterator& operator++() {
275 _Iterator& operator--() {
280 _Iterator operator++(
int) {
286 _Iterator operator--(
int) {
292 template <
class Owner2,
class I2,
class R2>
293 bool operator==(
const _Iterator<Owner2, I2, R2>& other)
const {
297 template <
class Owner2,
class I2,
class R2>
298 bool operator!=(
const _Iterator<Owner2, I2, R2>& other)
const {
299 return !
equal(other);
303 R dereference()
const
305 return Traits::Dereference(_owner, _data, _pos);
308 template <
class Owner2,
class I2,
class R2>
309 bool equal(
const _Iterator<Owner2, I2, R2>& other)
const
311 if (_owner == other._owner && _pos == other._pos) {
316 return atEnd() && other.atEnd();
330 return !_owner || _pos == _owner->_ConstData()->end();
334 Owner _owner =
nullptr;
335 const Type* _data =
nullptr;
338 template <
class Owner2,
class I2,
class R2>
friend class _Iterator;
346 typedef _Iterator<This*, inner_iterator, _PairProxy>
iterator;
347 typedef _Iterator<
const This*, const_inner_iterator,
365 if (other._Validate()) {
366 _Copy(*other._ConstData());
371 template <
class U,
class UVP>
374 if (other._Validate()) {
375 _Copy(
Type(other._ConstData()->begin(), other._ConstData()->end()));
389 return _Validate() ? *_ConstData() :
Type();
394 return _Validate() ?
iterator(
this, _Data(), _Data()->
begin()) :
399 return _Validate() ?
iterator(
this, _Data(), _Data()->
end()) :
434 return _Validate() ? _ConstData()->size() : 0;
439 return _Validate() ? _ConstData()->max_size() : 0;
444 return _Validate() ? _ConstData()->empty() :
true;
449 return _Insert(value);
454 return _Insert(value).first;
457 template <
class InputIterator>
464 ValuePolicy::CanonicalizePair(_Owner(), *first);
466 if (_ValidateInsert(v)) {
475 if (_Validate() && _ValidateErase(pos->first)) {
483 const key_type& k = ValuePolicy::CanonicalizeKey(_Owner(), key);
484 if (_ValidateErase(k)) {
485 return _editor->Erase(k) ? 1 : 0;
495 while (first != last) {
498 if (_ValidateErase(key)) {
515 _Data()->
find(ValuePolicy::CanonicalizeKey(_Owner(), key))) :
525 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
534 ValuePolicy::CanonicalizeKey(_Owner(), key)) :
544 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
554 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
564 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
574 ValuePolicy::CanonicalizeKey(_Owner(), key))) :
581 std::pair<inner_iterator, inner_iterator>
result =
582 _Data()->equal_range(
583 ValuePolicy::CanonicalizeKey(_Owner(), key));
584 return std::make_pair(
iterator(
this, _Data(), result.first),
585 iterator(
this, _Data(), result.second));
592 std::pair<const_iterator,const_iterator>
596 std::pair<const_inner_iterator, const_inner_iterator>
result =
597 _ConstData()->equal_range(
598 ValuePolicy::CanonicalizeKey(_Owner(), key));
599 return std::make_pair(
612 return reference(failed ?
nullptr :
this,
613 failed ?
nullptr : _Data(),
619 return _Validate() ? _CompareEqual(other) :
false;
624 return !(*
this == other);
641 return !_Validate() || _Compare(other) < 0;
646 return _Validate() ? _Compare(other) > 0 :
false;
651 return !(*
this < other);
656 return !(*
this > other);
681 template <
class U,
class UVP>
684 const bool isValid = _Validate();
685 const bool otherIsValid = other._Validate();
687 return isValid && otherIsValid ?
688 _CompareEqual(*other._ConstData()) : isValid == otherIsValid;
691 template <
class U,
class UVP>
694 return !(*
this == other);
697 template <
class U,
class UVP>
698 bool operator<(const SdfMapEditProxy<U, UVP>& other)
const
700 return _Validate() && other._Validate() ?
701 _Compare(*other._ConstData()) < 0 :
false;
704 template <
class U,
class UVP>
705 bool operator<=(const SdfMapEditProxy<U, UVP>& other)
const
707 return _Validate() && other._Validate() ?
708 _Compare(*other._ConstData()) <= 0 :
false;
711 template <
class U,
class UVP>
714 return !(*
this <= other);
717 template <
class U,
class UVP>
720 return !(*
this < other);
727 return _editor && _editor->IsExpired();
749 bool _Validate()
const
762 return _editor ? _editor->GetData() : NULL;
765 const Type* _ConstData()
const
767 return _editor ? _editor->GetData() : NULL;
770 SdfSpecHandle _Owner()
const
772 return _editor ? _editor->GetOwner() : SdfSpecHandle();
775 std::string _Location()
const
777 return _editor ? _editor->GetLocation() : std::string();
780 bool _CompareEqual(
const Type& other)
const
782 if (_ConstData()->
size() < other.size()) {
785 if (_ConstData()->size() > other.size()) {
790 const Type&
x = ValuePolicy::CanonicalizeType(_Owner(), other);
791 std::pair<const_inner_iterator, const_inner_iterator>
result =
792 std::mismatch(_ConstData()->
begin(), _ConstData()->
end(),
794 return result.first == _ConstData()->end();
797 int _Compare(
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 if (*result.first < *result.second) {
814 else if (*result.first > *result.second) {
823 bool _CompareEqual(
const D& other)
const
826 return _CompareEqual(
Type(other.begin(), other.end()));
830 int _Compare(
const D& other)
const
833 return _Compare(
Type(other.begin(), other.end()));
839 if (data == _ConstData()) {
845 return _ConstData()->find(i->first)->second;
852 const const_inner_iterator& i)
const
856 return (data == _ConstData()) ? *i : *_ConstData()->find(i->first);
859 void _Copy(
const Type& other)
870 ValuePolicy::CanonicalizePair(_Owner(), *it);
871 if (!canonicalOther.insert(canonicalValue).second) {
880 if (_ValidateCopy(canonicalOther)) {
881 _editor->Copy(canonicalOther);
886 bool _ValidateCopy(
const Type& other)
888 SdfSpecHandle owner = _Owner();
889 if (owner && !owner->PermissionToEdit()) {
891 _Location().
c_str());
900 if (!_ValidateInsert(*it)) {
909 void _Set(
const Type* data,
const inner_iterator& i,
const U&
value)
913 ValuePolicy::CanonicalizeValue(_Owner(), value);
914 if (_ValidateSet(i->first, x)) {
915 _editor->Set(i->first, x);
922 SdfSpecHandle owner = _Owner();
923 if (owner && !owner->PermissionToEdit()) {
925 _Location().
c_str());
929 if (
SdfAllowed allowed = _editor->IsValidValue(value)) {
935 allowed.GetWhyNot().c_str());
942 std::pair<iterator, bool> _Insert(
const value_type& value)
945 const value_type&
v = ValuePolicy::CanonicalizePair(_Owner(), value);
946 if (_ValidateInsert(v)) {
947 std::pair<inner_iterator, bool> status = _editor->Insert(v);
948 return std::make_pair(
iterator(
this, _Data(), status.first),
952 return std::make_pair(
iterator(),
false);
955 return std::make_pair(
iterator(),
false);
960 SdfSpecHandle owner = _Owner();
961 if (owner && !owner->PermissionToEdit()) {
963 _Location().
c_str());
967 if (
SdfAllowed allowed = _editor->IsValidKey(value.first)) {
973 allowed.GetWhyNot().c_str());
977 if (
SdfAllowed allowed = _editor->IsValidValue(value.second)) {
983 allowed.GetWhyNot().c_str());
992 if (_Validate() && _ValidateErase(key)) {
997 bool _ValidateErase(
const key_type& key)
999 SdfSpecHandle owner = _Owner();
1000 if (owner && !owner->PermissionToEdit()) {
1002 _Location().
c_str());
1012 std::shared_ptr<Sdf_MapEditor<T> > _editor;
1016 template <
class T,
class _ValuePolicy>
1023 #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 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)
OIIO_UTIL_API const char * c_str(string_view str)
#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