diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
commit | 39895a677e5d370824e702cfe90ebc67737b8482 (patch) | |
tree | ff5b4cc9e373d33a795d50d9333e05549bd9f2b8 /include/lib/ArduinoJson/Object | |
parent | 42e7fdf01c3a5701bb51e93ad6c650c3dbbc5450 (diff) |
import ArduinoJson 6.18.0
Diffstat (limited to 'include/lib/ArduinoJson/Object')
-rw-r--r-- | include/lib/ArduinoJson/Object/MemberProxy.hpp | 202 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/ObjectFunctions.hpp | 51 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/ObjectImpl.hpp | 69 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/ObjectIterator.hpp | 123 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/ObjectRef.hpp | 277 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/ObjectShortcuts.hpp | 73 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Object/Pair.hpp | 55 |
7 files changed, 850 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Object/MemberProxy.hpp b/include/lib/ArduinoJson/Object/MemberProxy.hpp new file mode 100644 index 0000000..0bee84b --- /dev/null +++ b/include/lib/ArduinoJson/Object/MemberProxy.hpp @@ -0,0 +1,202 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Configuration.hpp> +#include <ArduinoJson/Polyfills/type_traits.hpp> +#include <ArduinoJson/Variant/VariantOperators.hpp> +#include <ArduinoJson/Variant/VariantRef.hpp> +#include <ArduinoJson/Variant/VariantShortcuts.hpp> +#include <ArduinoJson/Variant/VariantTo.hpp> + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4522) +#endif + +namespace ARDUINOJSON_NAMESPACE { + +template <typename TObject, typename TStringRef> +class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >, + public VariantShortcuts<MemberProxy<TObject, TStringRef> >, + public Visitable, + public VariantTag { + typedef MemberProxy<TObject, TStringRef> this_type; + + public: + typedef VariantRef variant_type; + + FORCE_INLINE MemberProxy(TObject variant, TStringRef key) + : _object(variant), _key(key) {} + + FORCE_INLINE MemberProxy(const MemberProxy &src) + : _object(src._object), _key(src._key) {} + + FORCE_INLINE operator VariantConstRef() const { + return getUpstreamMember(); + } + + FORCE_INLINE this_type &operator=(const this_type &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) { + getOrAddUpstreamMember().set(src); + return *this; + } + + // operator=(char*) + // operator=(const char*) + // operator=(const __FlashStringHelper*) + template <typename TChar> + FORCE_INLINE this_type &operator=(TChar *src) { + getOrAddUpstreamMember().set(src); + return *this; + } + + FORCE_INLINE void clear() const { + getUpstreamMember().clear(); + } + + FORCE_INLINE bool isNull() const { + return getUpstreamMember().isNull(); + } + + template <typename T> + FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as() + const { + return getUpstreamMember().template as<T>(); + } + + template <typename T> + FORCE_INLINE typename enable_if<is_same<T, char *>::value, const char *>::type + ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()") + as() const { + return as<const char *>(); + } + + template <typename T> + FORCE_INLINE operator T() const { + return getUpstreamMember(); + } + + template <typename TValue> + FORCE_INLINE bool is() const { + return getUpstreamMember().template is<TValue>(); + } + + FORCE_INLINE size_t size() const { + return getUpstreamMember().size(); + } + + FORCE_INLINE void remove(size_t index) const { + getUpstreamMember().remove(index); + } + // remove(char*) const + // remove(const char*) const + // remove(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE typename enable_if<IsString<TChar *>::value>::type remove( + TChar *key) const { + getUpstreamMember().remove(key); + } + // remove(const std::string&) const + // remove(const String&) const + template <typename TString> + FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove( + const TString &key) const { + getUpstreamMember().remove(key); + } + + template <typename TValue> + FORCE_INLINE typename VariantTo<TValue>::type to() { + return getOrAddUpstreamMember().template to<TValue>(); + } + + template <typename TValue> + FORCE_INLINE bool set(const TValue &value) { + return getOrAddUpstreamMember().set(value); + } + + // set(char*) const + // set(const char*) const + // set(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE bool set(TChar *value) { + return getOrAddUpstreamMember().set(value); + } + + template <typename TVisitor> + typename TVisitor::result_type accept(TVisitor &visitor) const { + return getUpstreamMember().accept(visitor); + } + + FORCE_INLINE VariantRef addElement() const { + return getOrAddUpstreamMember().addElement(); + } + + FORCE_INLINE VariantRef getElement(size_t index) const { + return getUpstreamMember().getElement(index); + } + + FORCE_INLINE VariantRef getOrAddElement(size_t index) const { + return getOrAddUpstreamMember().getOrAddElement(index); + } + + // getMember(char*) const + // getMember(const char*) const + // getMember(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE VariantRef getMember(TChar *key) const { + return getUpstreamMember().getMember(key); + } + + // getMember(const std::string&) const + // getMember(const String&) const + template <typename TString> + FORCE_INLINE VariantRef getMember(const TString &key) const { + return getUpstreamMember().getMember(key); + } + + // getOrAddMember(char*) const + // getOrAddMember(const char*) const + // getOrAddMember(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE VariantRef getOrAddMember(TChar *key) const { + return getOrAddUpstreamMember().getOrAddMember(key); + } + + // getOrAddMember(const std::string&) const + // getOrAddMember(const String&) const + template <typename TString> + FORCE_INLINE VariantRef getOrAddMember(const TString &key) const { + return getOrAddUpstreamMember().getOrAddMember(key); + } + + private: + FORCE_INLINE VariantRef getUpstreamMember() const { + return _object.getMember(_key); + } + + FORCE_INLINE VariantRef getOrAddUpstreamMember() const { + return _object.getOrAddMember(_key); + } + + friend bool convertToJson(const this_type &src, VariantRef dst) { + return dst.set(src.getUpstreamMember()); + } + + TObject _object; + TStringRef _key; +}; + +} // namespace ARDUINOJSON_NAMESPACE + +#ifdef _MSC_VER +#pragma warning(pop) +#endif diff --git a/include/lib/ArduinoJson/Object/ObjectFunctions.hpp b/include/lib/ArduinoJson/Object/ObjectFunctions.hpp new file mode 100644 index 0000000..1b46e84 --- /dev/null +++ b/include/lib/ArduinoJson/Object/ObjectFunctions.hpp @@ -0,0 +1,51 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Collection/CollectionData.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +template <typename TVisitor> +typename TVisitor::result_type objectAccept(const CollectionData *obj, + TVisitor &visitor) { + if (obj) + return visitor.visitObject(*obj); + else + return visitor.visitNull(); +} + +inline bool objectEquals(const CollectionData *lhs, const CollectionData *rhs) { + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; + return lhs->equalsObject(*rhs); +} + +template <typename TAdaptedString> +inline VariantData *objectGetMember(const CollectionData *obj, + TAdaptedString key) { + if (!obj) + return 0; + return obj->getMember(key); +} + +template <typename TAdaptedString> +void objectRemove(CollectionData *obj, TAdaptedString key) { + if (!obj) + return; + obj->removeMember(key); +} + +template <typename TAdaptedString> +inline VariantData *objectGetOrAddMember(CollectionData *obj, + TAdaptedString key, MemoryPool *pool) { + if (!obj) + return 0; + + return obj->getOrAddMember(key, pool); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Object/ObjectImpl.hpp b/include/lib/ArduinoJson/Object/ObjectImpl.hpp new file mode 100644 index 0000000..d66b61c --- /dev/null +++ b/include/lib/ArduinoJson/Object/ObjectImpl.hpp @@ -0,0 +1,69 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Array/ArrayRef.hpp> +#include <ArduinoJson/Object/ObjectRef.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +template <typename TObject> +template <typename TString> +inline ArrayRef ObjectShortcuts<TObject>::createNestedArray( + const TString& key) const { + return impl()->getOrAddMember(key).template to<ArrayRef>(); +} + +template <typename TObject> +template <typename TChar> +inline ArrayRef ObjectShortcuts<TObject>::createNestedArray(TChar* key) const { + return impl()->getOrAddMember(key).template to<ArrayRef>(); +} + +template <typename TObject> +template <typename TString> +inline ObjectRef ObjectShortcuts<TObject>::createNestedObject( + const TString& key) const { + return impl()->getOrAddMember(key).template to<ObjectRef>(); +} + +template <typename TObject> +template <typename TChar> +inline ObjectRef ObjectShortcuts<TObject>::createNestedObject( + TChar* key) const { + return impl()->getOrAddMember(key).template to<ObjectRef>(); +} + +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).isUndefined(); +} + +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).isUndefined(); +} + +template <typename TObject> +template <typename TString> +inline typename enable_if<IsString<TString*>::value, + MemberProxy<TObject, TString*> >::type +ObjectShortcuts<TObject>::operator[](TString* key) const { + return MemberProxy<TObject, TString*>(*impl(), key); +} + +template <typename TObject> +template <typename TString> +inline typename enable_if<IsString<TString>::value, + MemberProxy<TObject, TString> >::type +ObjectShortcuts<TObject>::operator[](const TString& key) const { + return MemberProxy<TObject, TString>(*impl(), key); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Object/ObjectIterator.hpp b/include/lib/ArduinoJson/Object/ObjectIterator.hpp new file mode 100644 index 0000000..d729459 --- /dev/null +++ b/include/lib/ArduinoJson/Object/ObjectIterator.hpp @@ -0,0 +1,123 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Object/Pair.hpp> +#include <ArduinoJson/Variant/SlotFunctions.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +class PairPtr { + public: + PairPtr(MemoryPool *pool, VariantSlot *slot) : _pair(pool, slot) {} + + const Pair *operator->() const { + return &_pair; + } + + const Pair &operator*() const { + return _pair; + } + + private: + Pair _pair; +}; + +class ObjectIterator { + public: + ObjectIterator() : _slot(0) {} + + explicit ObjectIterator(MemoryPool *pool, VariantSlot *slot) + : _pool(pool), _slot(slot) {} + + Pair operator*() const { + return Pair(_pool, _slot); + } + PairPtr operator->() { + return PairPtr(_pool, _slot); + } + + bool operator==(const ObjectIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ObjectIterator &other) const { + return _slot != other._slot; + } + + ObjectIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ObjectIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + VariantSlot *internal() { + return _slot; + } + + private: + MemoryPool *_pool; + VariantSlot *_slot; +}; + +class PairConstPtr { + public: + PairConstPtr(const VariantSlot *slot) : _pair(slot) {} + + const PairConst *operator->() const { + return &_pair; + } + + const PairConst &operator*() const { + return _pair; + } + + private: + PairConst _pair; +}; + +class ObjectConstIterator { + public: + ObjectConstIterator() : _slot(0) {} + + explicit ObjectConstIterator(const VariantSlot *slot) : _slot(slot) {} + + PairConst operator*() const { + return PairConst(_slot); + } + PairConstPtr operator->() { + return PairConstPtr(_slot); + } + + bool operator==(const ObjectConstIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ObjectConstIterator &other) const { + return _slot != other._slot; + } + + ObjectConstIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ObjectConstIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + const VariantSlot *internal() { + return _slot; + } + + private: + const VariantSlot *_slot; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Object/ObjectRef.hpp b/include/lib/ArduinoJson/Object/ObjectRef.hpp new file mode 100644 index 0000000..c945fb6 --- /dev/null +++ b/include/lib/ArduinoJson/Object/ObjectRef.hpp @@ -0,0 +1,277 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Object/ObjectFunctions.hpp> +#include <ArduinoJson/Object/ObjectIterator.hpp> + +// Returns the size (in bytes) of an object with n elements. +// Can be very handy to determine the size of a StaticMemoryPool. +#define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \ + ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::VariantSlot)) + +namespace ARDUINOJSON_NAMESPACE { + +template <typename TData> +class ObjectRefBase { + public: + operator VariantConstRef() const { + const void* data = _data; // prevent warning cast-align + return VariantConstRef(reinterpret_cast<const VariantData*>(data)); + } + + template <typename TVisitor> + typename TVisitor::result_type accept(TVisitor& visitor) const { + return objectAccept(_data, visitor); + } + + FORCE_INLINE bool isNull() const { + return _data == 0; + } + + FORCE_INLINE operator bool() const { + return _data != 0; + } + + FORCE_INLINE size_t memoryUsage() const { + return _data ? _data->memoryUsage() : 0; + } + + FORCE_INLINE size_t nesting() const { + return _data ? _data->nesting() : 0; + } + + FORCE_INLINE size_t size() const { + return _data ? _data->size() : 0; + } + + protected: + ObjectRefBase(TData* data) : _data(data) {} + TData* _data; +}; + +class ObjectConstRef : public ObjectRefBase<const CollectionData>, + public Visitable { + friend class ObjectRef; + typedef ObjectRefBase<const CollectionData> base_type; + + public: + typedef ObjectConstIterator iterator; + + ObjectConstRef() : base_type(0) {} + ObjectConstRef(const CollectionData* data) : base_type(data) {} + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + // containsKey(const std::string&) const + // containsKey(const String&) const + template <typename TString> + FORCE_INLINE bool containsKey(const TString& key) const { + return !getMember(key).isUndefined(); + } + + // containsKey(char*) const + // containsKey(const char*) const + // containsKey(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE bool containsKey(TChar* key) const { + return !getMember(key).isUndefined(); + } + + // getMember(const std::string&) const + // getMember(const String&) const + template <typename TString> + FORCE_INLINE VariantConstRef getMember(const TString& key) const { + return get_impl(adaptString(key)); + } + + // getMember(char*) const + // getMember(const char*) const + // getMember(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE VariantConstRef getMember(TChar* key) const { + return get_impl(adaptString(key)); + } + + // operator[](const std::string&) const + // operator[](const String&) const + template <typename TString> + FORCE_INLINE + typename enable_if<IsString<TString>::value, VariantConstRef>::type + operator[](const TString& key) const { + return get_impl(adaptString(key)); + } + + // operator[](char*) const + // operator[](const char*) const + // operator[](const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE + typename enable_if<IsString<TChar*>::value, VariantConstRef>::type + operator[](TChar* key) const { + return get_impl(adaptString(key)); + } + + FORCE_INLINE bool operator==(ObjectConstRef rhs) const { + return objectEquals(_data, rhs._data); + } + + private: + template <typename TAdaptedString> + FORCE_INLINE VariantConstRef get_impl(TAdaptedString key) const { + return VariantConstRef(objectGetMember(_data, key)); + } +}; + +class ObjectRef : public ObjectRefBase<CollectionData>, + public ObjectShortcuts<ObjectRef>, + public Visitable { + typedef ObjectRefBase<CollectionData> base_type; + + public: + typedef ObjectIterator iterator; + + FORCE_INLINE ObjectRef() : base_type(0), _pool(0) {} + FORCE_INLINE ObjectRef(MemoryPool* buf, CollectionData* data) + : base_type(data), _pool(buf) {} + + operator VariantRef() const { + void* data = _data; // prevent warning cast-align + return VariantRef(_pool, reinterpret_cast<VariantData*>(data)); + } + + operator ObjectConstRef() const { + return ObjectConstRef(_data); + } + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_pool, _data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + void clear() const { + if (!_data) + return; + _data->clear(); + } + + FORCE_INLINE bool set(ObjectConstRef src) { + if (!_data || !src._data) + return false; + return _data->copyFrom(*src._data, _pool); + } + + // getMember(const std::string&) const + // getMember(const String&) const + template <typename TString> + FORCE_INLINE VariantRef getMember(const TString& key) const { + return VariantRef(_pool, objectGetMember(_data, adaptString(key))); + } + + // getMember(char*) const + // getMember(const char*) const + // getMember(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE VariantRef getMember(TChar* key) const { + return VariantRef(_pool, objectGetMember(_data, adaptString(key))); + } + + // getOrAddMember(const std::string&) const + // getOrAddMember(const String&) const + template <typename TString> + FORCE_INLINE VariantRef getOrAddMember(const TString& key) const { + return VariantRef(_pool, + objectGetOrAddMember(_data, adaptString(key), _pool)); + } + + // getOrAddMember(char*) const + // getOrAddMember(const char*) const + // getOrAddMember(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE VariantRef getOrAddMember(TChar* key) const { + return VariantRef(_pool, + objectGetOrAddMember(_data, adaptString(key), _pool)); + } + + FORCE_INLINE bool operator==(ObjectRef rhs) const { + return objectEquals(_data, rhs._data); + } + + FORCE_INLINE void remove(iterator it) const { + if (!_data) + return; + _data->removeSlot(it.internal()); + } + + // remove(const std::string&) const + // remove(const String&) const + template <typename TString> + FORCE_INLINE void remove(const TString& key) const { + objectRemove(_data, adaptString(key)); + } + + // remove(char*) const + // remove(const char*) const + // remove(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE void remove(TChar* key) const { + objectRemove(_data, adaptString(key)); + } + + private: + MemoryPool* _pool; +}; + +template <> +struct Converter<ObjectConstRef> { + static bool toJson(VariantConstRef src, VariantRef dst) { + return variantCopyFrom(getData(dst), getData(src), getPool(dst)); + } + + static ObjectConstRef fromJson(VariantConstRef src) { + return ObjectConstRef(variantAsObject(getData(src))); + } + + static bool checkJson(VariantConstRef src) { + const VariantData* data = getData(src); + return data && data->isObject(); + } +}; + +template <> +struct Converter<ObjectRef> { + static bool toJson(VariantConstRef src, VariantRef dst) { + return variantCopyFrom(getData(dst), getData(src), getPool(dst)); + } + + static ObjectRef fromJson(VariantRef src) { + VariantData* data = getData(src); + MemoryPool* pool = getPool(src); + return ObjectRef(pool, data != 0 ? data->asObject() : 0); + } + + static bool checkJson(VariantConstRef) { + return false; + } + + static bool checkJson(VariantRef src) { + VariantData* data = getData(src); + return data && data->isObject(); + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Object/ObjectShortcuts.hpp b/include/lib/ArduinoJson/Object/ObjectShortcuts.hpp new file mode 100644 index 0000000..0f3409f --- /dev/null +++ b/include/lib/ArduinoJson/Object/ObjectShortcuts.hpp @@ -0,0 +1,73 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Polyfills/attributes.hpp> +#include <ArduinoJson/Polyfills/type_traits.hpp> +#include <ArduinoJson/Strings/StringAdapters.hpp> + +namespace ARDUINOJSON_NAMESPACE { +template <typename TParent, typename TStringRef> +class MemberProxy; + +template <typename TObject> +class ObjectShortcuts { + public: + // containsKey(const std::string&) const + // containsKey(const String&) const + template <typename TString> + FORCE_INLINE typename enable_if<IsString<TString>::value, bool>::type + containsKey(const TString &key) const; + + // containsKey(char*) const + // containsKey(const char*) const + // containsKey(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE typename enable_if<IsString<TChar *>::value, bool>::type + containsKey(TChar *key) const; + + // operator[](const std::string&) const + // operator[](const String&) const + template <typename TString> + FORCE_INLINE typename enable_if<IsString<TString>::value, + MemberProxy<TObject, TString> >::type + operator[](const TString &key) const; + + // operator[](char*) const + // operator[](const char*) const + // operator[](const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE typename enable_if<IsString<TChar *>::value, + MemberProxy<TObject, TChar *> >::type + operator[](TChar *key) const; + + // createNestedArray(const std::string&) const + // createNestedArray(const String&) const + template <typename TString> + FORCE_INLINE ArrayRef createNestedArray(const TString &key) const; + + // createNestedArray(char*) const + // createNestedArray(const char*) const + // createNestedArray(const __FlashStringHelper*) const + template <typename TChar> + FORCE_INLINE ArrayRef createNestedArray(TChar *key) const; + + // createNestedObject(const std::string&) const + // createNestedObject(const String&) const + template <typename TString> + ObjectRef createNestedObject(const TString &key) const; + + // createNestedObject(char*) const + // createNestedObject(const char*) const + // createNestedObject(const __FlashStringHelper*) const + template <typename TChar> + ObjectRef createNestedObject(TChar *key) const; + + private: + const TObject *impl() const { + return static_cast<const TObject *>(this); + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Object/Pair.hpp b/include/lib/ArduinoJson/Object/Pair.hpp new file mode 100644 index 0000000..44fce75 --- /dev/null +++ b/include/lib/ArduinoJson/Object/Pair.hpp @@ -0,0 +1,55 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Strings/String.hpp> +#include <ArduinoJson/Variant/VariantRef.hpp> + +namespace ARDUINOJSON_NAMESPACE { +// A key value pair for CollectionData. +class Pair { + public: + Pair(MemoryPool* pool, VariantSlot* slot) { + if (slot) { + _key = String(slot->key(), !slot->ownsKey()); + _value = VariantRef(pool, slot->data()); + } + } + + String key() const { + return _key; + } + + VariantRef value() const { + return _value; + } + + private: + String _key; + VariantRef _value; +}; + +class PairConst { + public: + PairConst(const VariantSlot* slot) { + if (slot) { + _key = String(slot->key(), !slot->ownsKey()); + _value = VariantConstRef(slot->data()); + } + } + + String key() const { + return _key; + } + + VariantConstRef value() const { + return _value; + } + + private: + String _key; + VariantConstRef _value; +}; +} // namespace ARDUINOJSON_NAMESPACE |