Changed the array subscript to automatically add missing elements

This commit is contained in:
Benoit Blanchon
2020-02-20 08:59:25 +01:00
parent 0001dabfd1
commit d8724e0a0b
24 changed files with 209 additions and 93 deletions

View File

@@ -28,7 +28,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
: _array(src._array), _index(src._index) {}
FORCE_INLINE this_type& operator=(const this_type& src) {
getUpstreamElement().set(src.as<VariantConstRef>());
getOrAddUpstreamElement().set(src.as<VariantConstRef>());
return *this;
}
@@ -39,7 +39,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
// std::string, String, ArrayRef, ObjectRef
template <typename T>
FORCE_INLINE this_type& operator=(const T& src) {
getUpstreamElement().set(src);
getOrAddUpstreamElement().set(src);
return *this;
}
//
@@ -47,7 +47,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
// TValue = char*, const char*, const __FlashStringHelper*
template <typename T>
FORCE_INLINE this_type& operator=(T* src) {
getUpstreamElement().set(src);
getOrAddUpstreamElement().set(src);
return *this;
}
@@ -79,7 +79,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
template <typename T>
FORCE_INLINE typename VariantTo<T>::type to() const {
return getUpstreamElement().template to<T>();
return getOrAddUpstreamElement().template to<T>();
}
// Replaces the value
@@ -89,14 +89,14 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
// std::string, String, ArrayRef, ObjectRef
template <typename TValue>
FORCE_INLINE bool set(const TValue& value) const {
return getUpstreamElement().set(value);
return getOrAddUpstreamElement().set(value);
}
//
// bool set(TValue)
// TValue = char*, const char*, const __FlashStringHelper*
template <typename TValue>
FORCE_INLINE bool set(TValue* value) const {
return getUpstreamElement().set(value);
return getOrAddUpstreamElement().set(value);
}
template <typename Visitor>
@@ -120,20 +120,20 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
template <typename TNestedKey>
VariantRef getOrAddMember(TNestedKey* key) const {
return getUpstreamElement().getOrAddMember(key);
return getOrAddUpstreamElement().getOrAddMember(key);
}
template <typename TNestedKey>
VariantRef getOrAddMember(const TNestedKey& key) const {
return getUpstreamElement().getOrAddMember(key);
return getOrAddUpstreamElement().getOrAddMember(key);
}
VariantRef addElement() const {
return getUpstreamElement().addElement();
return getOrAddUpstreamElement().addElement();
}
VariantRef getElement(size_t index) const {
return getUpstreamElement().getElement(index);
return getOrAddUpstreamElement().getElement(index);
}
FORCE_INLINE void remove(size_t index) const {
@@ -160,6 +160,10 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
return _array.getElement(_index);
}
FORCE_INLINE VariantRef getOrAddUpstreamElement() const {
return _array.getOrAddElement(_index);
}
TArray _array;
const size_t _index;
};