From 39895a677e5d370824e702cfe90ebc67737b8482 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 May 2021 09:12:09 +0200 Subject: import ArduinoJson 6.18.0 --- include/lib/ArduinoJson/Object/MemberProxy.hpp | 202 +++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 include/lib/ArduinoJson/Object/MemberProxy.hpp (limited to 'include/lib/ArduinoJson/Object/MemberProxy.hpp') 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 +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4522) +#endif + +namespace ARDUINOJSON_NAMESPACE { + +template +class MemberProxy : public VariantOperators >, + public VariantShortcuts >, + public Visitable, + public VariantTag { + typedef MemberProxy 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 + FORCE_INLINE typename enable_if::value, this_type &>::type + operator=(const TValue &src) { + getOrAddUpstreamMember().set(src); + return *this; + } + + // operator=(char*) + // operator=(const char*) + // operator=(const __FlashStringHelper*) + template + 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 + FORCE_INLINE typename enable_if::value, T>::type as() + const { + return getUpstreamMember().template as(); + } + + template + FORCE_INLINE typename enable_if::value, const char *>::type + ARDUINOJSON_DEPRECATED("Replace as() with as()") + as() const { + return as(); + } + + template + FORCE_INLINE operator T() const { + return getUpstreamMember(); + } + + template + FORCE_INLINE bool is() const { + return getUpstreamMember().template is(); + } + + 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 + FORCE_INLINE typename enable_if::value>::type remove( + TChar *key) const { + getUpstreamMember().remove(key); + } + // remove(const std::string&) const + // remove(const String&) const + template + FORCE_INLINE typename enable_if::value>::type remove( + const TString &key) const { + getUpstreamMember().remove(key); + } + + template + FORCE_INLINE typename VariantTo::type to() { + return getOrAddUpstreamMember().template to(); + } + + template + FORCE_INLINE bool set(const TValue &value) { + return getOrAddUpstreamMember().set(value); + } + + // set(char*) const + // set(const char*) const + // set(const __FlashStringHelper*) const + template + FORCE_INLINE bool set(TChar *value) { + return getOrAddUpstreamMember().set(value); + } + + template + 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 + FORCE_INLINE VariantRef getMember(TChar *key) const { + return getUpstreamMember().getMember(key); + } + + // getMember(const std::string&) const + // getMember(const String&) const + template + FORCE_INLINE VariantRef getMember(const TString &key) const { + return getUpstreamMember().getMember(key); + } + + // getOrAddMember(char*) const + // getOrAddMember(const char*) const + // getOrAddMember(const __FlashStringHelper*) const + template + FORCE_INLINE VariantRef getOrAddMember(TChar *key) const { + return getOrAddUpstreamMember().getOrAddMember(key); + } + + // getOrAddMember(const std::string&) const + // getOrAddMember(const String&) const + template + 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 -- cgit v1.2.3