mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Add getMemberConst() and getElementConst()
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <ArduinoJson/Configuration.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Variant/Converter.hpp>
|
||||
#include <ArduinoJson/Variant/VariantOperators.hpp>
|
||||
#include <ArduinoJson/Variant/VariantRef.hpp>
|
||||
#include <ArduinoJson/Variant/VariantShortcuts.hpp>
|
||||
@@ -35,7 +36,7 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
: _object(src._object), _key(src._key) {}
|
||||
|
||||
FORCE_INLINE operator VariantConstRef() const {
|
||||
return getUpstreamMember();
|
||||
return getUpstreamMemberConst();
|
||||
}
|
||||
|
||||
FORCE_INLINE this_type &operator=(const this_type &src) {
|
||||
@@ -64,12 +65,20 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
}
|
||||
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return getUpstreamMember().isNull();
|
||||
return getUpstreamMemberConst().isNull();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as()
|
||||
const {
|
||||
FORCE_INLINE typename enable_if<!is_same<T, char *>::value &&
|
||||
!ConverterNeedsWriteableRef<T>::value,
|
||||
T>::type
|
||||
as() const {
|
||||
return getUpstreamMemberConst().template as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
|
||||
as() const {
|
||||
return getUpstreamMember().template as<T>();
|
||||
}
|
||||
|
||||
@@ -82,20 +91,29 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE operator T() const {
|
||||
return getUpstreamMember();
|
||||
return as<T>();
|
||||
}
|
||||
|
||||
template <typename TValue>
|
||||
FORCE_INLINE bool is() const {
|
||||
return getUpstreamMember().template is<TValue>();
|
||||
template <typename T>
|
||||
FORCE_INLINE
|
||||
typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
|
||||
is() const {
|
||||
return getUpstreamMember().template is<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE
|
||||
typename enable_if<!ConverterNeedsWriteableRef<T>::value, bool>::type
|
||||
is() const {
|
||||
return getUpstreamMemberConst().template is<T>();
|
||||
}
|
||||
|
||||
FORCE_INLINE size_t size() const {
|
||||
return getUpstreamMember().size();
|
||||
return getUpstreamMemberConst().size();
|
||||
}
|
||||
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return getUpstreamMember().memoryUsage();
|
||||
return getUpstreamMemberConst().memoryUsage();
|
||||
}
|
||||
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
@@ -137,7 +155,7 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
|
||||
template <typename TVisitor>
|
||||
typename TVisitor::result_type accept(TVisitor &visitor) const {
|
||||
return getUpstreamMember().accept(visitor);
|
||||
return getUpstreamMemberConst().accept(visitor);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantRef addElement() const {
|
||||
@@ -148,6 +166,10 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return getUpstreamMember().getElement(index);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantConstRef getElementConst(size_t index) const {
|
||||
return getUpstreamMemberConst().getElementConst(index);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantRef getOrAddElement(size_t index) const {
|
||||
return getOrAddUpstreamMember().getOrAddElement(index);
|
||||
}
|
||||
@@ -167,6 +189,21 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return getUpstreamMember().getMember(key);
|
||||
}
|
||||
|
||||
// getMemberConst(char*) const
|
||||
// getMemberConst(const char*) const
|
||||
// getMemberConst(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE VariantConstRef getMemberConst(TChar *key) const {
|
||||
return getUpstreamMemberConst().getMemberConst(key);
|
||||
}
|
||||
|
||||
// getMemberConst(const std::string&) const
|
||||
// getMemberConst(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE VariantConstRef getMemberConst(const TString &key) const {
|
||||
return getUpstreamMemberConst().getMemberConst(key);
|
||||
}
|
||||
|
||||
// getOrAddMember(char*) const
|
||||
// getOrAddMember(const char*) const
|
||||
// getOrAddMember(const __FlashStringHelper*) const
|
||||
@@ -187,12 +224,16 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return _object.getMember(_key);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantConstRef getUpstreamMemberConst() const {
|
||||
return _object.getMemberConst(_key);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantRef getOrAddUpstreamMember() const {
|
||||
return _object.getOrAddMember(_key);
|
||||
}
|
||||
|
||||
friend void convertToJson(const this_type &src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamMember());
|
||||
dst.set(src.getUpstreamMemberConst());
|
||||
}
|
||||
|
||||
TObject _object;
|
||||
|
||||
@@ -40,14 +40,14 @@ template <typename TObject>
|
||||
template <typename TString>
|
||||
inline typename enable_if<IsString<TString>::value, bool>::type
|
||||
ObjectShortcuts<TObject>::containsKey(const TString& key) const {
|
||||
return !impl()->getMember(key).isUnbound();
|
||||
return !impl()->getMemberConst(key).isUnbound();
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
template <typename TChar>
|
||||
inline typename enable_if<IsString<TChar*>::value, bool>::type
|
||||
ObjectShortcuts<TObject>::containsKey(TChar* key) const {
|
||||
return !impl()->getMember(key).isUnbound();
|
||||
return !impl()->getMemberConst(key).isUnbound();
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
|
||||
@@ -81,7 +81,7 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
||||
// containsKey(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE bool containsKey(const TString& key) const {
|
||||
return !getMember(key).isUnbound();
|
||||
return !getMemberConst(key).isUnbound();
|
||||
}
|
||||
|
||||
// containsKey(char*) const
|
||||
@@ -89,22 +89,22 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
||||
// containsKey(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE bool containsKey(TChar* key) const {
|
||||
return !getMember(key).isUnbound();
|
||||
return !getMemberConst(key).isUnbound();
|
||||
}
|
||||
|
||||
// getMember(const std::string&) const
|
||||
// getMember(const String&) const
|
||||
// getMemberConst(const std::string&) const
|
||||
// getMemberConst(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE VariantConstRef getMember(const TString& key) const {
|
||||
return get_impl(adaptString(key));
|
||||
FORCE_INLINE VariantConstRef getMemberConst(const TString& key) const {
|
||||
return VariantConstRef(objectGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// getMember(char*) const
|
||||
// getMember(const char*) const
|
||||
// getMember(const __FlashStringHelper*) const
|
||||
// getMemberConst(char*) const
|
||||
// getMemberConst(const char*) const
|
||||
// getMemberConst(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE VariantConstRef getMember(TChar* key) const {
|
||||
return get_impl(adaptString(key));
|
||||
FORCE_INLINE VariantConstRef getMemberConst(TChar* key) const {
|
||||
return VariantConstRef(objectGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// operator[](const std::string&) const
|
||||
@@ -113,7 +113,7 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TString>::value, VariantConstRef>::type
|
||||
operator[](const TString& key) const {
|
||||
return get_impl(adaptString(key));
|
||||
return getMemberConst(key);
|
||||
}
|
||||
|
||||
// operator[](char*) const
|
||||
@@ -123,7 +123,7 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TChar*>::value, VariantConstRef>::type
|
||||
operator[](TChar* key) const {
|
||||
return get_impl(adaptString(key));
|
||||
return getMemberConst(key);
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator==(ObjectConstRef rhs) const {
|
||||
@@ -143,10 +143,6 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename TAdaptedString>
|
||||
FORCE_INLINE VariantConstRef get_impl(TAdaptedString key) const {
|
||||
return VariantConstRef(objectGetMember(_data, key));
|
||||
}
|
||||
};
|
||||
|
||||
class ObjectRef : public ObjectRefBase<CollectionData>,
|
||||
@@ -207,6 +203,21 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
|
||||
return VariantRef(_pool, objectGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// getMemberConst(const std::string&) const
|
||||
// getMemberConst(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE VariantConstRef getMemberConst(const TString& key) const {
|
||||
return VariantConstRef(objectGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// getMemberConst(char*) const
|
||||
// getMemberConst(const char*) const
|
||||
// getMemberConst(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE VariantConstRef getMemberConst(TChar* key) const {
|
||||
return VariantConstRef(objectGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// getOrAddMember(const std::string&) const
|
||||
// getOrAddMember(const String&) const
|
||||
template <typename TString>
|
||||
|
||||
Reference in New Issue
Block a user