mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	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 | ||||
| * Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()` | ||||
| * 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) | ||||
| ----------- | ||||
|   | ||||
| @@ -11,12 +11,12 @@ namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TArray> | ||||
| inline ArrayRef ArrayShortcuts<TArray>::createNestedArray() const { | ||||
|   return impl()->add().template to<ArrayRef>(); | ||||
|   return impl()->addElement().template to<ArrayRef>(); | ||||
| } | ||||
|  | ||||
| template <typename TArray> | ||||
| inline ObjectRef ArrayShortcuts<TArray>::createNestedObject() const { | ||||
|   return impl()->add().template to<ObjectRef>(); | ||||
|   return impl()->addElement().template to<ObjectRef>(); | ||||
| } | ||||
|  | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -101,8 +101,7 @@ class ArrayRef : public ArrayRefBase<CollectionData>, | ||||
|     return ArrayConstRef(_data); | ||||
|   } | ||||
|  | ||||
|   using ArrayShortcuts::add; | ||||
|   VariantRef add() const { | ||||
|   VariantRef addElement() const { | ||||
|     return VariantRef(_pool, arrayAdd(_data, _pool)); | ||||
|   } | ||||
|  | ||||
| @@ -126,7 +125,7 @@ class ArrayRef : public ArrayRefBase<CollectionData>, | ||||
|   } | ||||
|  | ||||
|   // 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); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -29,14 +29,14 @@ class ArrayShortcuts { | ||||
|   //          std::string, String, ObjectRef | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool add(const T &value) const { | ||||
|     return impl()->add().set(value); | ||||
|     return impl()->addElement().set(value); | ||||
|   } | ||||
|   // | ||||
|   // bool add(TValue); | ||||
|   // TValue = char*, const char*, const __FlashStringHelper* | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool add(T *value) const { | ||||
|     return impl()->add().set(value); | ||||
|     return impl()->addElement().set(value); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -24,7 +24,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >, | ||||
|       : _array(array), _index(index) {} | ||||
|  | ||||
|   FORCE_INLINE this_type& operator=(const this_type& src) { | ||||
|     getElement().set(src.as<VariantConstRef>()); | ||||
|     getUpstreamElement().set(src.as<VariantConstRef>()); | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
| @@ -35,7 +35,7 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >, | ||||
|   //          std::string, String, ArrayRef, ObjectRef | ||||
|   template <typename T> | ||||
|   FORCE_INLINE this_type& operator=(const T& src) { | ||||
|     getElement().set(src); | ||||
|     getUpstreamElement().set(src); | ||||
|     return *this; | ||||
|   } | ||||
|   // | ||||
| @@ -43,27 +43,27 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >, | ||||
|   // TValue = char*, const char*, const __FlashStringHelper* | ||||
|   template <typename T> | ||||
|   FORCE_INLINE this_type& operator=(T* src) { | ||||
|     getElement().set(src); | ||||
|     getUpstreamElement().set(src); | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return getElement().isNull(); | ||||
|     return getUpstreamElement().isNull(); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename VariantAs<T>::type as() const { | ||||
|     return getElement().template as<T>(); | ||||
|     return getUpstreamElement().template as<T>(); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool is() const { | ||||
|     return getElement().template is<T>(); | ||||
|     return getUpstreamElement().template is<T>(); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename VariantTo<T>::type to() const { | ||||
|     return getElement().template to<T>(); | ||||
|     return getUpstreamElement().template to<T>(); | ||||
|   } | ||||
|  | ||||
|   // Replaces the value | ||||
| @@ -73,53 +73,56 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >, | ||||
|   //          std::string, String, ArrayRef, ObjectRef | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE bool set(const TValue& value) const { | ||||
|     return getElement().set(value); | ||||
|     return getUpstreamElement().set(value); | ||||
|   } | ||||
|   // | ||||
|   // bool set(TValue) | ||||
|   // TValue = char*, const char*, const __FlashStringHelper* | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE bool set(TValue* value) const { | ||||
|     return getElement().set(value); | ||||
|     return getUpstreamElement().set(value); | ||||
|   } | ||||
|  | ||||
|   template <typename Visitor> | ||||
|   void accept(Visitor& visitor) const { | ||||
|     return getElement().accept(visitor); | ||||
|     return getUpstreamElement().accept(visitor); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     return getElement().size(); | ||||
|     return getUpstreamElement().size(); | ||||
|   } | ||||
|  | ||||
|   template <typename TNestedKey> | ||||
|   VariantRef get(TNestedKey* key) const { | ||||
|     return getElement().get(key); | ||||
|   VariantRef getMember(TNestedKey* key) const { | ||||
|     return getUpstreamElement().getMember(key); | ||||
|   } | ||||
|  | ||||
|   template <typename TNestedKey> | ||||
|   VariantRef get(const TNestedKey& key) const { | ||||
|     return getElement().get(key); | ||||
|   VariantRef getMember(const TNestedKey& key) const { | ||||
|     return getUpstreamElement().getMember(key); | ||||
|   } | ||||
|  | ||||
|   template <typename TNestedKey> | ||||
|   VariantRef getOrCreate(TNestedKey* key) const { | ||||
|     return getElement().getOrCreate(key); | ||||
|   VariantRef getOrAddMember(TNestedKey* key) const { | ||||
|     return getUpstreamElement().getOrAddMember(key); | ||||
|   } | ||||
|  | ||||
|   template <typename TNestedKey> | ||||
|   VariantRef getOrCreate(const TNestedKey& key) const { | ||||
|     return getElement().getOrCreate(key); | ||||
|   VariantRef getOrAddMember(const TNestedKey& key) const { | ||||
|     return getUpstreamElement().getOrAddMember(key); | ||||
|   } | ||||
|  | ||||
|   using ArrayShortcuts<ElementProxy>::add; | ||||
|   VariantRef add() const { | ||||
|     return getElement().add(); | ||||
|   VariantRef addElement() const { | ||||
|     return getUpstreamElement().addElement(); | ||||
|   } | ||||
|  | ||||
|   VariantRef getElement(size_t index) const { | ||||
|     return getUpstreamElement().getElement(index); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   FORCE_INLINE VariantRef getElement() const { | ||||
|     return _array.get(_index); | ||||
|   FORCE_INLINE VariantRef getUpstreamElement() const { | ||||
|     return _array.getElement(_index); | ||||
|   } | ||||
|  | ||||
|   TArray _array; | ||||
|   | ||||
| @@ -83,7 +83,7 @@ class JsonDocument : public Visitable { | ||||
|   } | ||||
|  | ||||
|   ArrayRef createNestedArray() { | ||||
|     return add().to<ArrayRef>(); | ||||
|     return addElement().to<ArrayRef>(); | ||||
|   } | ||||
|  | ||||
|   // createNestedArray(char*) | ||||
| @@ -91,18 +91,18 @@ class JsonDocument : public Visitable { | ||||
|   // createNestedArray(const __FlashStringHelper*) | ||||
|   template <typename TChar> | ||||
|   ArrayRef createNestedArray(TChar* key) { | ||||
|     return getOrCreate(key).template to<ArrayRef>(); | ||||
|     return getOrAddMember(key).template to<ArrayRef>(); | ||||
|   } | ||||
|  | ||||
|   // createNestedArray(const std::string&) | ||||
|   // createNestedArray(const String&) | ||||
|   template <typename TString> | ||||
|   ArrayRef createNestedArray(const TString& key) { | ||||
|     return getOrCreate(key).template to<ArrayRef>(); | ||||
|     return getOrAddMember(key).template to<ArrayRef>(); | ||||
|   } | ||||
|  | ||||
|   ObjectRef createNestedObject() { | ||||
|     return add().to<ObjectRef>(); | ||||
|     return addElement().to<ObjectRef>(); | ||||
|   } | ||||
|  | ||||
|   // createNestedObject(char*) | ||||
| @@ -110,14 +110,14 @@ class JsonDocument : public Visitable { | ||||
|   // createNestedObject(const __FlashStringHelper*) | ||||
|   template <typename TChar> | ||||
|   ObjectRef createNestedObject(TChar* key) { | ||||
|     return getOrCreate(key).template to<ObjectRef>(); | ||||
|     return getOrAddMember(key).template to<ObjectRef>(); | ||||
|   } | ||||
|  | ||||
|   // createNestedObject(const std::string&) | ||||
|   // createNestedObject(const String&) | ||||
|   template <typename TString> | ||||
|   ObjectRef createNestedObject(const TString& key) { | ||||
|     return getOrCreate(key).template to<ObjectRef>(); | ||||
|     return getOrAddMember(key).template to<ObjectRef>(); | ||||
|   } | ||||
|  | ||||
|   // operator[](const std::string&) | ||||
| @@ -164,51 +164,51 @@ class JsonDocument : public Visitable { | ||||
|   } | ||||
|  | ||||
|   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) { | ||||
|     return VariantRef(&_pool, _data.get(index)); | ||||
|   FORCE_INLINE VariantRef getElement(size_t index) { | ||||
|     return VariantRef(&_pool, _data.getElement(index)); | ||||
|   } | ||||
|  | ||||
|   // get(char*) const | ||||
|   // get(const char*) const | ||||
|   // get(const __FlashStringHelper*) const | ||||
|   // getMember(char*) const | ||||
|   // getMember(const char*) const | ||||
|   // getMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef get(TChar* key) { | ||||
|     return VariantRef(&_pool, _data.get(adaptString(key))); | ||||
|   FORCE_INLINE VariantRef getMember(TChar* key) { | ||||
|     return VariantRef(&_pool, _data.getMember(adaptString(key))); | ||||
|   } | ||||
|  | ||||
|   // get(const std::string&) const | ||||
|   // get(const String&) const | ||||
|   // getMember(const std::string&) const | ||||
|   // getMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type | ||||
|   get(const TString& key) { | ||||
|     return VariantRef(&_pool, _data.get(adaptString(key))); | ||||
|   getMember(const TString& key) { | ||||
|     return VariantRef(&_pool, _data.getMember(adaptString(key))); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(char*) | ||||
|   // getOrCreate(const char*) | ||||
|   // getOrCreate(const __FlashStringHelper*) | ||||
|   // getOrAddMember(char*) | ||||
|   // getOrAddMember(const char*) | ||||
|   // getOrAddMember(const __FlashStringHelper*) | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef getOrCreate(TChar* key) { | ||||
|     return VariantRef(&_pool, _data.getOrCreate(adaptString(key), &_pool)); | ||||
|   FORCE_INLINE VariantRef getOrAddMember(TChar* key) { | ||||
|     return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool)); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(const std::string&) | ||||
|   // getOrCreate(const String&) | ||||
|   // getOrAddMember(const std::string&) | ||||
|   // getOrAddMember(const String&) | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef getOrCreate(const TString& key) { | ||||
|     return VariantRef(&_pool, _data.getOrCreate(adaptString(key), &_pool)); | ||||
|   FORCE_INLINE VariantRef getOrAddMember(const TString& key) { | ||||
|     return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool)); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE VariantRef add() { | ||||
|     return VariantRef(&_pool, _data.add(&_pool)); | ||||
|   FORCE_INLINE VariantRef addElement() { | ||||
|     return VariantRef(&_pool, _data.addElement(&_pool)); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE bool add(const TValue& value) { | ||||
|     return add().set(value); | ||||
|     return addElement().set(value); | ||||
|   } | ||||
|  | ||||
|   // add(char*) const | ||||
| @@ -216,7 +216,7 @@ class JsonDocument : public Visitable { | ||||
|   // add(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE bool add(TChar* value) { | ||||
|     return add().set(value); | ||||
|     return addElement().set(value); | ||||
|   } | ||||
|  | ||||
|  protected: | ||||
|   | ||||
| @@ -25,18 +25,18 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >, | ||||
|       : _object(variant), _key(key) {} | ||||
|  | ||||
|   FORCE_INLINE operator VariantConstRef() const { | ||||
|     return getMember(); | ||||
|     return getUpstreamMember(); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE this_type &operator=(const this_type &src) { | ||||
|     getOrCreateMember().set(src); | ||||
|     getOrAddUpstreamMember().set(src); | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type | ||||
|   operator=(const TValue &src) { | ||||
|     getOrCreateMember().set(src); | ||||
|     getOrAddUpstreamMember().set(src); | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
| @@ -45,33 +45,33 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >, | ||||
|   // operator=(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE this_type &operator=(TChar *src) { | ||||
|     getOrCreateMember().set(src); | ||||
|     getOrAddUpstreamMember().set(src); | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return getMember().isNull(); | ||||
|     return getUpstreamMember().isNull(); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE typename VariantAs<TValue>::type as() const { | ||||
|     return getMember().template as<TValue>(); | ||||
|     return getUpstreamMember().template as<TValue>(); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE bool is() const { | ||||
|     return getMember().template is<TValue>(); | ||||
|     return getUpstreamMember().template is<TValue>(); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE typename VariantTo<TValue>::type to() { | ||||
|     return getOrCreateMember().template to<TValue>(); | ||||
|     return getOrAddUpstreamMember().template to<TValue>(); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE typename enable_if<!is_array<TValue>::value, bool>::type set( | ||||
|       const TValue &value) { | ||||
|     return getOrCreateMember().set(value); | ||||
|     return getOrAddUpstreamMember().set(value); | ||||
|   } | ||||
|  | ||||
|   // set(char*) const | ||||
| @@ -79,56 +79,60 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >, | ||||
|   // set(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE bool set(const TChar *value) { | ||||
|     return getOrCreateMember().set(value); | ||||
|     return getOrAddUpstreamMember().set(value); | ||||
|   } | ||||
|  | ||||
|   template <typename Visitor> | ||||
|   void accept(Visitor &visitor) const { | ||||
|     return getMember().accept(visitor); | ||||
|     return getUpstreamMember().accept(visitor); | ||||
|   } | ||||
|  | ||||
|   using ArrayShortcuts<MemberProxy>::add; | ||||
|   FORCE_INLINE VariantRef add() const { | ||||
|     return getOrCreateMember().add(); | ||||
|   FORCE_INLINE VariantRef addElement() const { | ||||
|     return getOrAddUpstreamMember().addElement(); | ||||
|   } | ||||
|  | ||||
|   // get(char*) const | ||||
|   // get(const char*) const | ||||
|   // get(const __FlashStringHelper*) const | ||||
|   // getElement(size_t) const | ||||
|   FORCE_INLINE VariantRef getElement(size_t index) const { | ||||
|     return getUpstreamMember().getElement(index); | ||||
|   } | ||||
|  | ||||
|   // getMember(char*) const | ||||
|   // getMember(const char*) const | ||||
|   // getMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef get(TChar *key) const { | ||||
|     return getMember().get(key); | ||||
|   FORCE_INLINE VariantRef getMember(TChar *key) const { | ||||
|     return getUpstreamMember().getMember(key); | ||||
|   } | ||||
|  | ||||
|   // get(const std::string&) const | ||||
|   // get(const String&) const | ||||
|   // getMember(const std::string&) const | ||||
|   // getMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef get(const TString &key) const { | ||||
|     return getMember().get(key); | ||||
|   FORCE_INLINE VariantRef getMember(const TString &key) const { | ||||
|     return getUpstreamMember().getMember(key); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(char*) const | ||||
|   // getOrCreate(const char*) const | ||||
|   // getOrCreate(const __FlashStringHelper*) const | ||||
|   // getOrAddMember(char*) const | ||||
|   // getOrAddMember(const char*) const | ||||
|   // getOrAddMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef getOrCreate(TChar *key) const { | ||||
|     return getOrCreateMember().getOrCreate(key); | ||||
|   FORCE_INLINE VariantRef getOrAddMember(TChar *key) const { | ||||
|     return getOrAddUpstreamMember().getOrAddMember(key); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(const std::string&) const | ||||
|   // getOrCreate(const String&) const | ||||
|   // getOrAddMember(const std::string&) const | ||||
|   // getOrAddMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef getOrCreate(const TString &key) const { | ||||
|     return getOrCreateMember().getOrCreate(key); | ||||
|   FORCE_INLINE VariantRef getOrAddMember(const TString &key) const { | ||||
|     return getOrAddUpstreamMember().getOrAddMember(key); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   FORCE_INLINE VariantRef getMember() const { | ||||
|     return _object.get(_key); | ||||
|   FORCE_INLINE VariantRef getUpstreamMember() const { | ||||
|     return _object.getMember(_key); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE VariantRef getOrCreateMember() const { | ||||
|     return _object.getOrCreate(_key); | ||||
|   FORCE_INLINE VariantRef getOrAddUpstreamMember() const { | ||||
|     return _object.getOrAddMember(_key); | ||||
|   } | ||||
|  | ||||
|   TObject _object; | ||||
|   | ||||
| @@ -13,26 +13,26 @@ template <typename TObject> | ||||
| template <typename TString> | ||||
| inline ArrayRef ObjectShortcuts<TObject>::createNestedArray( | ||||
|     const TString& key) const { | ||||
|   return impl()->getOrCreate(key).template to<ArrayRef>(); | ||||
|   return impl()->getOrAddMember(key).template to<ArrayRef>(); | ||||
| } | ||||
|  | ||||
| template <typename TObject> | ||||
| template <typename TChar> | ||||
| 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 TString> | ||||
| inline ObjectRef ObjectShortcuts<TObject>::createNestedObject( | ||||
|     const TString& key) const { | ||||
|   return impl()->getOrCreate(key).template to<ObjectRef>(); | ||||
|   return impl()->getOrAddMember(key).template to<ObjectRef>(); | ||||
| } | ||||
|  | ||||
| template <typename TObject> | ||||
| template <typename TChar> | ||||
| inline ObjectRef ObjectShortcuts<TObject>::createNestedObject( | ||||
|     TChar* key) const { | ||||
|   return impl()->getOrCreate(key).template to<ObjectRef>(); | ||||
|   return impl()->getOrAddMember(key).template to<ObjectRef>(); | ||||
| } | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -82,18 +82,18 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>, | ||||
|     return iterator(); | ||||
|   } | ||||
|  | ||||
|   // get(const std::string&) const | ||||
|   // get(const String&) const | ||||
|   // getMember(const std::string&) const | ||||
|   // getMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantConstRef get(const TString& key) const { | ||||
|   FORCE_INLINE VariantConstRef getMember(const TString& key) const { | ||||
|     return get_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
|   // get(char*) const | ||||
|   // get(const char*) const | ||||
|   // get(const __FlashStringHelper*) const | ||||
|   // getMember(char*) const | ||||
|   // getMember(const char*) const | ||||
|   // getMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantConstRef get(TChar* key) const { | ||||
|   FORCE_INLINE VariantConstRef getMember(TChar* key) const { | ||||
|     return get_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
| @@ -166,33 +166,33 @@ class ObjectRef : public ObjectRefBase<CollectionData>, | ||||
|     return _data->copyFrom(*src._data, _pool); | ||||
|   } | ||||
|  | ||||
|   // get(const std::string&) const | ||||
|   // get(const String&) const | ||||
|   // getMember(const std::string&) const | ||||
|   // getMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef get(const TString& key) const { | ||||
|   FORCE_INLINE VariantRef getMember(const TString& key) const { | ||||
|     return get_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
|   // get(char*) const | ||||
|   // get(const char*) const | ||||
|   // get(const __FlashStringHelper*) const | ||||
|   // getMember(char*) const | ||||
|   // getMember(const char*) const | ||||
|   // getMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef get(TChar* key) const { | ||||
|   FORCE_INLINE VariantRef getMember(TChar* key) const { | ||||
|     return get_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(const std::string&) const | ||||
|   // getOrCreate(const String&) const | ||||
|   // getOrAddMember(const std::string&) const | ||||
|   // getOrAddMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef getOrCreate(const TString& key) const { | ||||
|   FORCE_INLINE VariantRef getOrAddMember(const TString& key) const { | ||||
|     return getOrCreate_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
|   // getOrCreate(char*) const | ||||
|   // getOrCreate(const char*) const | ||||
|   // getOrCreate(const __FlashStringHelper*) const | ||||
|   // getOrAddMember(char*) const | ||||
|   // getOrAddMember(const char*) const | ||||
|   // getOrAddMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef getOrCreate(TChar* key) const { | ||||
|   FORCE_INLINE VariantRef getOrAddMember(TChar* key) const { | ||||
|     return getOrCreate_impl(adaptString(key)); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -285,17 +285,23 @@ class VariantData { | ||||
|     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; | ||||
|   } | ||||
|  | ||||
|   template <typename TAdaptedString> | ||||
|   VariantData *get(TAdaptedString key) const { | ||||
|   VariantData *getMember(TAdaptedString key) const { | ||||
|     return isObject() ? _content.asCollection.get(key) : 0; | ||||
|   } | ||||
|  | ||||
|   template <typename TAdaptedString> | ||||
|   VariantData *getOrCreate(TAdaptedString key, MemoryPool *pool) { | ||||
|   VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool) { | ||||
|     if (isNull()) toObject(); | ||||
|     if (!isObject()) return 0; | ||||
|     VariantData *var = _content.asCollection.get(key); | ||||
| @@ -303,12 +309,6 @@ class VariantData { | ||||
|     return _content.asCollection.add(key, pool); | ||||
|   } | ||||
|  | ||||
|   VariantData *add(MemoryPool *pool) { | ||||
|     if (isNull()) toArray(); | ||||
|     if (!isArray()) return 0; | ||||
|     return _content.asCollection.add(pool); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   uint8_t type() const { | ||||
|     return _flags & VALUE_MASK; | ||||
|   | ||||
| @@ -147,19 +147,19 @@ inline CollectionData *variantToObject(VariantData *var) { | ||||
| } | ||||
|  | ||||
| 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> | ||||
| NO_INLINE VariantData *variantGetOrCreate(VariantData *var, TChar *key, | ||||
|                                           MemoryPool *pool) { | ||||
|   return var != 0 ? var->getOrCreate(adaptString(key), pool) : 0; | ||||
|   return var != 0 ? var->getOrAddMember(adaptString(key), pool) : 0; | ||||
| } | ||||
|  | ||||
| template <typename TString> | ||||
| NO_INLINE VariantData *variantGetOrCreate(VariantData *var, const TString &key, | ||||
|                                           MemoryPool *pool) { | ||||
|   return var != 0 ? var->getOrCreate(adaptString(key), pool) : 0; | ||||
|   return var != 0 ? var->getOrAddMember(adaptString(key), pool) : 0; | ||||
| } | ||||
|  | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -102,32 +102,32 @@ inline VariantConstRef VariantConstRef::operator[](size_t index) const { | ||||
|   return ArrayConstRef(_data != 0 ? _data->asArray() : 0)[index]; | ||||
| } | ||||
|  | ||||
| inline VariantRef VariantRef::add() const { | ||||
| inline VariantRef VariantRef::addElement() const { | ||||
|   return VariantRef(_pool, variantAdd(_data, _pool)); | ||||
| } | ||||
|  | ||||
| inline VariantRef VariantRef::get(size_t index) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->get(index) : 0); | ||||
| inline VariantRef VariantRef::getElement(size_t index) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->getElement(index) : 0); | ||||
| } | ||||
|  | ||||
| template <typename TChar> | ||||
| inline VariantRef VariantRef::get(TChar *key) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->get(adaptString(key)) : 0); | ||||
| inline VariantRef VariantRef::getMember(TChar *key) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->getMember(adaptString(key)) : 0); | ||||
| } | ||||
|  | ||||
| template <typename TString> | ||||
| inline typename enable_if<IsString<TString>::value, VariantRef>::type | ||||
| VariantRef::get(const TString &key) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->get(adaptString(key)) : 0); | ||||
| VariantRef::getMember(const TString &key) const { | ||||
|   return VariantRef(_pool, _data != 0 ? _data->getMember(adaptString(key)) : 0); | ||||
| } | ||||
|  | ||||
| template <typename TChar> | ||||
| inline VariantRef VariantRef::getOrCreate(TChar *key) const { | ||||
| inline VariantRef VariantRef::getOrAddMember(TChar *key) const { | ||||
|   return VariantRef(_pool, variantGetOrCreate(_data, key, _pool)); | ||||
| } | ||||
|  | ||||
| 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)); | ||||
| } | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -280,32 +280,31 @@ class VariantRef : public VariantRefBase<VariantData>, | ||||
|   typename enable_if<is_same<T, VariantRef>::value, VariantRef>::type to() | ||||
|       const; | ||||
|  | ||||
|   VariantRef add() const; | ||||
|   using ArrayShortcuts::add; | ||||
|   VariantRef addElement() const; | ||||
|  | ||||
|   FORCE_INLINE VariantRef get(size_t) const; | ||||
|   FORCE_INLINE VariantRef getElement(size_t) const; | ||||
|  | ||||
|   // get(const char*) const | ||||
|   // get(const __FlashStringHelper*) const | ||||
|   // getMember(const char*) const | ||||
|   // getMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef get(TChar *) const; | ||||
|   FORCE_INLINE VariantRef getMember(TChar *) const; | ||||
|  | ||||
|   // get(const std::string&) const | ||||
|   // get(const String&) const | ||||
|   // getMember(const std::string&) const | ||||
|   // getMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE typename enable_if<IsString<TString>::value, VariantRef>::type | ||||
|   get(const TString &) const; | ||||
|   getMember(const TString &) const; | ||||
|  | ||||
|   // getOrCreate(char*) const | ||||
|   // getOrCreate(const char*) const | ||||
|   // getOrCreate(const __FlashStringHelper*) const | ||||
|   // getOrAddMember(char*) const | ||||
|   // getOrAddMember(const char*) const | ||||
|   // getOrAddMember(const __FlashStringHelper*) const | ||||
|   template <typename TChar> | ||||
|   FORCE_INLINE VariantRef getOrCreate(TChar *) const; | ||||
|   FORCE_INLINE VariantRef getOrAddMember(TChar *) const; | ||||
|  | ||||
|   // getOrCreate(const std::string&) const | ||||
|   // getOrCreate(const String&) const | ||||
|   // getOrAddMember(const std::string&) const | ||||
|   // getOrAddMember(const String&) const | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE VariantRef getOrCreate(const TString &) const; | ||||
|   FORCE_INLINE VariantRef getOrAddMember(const TString &) const; | ||||
|  | ||||
|  private: | ||||
|   MemoryPool *_pool; | ||||
|   | ||||
| @@ -9,7 +9,7 @@ using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("ElementProxy::add()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   doc.add(); | ||||
|   doc.addElement(); | ||||
|   ElementProxy<JsonDocument&> ep = doc[0]; | ||||
|  | ||||
|   SECTION("add(int)") { | ||||
|   | ||||
| @@ -9,7 +9,7 @@ using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("ElementProxy::set()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   doc.add(); | ||||
|   doc.addElement(); | ||||
|   ElementProxy<JsonDocument&> ep = doc[0]; | ||||
|  | ||||
|   SECTION("set(int)") { | ||||
|   | ||||
| @@ -11,6 +11,6 @@ TEST_CASE("JsonArray::get()") { | ||||
|   JsonArray array = doc.as<JsonArray>(); | ||||
|  | ||||
|   SECTION("Overflow") { | ||||
|     REQUIRE(array.get(3).isNull()); | ||||
|     REQUIRE(array.getElement(3).isNull()); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -8,7 +8,6 @@ add_executable(JsonVariantTests | ||||
| 	compare.cpp | ||||
| 	copy.cpp | ||||
| 	createNested.cpp | ||||
| 	get.cpp | ||||
| 	is.cpp | ||||
| 	isnull.cpp | ||||
| 	memoryUsage.cpp | ||||
|   | ||||
| @@ -12,13 +12,6 @@ TEST_CASE("JsonVariant::add()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   JsonVariant var = doc.to<JsonVariant>(); | ||||
|  | ||||
|   SECTION("No argument") { | ||||
|     JsonVariant nested = var.add(); | ||||
|  | ||||
|     REQUIRE(var.is<JsonArray>() == true); | ||||
|     REQUIRE(nested.isNull() == true); | ||||
|   } | ||||
|  | ||||
|   SECTION("integer") { | ||||
|     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