forked from bblanchon/ArduinoJson
Disambiguated the name get()
with getElement()
and getMember()
This commit is contained in:
@ -9,6 +9,10 @@ HEAD
|
|||||||
* Add option ARDUINOJSON_DECODE_UNICODE to enable it
|
* Add option ARDUINOJSON_DECODE_UNICODE to enable it
|
||||||
* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()`
|
* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()`
|
||||||
* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()`
|
* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()`
|
||||||
|
* Renamed `JsonArray::get()` to `getElement()`
|
||||||
|
* Renamed `JsonArray::add()` (without arg) to `addElement()`
|
||||||
|
* Renamed `JsonObject::get()` to `getMember()`
|
||||||
|
* Renamed `JsonObject::getOrCreate()` to `getOrAddMember()`
|
||||||
|
|
||||||
v6.8.0-beta (2019-01-30)
|
v6.8.0-beta (2019-01-30)
|
||||||
-----------
|
-----------
|
||||||
|
@ -11,12 +11,12 @@ namespace ARDUINOJSON_NAMESPACE {
|
|||||||
|
|
||||||
template <typename TArray>
|
template <typename TArray>
|
||||||
inline ArrayRef ArrayShortcuts<TArray>::createNestedArray() const {
|
inline ArrayRef ArrayShortcuts<TArray>::createNestedArray() const {
|
||||||
return impl()->add().template to<ArrayRef>();
|
return impl()->addElement().template to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TArray>
|
template <typename TArray>
|
||||||
inline ObjectRef ArrayShortcuts<TArray>::createNestedObject() const {
|
inline ObjectRef ArrayShortcuts<TArray>::createNestedObject() const {
|
||||||
return impl()->add().template to<ObjectRef>();
|
return impl()->addElement().template to<ObjectRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ARDUINOJSON_NAMESPACE
|
} // namespace ARDUINOJSON_NAMESPACE
|
||||||
|
@ -101,8 +101,7 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
|
|||||||
return ArrayConstRef(_data);
|
return ArrayConstRef(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ArrayShortcuts::add;
|
VariantRef addElement() const {
|
||||||
VariantRef add() const {
|
|
||||||
return VariantRef(_pool, arrayAdd(_data, _pool));
|
return VariantRef(_pool, arrayAdd(_data, _pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +125,7 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gets the value at the specified index.
|
// Gets the value at the specified index.
|
||||||
FORCE_INLINE VariantRef get(size_t index) const {
|
FORCE_INLINE VariantRef getElement(size_t index) const {
|
||||||
return VariantRef(_pool, _data ? _data->get(index) : 0);
|
return VariantRef(_pool, _data ? _data->get(index) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ class ArrayShortcuts {
|
|||||||
// std::string, String, ObjectRef
|
// std::string, String, ObjectRef
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE bool add(const T &value) const {
|
FORCE_INLINE bool add(const T &value) const {
|
||||||
return impl()->add().set(value);
|
return impl()->addElement().set(value);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// bool add(TValue);
|
// bool add(TValue);
|
||||||
// TValue = char*, const char*, const __FlashStringHelper*
|
// TValue = char*, const char*, const __FlashStringHelper*
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE bool add(T *value) const {
|
FORCE_INLINE bool add(T *value) const {
|
||||||
return impl()->add().set(value);
|
return impl()->addElement().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -24,7 +24,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
|||||||
: _array(array), _index(index) {}
|
: _array(array), _index(index) {}
|
||||||
|
|
||||||
FORCE_INLINE this_type& operator=(const this_type& src) {
|
FORCE_INLINE this_type& operator=(const this_type& src) {
|
||||||
getElement().set(src.as<VariantConstRef>());
|
getUpstreamElement().set(src.as<VariantConstRef>());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
|||||||
// std::string, String, ArrayRef, ObjectRef
|
// std::string, String, ArrayRef, ObjectRef
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE this_type& operator=(const T& src) {
|
FORCE_INLINE this_type& operator=(const T& src) {
|
||||||
getElement().set(src);
|
getUpstreamElement().set(src);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
@ -43,27 +43,27 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
|||||||
// TValue = char*, const char*, const __FlashStringHelper*
|
// TValue = char*, const char*, const __FlashStringHelper*
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE this_type& operator=(T* src) {
|
FORCE_INLINE this_type& operator=(T* src) {
|
||||||
getElement().set(src);
|
getUpstreamElement().set(src);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE bool isNull() const {
|
FORCE_INLINE bool isNull() const {
|
||||||
return getElement().isNull();
|
return getUpstreamElement().isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE typename VariantAs<T>::type as() const {
|
FORCE_INLINE typename VariantAs<T>::type as() const {
|
||||||
return getElement().template as<T>();
|
return getUpstreamElement().template as<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE bool is() const {
|
FORCE_INLINE bool is() const {
|
||||||
return getElement().template is<T>();
|
return getUpstreamElement().template is<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FORCE_INLINE typename VariantTo<T>::type to() const {
|
FORCE_INLINE typename VariantTo<T>::type to() const {
|
||||||
return getElement().template to<T>();
|
return getUpstreamElement().template to<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replaces the value
|
// Replaces the value
|
||||||
@ -73,53 +73,56 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
|||||||
// std::string, String, ArrayRef, ObjectRef
|
// std::string, String, ArrayRef, ObjectRef
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE bool set(const TValue& value) const {
|
FORCE_INLINE bool set(const TValue& value) const {
|
||||||
return getElement().set(value);
|
return getUpstreamElement().set(value);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// bool set(TValue)
|
// bool set(TValue)
|
||||||
// TValue = char*, const char*, const __FlashStringHelper*
|
// TValue = char*, const char*, const __FlashStringHelper*
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE bool set(TValue* value) const {
|
FORCE_INLINE bool set(TValue* value) const {
|
||||||
return getElement().set(value);
|
return getUpstreamElement().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Visitor>
|
template <typename Visitor>
|
||||||
void accept(Visitor& visitor) const {
|
void accept(Visitor& visitor) const {
|
||||||
return getElement().accept(visitor);
|
return getUpstreamElement().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE size_t size() const {
|
FORCE_INLINE size_t size() const {
|
||||||
return getElement().size();
|
return getUpstreamElement().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TNestedKey>
|
template <typename TNestedKey>
|
||||||
VariantRef get(TNestedKey* key) const {
|
VariantRef getMember(TNestedKey* key) const {
|
||||||
return getElement().get(key);
|
return getUpstreamElement().getMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TNestedKey>
|
template <typename TNestedKey>
|
||||||
VariantRef get(const TNestedKey& key) const {
|
VariantRef getMember(const TNestedKey& key) const {
|
||||||
return getElement().get(key);
|
return getUpstreamElement().getMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TNestedKey>
|
template <typename TNestedKey>
|
||||||
VariantRef getOrCreate(TNestedKey* key) const {
|
VariantRef getOrAddMember(TNestedKey* key) const {
|
||||||
return getElement().getOrCreate(key);
|
return getUpstreamElement().getOrAddMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TNestedKey>
|
template <typename TNestedKey>
|
||||||
VariantRef getOrCreate(const TNestedKey& key) const {
|
VariantRef getOrAddMember(const TNestedKey& key) const {
|
||||||
return getElement().getOrCreate(key);
|
return getUpstreamElement().getOrAddMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ArrayShortcuts<ElementProxy>::add;
|
VariantRef addElement() const {
|
||||||
VariantRef add() const {
|
return getUpstreamElement().addElement();
|
||||||
return getElement().add();
|
}
|
||||||
|
|
||||||
|
VariantRef getElement(size_t index) const {
|
||||||
|
return getUpstreamElement().getElement(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FORCE_INLINE VariantRef getElement() const {
|
FORCE_INLINE VariantRef getUpstreamElement() const {
|
||||||
return _array.get(_index);
|
return _array.getElement(_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
TArray _array;
|
TArray _array;
|
||||||
|
@ -83,7 +83,7 @@ class JsonDocument : public Visitable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef createNestedArray() {
|
ArrayRef createNestedArray() {
|
||||||
return add().to<ArrayRef>();
|
return addElement().to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// createNestedArray(char*)
|
// createNestedArray(char*)
|
||||||
@ -91,18 +91,18 @@ class JsonDocument : public Visitable {
|
|||||||
// createNestedArray(const __FlashStringHelper*)
|
// createNestedArray(const __FlashStringHelper*)
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
ArrayRef createNestedArray(TChar* key) {
|
ArrayRef createNestedArray(TChar* key) {
|
||||||
return getOrCreate(key).template to<ArrayRef>();
|
return getOrAddMember(key).template to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// createNestedArray(const std::string&)
|
// createNestedArray(const std::string&)
|
||||||
// createNestedArray(const String&)
|
// createNestedArray(const String&)
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
ArrayRef createNestedArray(const TString& key) {
|
ArrayRef createNestedArray(const TString& key) {
|
||||||
return getOrCreate(key).template to<ArrayRef>();
|
return getOrAddMember(key).template to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectRef createNestedObject() {
|
ObjectRef createNestedObject() {
|
||||||
return add().to<ObjectRef>();
|
return addElement().to<ObjectRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// createNestedObject(char*)
|
// createNestedObject(char*)
|
||||||
@ -110,14 +110,14 @@ class JsonDocument : public Visitable {
|
|||||||
// createNestedObject(const __FlashStringHelper*)
|
// createNestedObject(const __FlashStringHelper*)
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
ObjectRef createNestedObject(TChar* key) {
|
ObjectRef createNestedObject(TChar* key) {
|
||||||
return getOrCreate(key).template to<ObjectRef>();
|
return getOrAddMember(key).template to<ObjectRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// createNestedObject(const std::string&)
|
// createNestedObject(const std::string&)
|
||||||
// createNestedObject(const String&)
|
// createNestedObject(const String&)
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
ObjectRef createNestedObject(const TString& key) {
|
ObjectRef createNestedObject(const TString& key) {
|
||||||
return getOrCreate(key).template to<ObjectRef>();
|
return getOrAddMember(key).template to<ObjectRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator[](const std::string&)
|
// operator[](const std::string&)
|
||||||
@ -164,51 +164,51 @@ class JsonDocument : public Visitable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE VariantConstRef operator[](size_t index) const {
|
FORCE_INLINE VariantConstRef operator[](size_t index) const {
|
||||||
return VariantConstRef(_data.get(index));
|
return VariantConstRef(_data.getElement(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE VariantRef get(size_t index) {
|
FORCE_INLINE VariantRef getElement(size_t index) {
|
||||||
return VariantRef(&_pool, _data.get(index));
|
return VariantRef(&_pool, _data.getElement(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(char*) const
|
// getMember(char*) const
|
||||||
// get(const char*) const
|
// getMember(const char*) const
|
||||||
// get(const __FlashStringHelper*) const
|
// getMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef get(TChar* key) {
|
FORCE_INLINE VariantRef getMember(TChar* key) {
|
||||||
return VariantRef(&_pool, _data.get(adaptString(key)));
|
return VariantRef(&_pool, _data.getMember(adaptString(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(const std::string&) const
|
// getMember(const std::string&) const
|
||||||
// get(const String&) const
|
// getMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type
|
FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type
|
||||||
get(const TString& key) {
|
getMember(const TString& key) {
|
||||||
return VariantRef(&_pool, _data.get(adaptString(key)));
|
return VariantRef(&_pool, _data.getMember(adaptString(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(char*)
|
// getOrAddMember(char*)
|
||||||
// getOrCreate(const char*)
|
// getOrAddMember(const char*)
|
||||||
// getOrCreate(const __FlashStringHelper*)
|
// getOrAddMember(const __FlashStringHelper*)
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef getOrCreate(TChar* key) {
|
FORCE_INLINE VariantRef getOrAddMember(TChar* key) {
|
||||||
return VariantRef(&_pool, _data.getOrCreate(adaptString(key), &_pool));
|
return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(const std::string&)
|
// getOrAddMember(const std::string&)
|
||||||
// getOrCreate(const String&)
|
// getOrAddMember(const String&)
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef getOrCreate(const TString& key) {
|
FORCE_INLINE VariantRef getOrAddMember(const TString& key) {
|
||||||
return VariantRef(&_pool, _data.getOrCreate(adaptString(key), &_pool));
|
return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE VariantRef add() {
|
FORCE_INLINE VariantRef addElement() {
|
||||||
return VariantRef(&_pool, _data.add(&_pool));
|
return VariantRef(&_pool, _data.addElement(&_pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE bool add(const TValue& value) {
|
FORCE_INLINE bool add(const TValue& value) {
|
||||||
return add().set(value);
|
return addElement().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add(char*) const
|
// add(char*) const
|
||||||
@ -216,7 +216,7 @@ class JsonDocument : public Visitable {
|
|||||||
// add(const __FlashStringHelper*) const
|
// add(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE bool add(TChar* value) {
|
FORCE_INLINE bool add(TChar* value) {
|
||||||
return add().set(value);
|
return addElement().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -25,18 +25,18 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
|||||||
: _object(variant), _key(key) {}
|
: _object(variant), _key(key) {}
|
||||||
|
|
||||||
FORCE_INLINE operator VariantConstRef() const {
|
FORCE_INLINE operator VariantConstRef() const {
|
||||||
return getMember();
|
return getUpstreamMember();
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE this_type &operator=(const this_type &src) {
|
FORCE_INLINE this_type &operator=(const this_type &src) {
|
||||||
getOrCreateMember().set(src);
|
getOrAddUpstreamMember().set(src);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type
|
FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type
|
||||||
operator=(const TValue &src) {
|
operator=(const TValue &src) {
|
||||||
getOrCreateMember().set(src);
|
getOrAddUpstreamMember().set(src);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,33 +45,33 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
|||||||
// operator=(const __FlashStringHelper*) const
|
// operator=(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE this_type &operator=(TChar *src) {
|
FORCE_INLINE this_type &operator=(TChar *src) {
|
||||||
getOrCreateMember().set(src);
|
getOrAddUpstreamMember().set(src);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE bool isNull() const {
|
FORCE_INLINE bool isNull() const {
|
||||||
return getMember().isNull();
|
return getUpstreamMember().isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE typename VariantAs<TValue>::type as() const {
|
FORCE_INLINE typename VariantAs<TValue>::type as() const {
|
||||||
return getMember().template as<TValue>();
|
return getUpstreamMember().template as<TValue>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE bool is() const {
|
FORCE_INLINE bool is() const {
|
||||||
return getMember().template is<TValue>();
|
return getUpstreamMember().template is<TValue>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE typename VariantTo<TValue>::type to() {
|
FORCE_INLINE typename VariantTo<TValue>::type to() {
|
||||||
return getOrCreateMember().template to<TValue>();
|
return getOrAddUpstreamMember().template to<TValue>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValue>
|
template <typename TValue>
|
||||||
FORCE_INLINE typename enable_if<!is_array<TValue>::value, bool>::type set(
|
FORCE_INLINE typename enable_if<!is_array<TValue>::value, bool>::type set(
|
||||||
const TValue &value) {
|
const TValue &value) {
|
||||||
return getOrCreateMember().set(value);
|
return getOrAddUpstreamMember().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set(char*) const
|
// set(char*) const
|
||||||
@ -79,56 +79,60 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
|||||||
// set(const __FlashStringHelper*) const
|
// set(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE bool set(const TChar *value) {
|
FORCE_INLINE bool set(const TChar *value) {
|
||||||
return getOrCreateMember().set(value);
|
return getOrAddUpstreamMember().set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Visitor>
|
template <typename Visitor>
|
||||||
void accept(Visitor &visitor) const {
|
void accept(Visitor &visitor) const {
|
||||||
return getMember().accept(visitor);
|
return getUpstreamMember().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ArrayShortcuts<MemberProxy>::add;
|
FORCE_INLINE VariantRef addElement() const {
|
||||||
FORCE_INLINE VariantRef add() const {
|
return getOrAddUpstreamMember().addElement();
|
||||||
return getOrCreateMember().add();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(char*) const
|
// getElement(size_t) const
|
||||||
// get(const char*) const
|
FORCE_INLINE VariantRef getElement(size_t index) const {
|
||||||
// get(const __FlashStringHelper*) const
|
return getUpstreamMember().getElement(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMember(char*) const
|
||||||
|
// getMember(const char*) const
|
||||||
|
// getMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef get(TChar *key) const {
|
FORCE_INLINE VariantRef getMember(TChar *key) const {
|
||||||
return getMember().get(key);
|
return getUpstreamMember().getMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(const std::string&) const
|
// getMember(const std::string&) const
|
||||||
// get(const String&) const
|
// getMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef get(const TString &key) const {
|
FORCE_INLINE VariantRef getMember(const TString &key) const {
|
||||||
return getMember().get(key);
|
return getUpstreamMember().getMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(char*) const
|
// getOrAddMember(char*) const
|
||||||
// getOrCreate(const char*) const
|
// getOrAddMember(const char*) const
|
||||||
// getOrCreate(const __FlashStringHelper*) const
|
// getOrAddMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef getOrCreate(TChar *key) const {
|
FORCE_INLINE VariantRef getOrAddMember(TChar *key) const {
|
||||||
return getOrCreateMember().getOrCreate(key);
|
return getOrAddUpstreamMember().getOrAddMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(const std::string&) const
|
// getOrAddMember(const std::string&) const
|
||||||
// getOrCreate(const String&) const
|
// getOrAddMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef getOrCreate(const TString &key) const {
|
FORCE_INLINE VariantRef getOrAddMember(const TString &key) const {
|
||||||
return getOrCreateMember().getOrCreate(key);
|
return getOrAddUpstreamMember().getOrAddMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FORCE_INLINE VariantRef getMember() const {
|
FORCE_INLINE VariantRef getUpstreamMember() const {
|
||||||
return _object.get(_key);
|
return _object.getMember(_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE VariantRef getOrCreateMember() const {
|
FORCE_INLINE VariantRef getOrAddUpstreamMember() const {
|
||||||
return _object.getOrCreate(_key);
|
return _object.getOrAddMember(_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
TObject _object;
|
TObject _object;
|
||||||
|
@ -13,26 +13,26 @@ template <typename TObject>
|
|||||||
template <typename TString>
|
template <typename TString>
|
||||||
inline ArrayRef ObjectShortcuts<TObject>::createNestedArray(
|
inline ArrayRef ObjectShortcuts<TObject>::createNestedArray(
|
||||||
const TString& key) const {
|
const TString& key) const {
|
||||||
return impl()->getOrCreate(key).template to<ArrayRef>();
|
return impl()->getOrAddMember(key).template to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TObject>
|
template <typename TObject>
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
inline ArrayRef ObjectShortcuts<TObject>::createNestedArray(TChar* key) const {
|
inline ArrayRef ObjectShortcuts<TObject>::createNestedArray(TChar* key) const {
|
||||||
return impl()->getOrCreate(key).template to<ArrayRef>();
|
return impl()->getOrAddMember(key).template to<ArrayRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TObject>
|
template <typename TObject>
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
inline ObjectRef ObjectShortcuts<TObject>::createNestedObject(
|
inline ObjectRef ObjectShortcuts<TObject>::createNestedObject(
|
||||||
const TString& key) const {
|
const TString& key) const {
|
||||||
return impl()->getOrCreate(key).template to<ObjectRef>();
|
return impl()->getOrAddMember(key).template to<ObjectRef>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TObject>
|
template <typename TObject>
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
inline ObjectRef ObjectShortcuts<TObject>::createNestedObject(
|
inline ObjectRef ObjectShortcuts<TObject>::createNestedObject(
|
||||||
TChar* key) const {
|
TChar* key) const {
|
||||||
return impl()->getOrCreate(key).template to<ObjectRef>();
|
return impl()->getOrAddMember(key).template to<ObjectRef>();
|
||||||
}
|
}
|
||||||
} // namespace ARDUINOJSON_NAMESPACE
|
} // namespace ARDUINOJSON_NAMESPACE
|
||||||
|
@ -82,18 +82,18 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
|
|||||||
return iterator();
|
return iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(const std::string&) const
|
// getMember(const std::string&) const
|
||||||
// get(const String&) const
|
// getMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantConstRef get(const TString& key) const {
|
FORCE_INLINE VariantConstRef getMember(const TString& key) const {
|
||||||
return get_impl(adaptString(key));
|
return get_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(char*) const
|
// getMember(char*) const
|
||||||
// get(const char*) const
|
// getMember(const char*) const
|
||||||
// get(const __FlashStringHelper*) const
|
// getMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantConstRef get(TChar* key) const {
|
FORCE_INLINE VariantConstRef getMember(TChar* key) const {
|
||||||
return get_impl(adaptString(key));
|
return get_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,33 +166,33 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
|
|||||||
return _data->copyFrom(*src._data, _pool);
|
return _data->copyFrom(*src._data, _pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(const std::string&) const
|
// getMember(const std::string&) const
|
||||||
// get(const String&) const
|
// getMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef get(const TString& key) const {
|
FORCE_INLINE VariantRef getMember(const TString& key) const {
|
||||||
return get_impl(adaptString(key));
|
return get_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get(char*) const
|
// getMember(char*) const
|
||||||
// get(const char*) const
|
// getMember(const char*) const
|
||||||
// get(const __FlashStringHelper*) const
|
// getMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef get(TChar* key) const {
|
FORCE_INLINE VariantRef getMember(TChar* key) const {
|
||||||
return get_impl(adaptString(key));
|
return get_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(const std::string&) const
|
// getOrAddMember(const std::string&) const
|
||||||
// getOrCreate(const String&) const
|
// getOrAddMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef getOrCreate(const TString& key) const {
|
FORCE_INLINE VariantRef getOrAddMember(const TString& key) const {
|
||||||
return getOrCreate_impl(adaptString(key));
|
return getOrCreate_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCreate(char*) const
|
// getOrAddMember(char*) const
|
||||||
// getOrCreate(const char*) const
|
// getOrAddMember(const char*) const
|
||||||
// getOrCreate(const __FlashStringHelper*) const
|
// getOrAddMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef getOrCreate(TChar* key) const {
|
FORCE_INLINE VariantRef getOrAddMember(TChar* key) const {
|
||||||
return getOrCreate_impl(adaptString(key));
|
return getOrCreate_impl(adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,17 +285,23 @@ class VariantData {
|
|||||||
return isCollection() ? _content.asCollection.size() : 0;
|
return isCollection() ? _content.asCollection.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantData *get(size_t index) const {
|
VariantData *addElement(MemoryPool *pool) {
|
||||||
|
if (isNull()) toArray();
|
||||||
|
if (!isArray()) return 0;
|
||||||
|
return _content.asCollection.add(pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
VariantData *getElement(size_t index) const {
|
||||||
return isArray() ? _content.asCollection.get(index) : 0;
|
return isArray() ? _content.asCollection.get(index) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
template <typename TAdaptedString>
|
||||||
VariantData *get(TAdaptedString key) const {
|
VariantData *getMember(TAdaptedString key) const {
|
||||||
return isObject() ? _content.asCollection.get(key) : 0;
|
return isObject() ? _content.asCollection.get(key) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
template <typename TAdaptedString>
|
||||||
VariantData *getOrCreate(TAdaptedString key, MemoryPool *pool) {
|
VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool) {
|
||||||
if (isNull()) toObject();
|
if (isNull()) toObject();
|
||||||
if (!isObject()) return 0;
|
if (!isObject()) return 0;
|
||||||
VariantData *var = _content.asCollection.get(key);
|
VariantData *var = _content.asCollection.get(key);
|
||||||
@ -303,12 +309,6 @@ class VariantData {
|
|||||||
return _content.asCollection.add(key, pool);
|
return _content.asCollection.add(key, pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantData *add(MemoryPool *pool) {
|
|
||||||
if (isNull()) toArray();
|
|
||||||
if (!isArray()) return 0;
|
|
||||||
return _content.asCollection.add(pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t type() const {
|
uint8_t type() const {
|
||||||
return _flags & VALUE_MASK;
|
return _flags & VALUE_MASK;
|
||||||
|
@ -147,19 +147,19 @@ inline CollectionData *variantToObject(VariantData *var) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline NO_INLINE VariantData *variantAdd(VariantData *var, MemoryPool *pool) {
|
inline NO_INLINE VariantData *variantAdd(VariantData *var, MemoryPool *pool) {
|
||||||
return var != 0 ? var->add(pool) : 0;
|
return var != 0 ? var->addElement(pool) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
NO_INLINE VariantData *variantGetOrCreate(VariantData *var, TChar *key,
|
NO_INLINE VariantData *variantGetOrCreate(VariantData *var, TChar *key,
|
||||||
MemoryPool *pool) {
|
MemoryPool *pool) {
|
||||||
return var != 0 ? var->getOrCreate(adaptString(key), pool) : 0;
|
return var != 0 ? var->getOrAddMember(adaptString(key), pool) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
NO_INLINE VariantData *variantGetOrCreate(VariantData *var, const TString &key,
|
NO_INLINE VariantData *variantGetOrCreate(VariantData *var, const TString &key,
|
||||||
MemoryPool *pool) {
|
MemoryPool *pool) {
|
||||||
return var != 0 ? var->getOrCreate(adaptString(key), pool) : 0;
|
return var != 0 ? var->getOrAddMember(adaptString(key), pool) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ARDUINOJSON_NAMESPACE
|
} // namespace ARDUINOJSON_NAMESPACE
|
||||||
|
@ -102,32 +102,32 @@ inline VariantConstRef VariantConstRef::operator[](size_t index) const {
|
|||||||
return ArrayConstRef(_data != 0 ? _data->asArray() : 0)[index];
|
return ArrayConstRef(_data != 0 ? _data->asArray() : 0)[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VariantRef VariantRef::add() const {
|
inline VariantRef VariantRef::addElement() const {
|
||||||
return VariantRef(_pool, variantAdd(_data, _pool));
|
return VariantRef(_pool, variantAdd(_data, _pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VariantRef VariantRef::get(size_t index) const {
|
inline VariantRef VariantRef::getElement(size_t index) const {
|
||||||
return VariantRef(_pool, _data != 0 ? _data->get(index) : 0);
|
return VariantRef(_pool, _data != 0 ? _data->getElement(index) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
inline VariantRef VariantRef::get(TChar *key) const {
|
inline VariantRef VariantRef::getMember(TChar *key) const {
|
||||||
return VariantRef(_pool, _data != 0 ? _data->get(adaptString(key)) : 0);
|
return VariantRef(_pool, _data != 0 ? _data->getMember(adaptString(key)) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
inline typename enable_if<IsString<TString>::value, VariantRef>::type
|
inline typename enable_if<IsString<TString>::value, VariantRef>::type
|
||||||
VariantRef::get(const TString &key) const {
|
VariantRef::getMember(const TString &key) const {
|
||||||
return VariantRef(_pool, _data != 0 ? _data->get(adaptString(key)) : 0);
|
return VariantRef(_pool, _data != 0 ? _data->getMember(adaptString(key)) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
inline VariantRef VariantRef::getOrCreate(TChar *key) const {
|
inline VariantRef VariantRef::getOrAddMember(TChar *key) const {
|
||||||
return VariantRef(_pool, variantGetOrCreate(_data, key, _pool));
|
return VariantRef(_pool, variantGetOrCreate(_data, key, _pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
inline VariantRef VariantRef::getOrCreate(const TString &key) const {
|
inline VariantRef VariantRef::getOrAddMember(const TString &key) const {
|
||||||
return VariantRef(_pool, variantGetOrCreate(_data, key, _pool));
|
return VariantRef(_pool, variantGetOrCreate(_data, key, _pool));
|
||||||
}
|
}
|
||||||
} // namespace ARDUINOJSON_NAMESPACE
|
} // namespace ARDUINOJSON_NAMESPACE
|
||||||
|
@ -280,32 +280,31 @@ class VariantRef : public VariantRefBase<VariantData>,
|
|||||||
typename enable_if<is_same<T, VariantRef>::value, VariantRef>::type to()
|
typename enable_if<is_same<T, VariantRef>::value, VariantRef>::type to()
|
||||||
const;
|
const;
|
||||||
|
|
||||||
VariantRef add() const;
|
VariantRef addElement() const;
|
||||||
using ArrayShortcuts::add;
|
|
||||||
|
|
||||||
FORCE_INLINE VariantRef get(size_t) const;
|
FORCE_INLINE VariantRef getElement(size_t) const;
|
||||||
|
|
||||||
// get(const char*) const
|
// getMember(const char*) const
|
||||||
// get(const __FlashStringHelper*) const
|
// getMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef get(TChar *) const;
|
FORCE_INLINE VariantRef getMember(TChar *) const;
|
||||||
|
|
||||||
// get(const std::string&) const
|
// getMember(const std::string&) const
|
||||||
// get(const String&) const
|
// getMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type
|
FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type
|
||||||
get(const TString &) const;
|
getMember(const TString &) const;
|
||||||
|
|
||||||
// getOrCreate(char*) const
|
// getOrAddMember(char*) const
|
||||||
// getOrCreate(const char*) const
|
// getOrAddMember(const char*) const
|
||||||
// getOrCreate(const __FlashStringHelper*) const
|
// getOrAddMember(const __FlashStringHelper*) const
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE VariantRef getOrCreate(TChar *) const;
|
FORCE_INLINE VariantRef getOrAddMember(TChar *) const;
|
||||||
|
|
||||||
// getOrCreate(const std::string&) const
|
// getOrAddMember(const std::string&) const
|
||||||
// getOrCreate(const String&) const
|
// getOrAddMember(const String&) const
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE VariantRef getOrCreate(const TString &) const;
|
FORCE_INLINE VariantRef getOrAddMember(const TString &) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MemoryPool *_pool;
|
MemoryPool *_pool;
|
||||||
|
@ -9,7 +9,7 @@ using namespace ARDUINOJSON_NAMESPACE;
|
|||||||
|
|
||||||
TEST_CASE("ElementProxy::add()") {
|
TEST_CASE("ElementProxy::add()") {
|
||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
doc.add();
|
doc.addElement();
|
||||||
ElementProxy<JsonDocument&> ep = doc[0];
|
ElementProxy<JsonDocument&> ep = doc[0];
|
||||||
|
|
||||||
SECTION("add(int)") {
|
SECTION("add(int)") {
|
||||||
|
@ -9,7 +9,7 @@ using namespace ARDUINOJSON_NAMESPACE;
|
|||||||
|
|
||||||
TEST_CASE("ElementProxy::set()") {
|
TEST_CASE("ElementProxy::set()") {
|
||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
doc.add();
|
doc.addElement();
|
||||||
ElementProxy<JsonDocument&> ep = doc[0];
|
ElementProxy<JsonDocument&> ep = doc[0];
|
||||||
|
|
||||||
SECTION("set(int)") {
|
SECTION("set(int)") {
|
||||||
|
@ -11,6 +11,6 @@ TEST_CASE("JsonArray::get()") {
|
|||||||
JsonArray array = doc.as<JsonArray>();
|
JsonArray array = doc.as<JsonArray>();
|
||||||
|
|
||||||
SECTION("Overflow") {
|
SECTION("Overflow") {
|
||||||
REQUIRE(array.get(3).isNull());
|
REQUIRE(array.getElement(3).isNull());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ add_executable(JsonVariantTests
|
|||||||
compare.cpp
|
compare.cpp
|
||||||
copy.cpp
|
copy.cpp
|
||||||
createNested.cpp
|
createNested.cpp
|
||||||
get.cpp
|
|
||||||
is.cpp
|
is.cpp
|
||||||
isnull.cpp
|
isnull.cpp
|
||||||
memoryUsage.cpp
|
memoryUsage.cpp
|
||||||
|
@ -12,13 +12,6 @@ TEST_CASE("JsonVariant::add()") {
|
|||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
JsonVariant var = doc.to<JsonVariant>();
|
JsonVariant var = doc.to<JsonVariant>();
|
||||||
|
|
||||||
SECTION("No argument") {
|
|
||||||
JsonVariant nested = var.add();
|
|
||||||
|
|
||||||
REQUIRE(var.is<JsonArray>() == true);
|
|
||||||
REQUIRE(nested.isNull() == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("integer") {
|
SECTION("integer") {
|
||||||
var.add(42);
|
var.add(42);
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
// ArduinoJson - arduinojson.org
|
|
||||||
// Copyright Benoit Blanchon 2014-2019
|
|
||||||
// MIT License
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include <catch.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("JsonVariant::get()") {
|
|
||||||
DynamicJsonDocument doc(4096);
|
|
||||||
JsonVariant var = doc.to<JsonVariant>();
|
|
||||||
|
|
||||||
SECTION("get(const char*)") {
|
|
||||||
var["value"] = 42;
|
|
||||||
|
|
||||||
REQUIRE(var.get("value") == 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("get(std::string)") {
|
|
||||||
var["value"] = 42;
|
|
||||||
|
|
||||||
REQUIRE(var.get(std::string("value")) == 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("get(int)") {
|
|
||||||
var.add().set(42);
|
|
||||||
|
|
||||||
REQUIRE(var.get(0) == 42);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user