// Copyright Benoit Blanchon 2014-2017 // MIT License // // Arduino JSON library // https://github.com/bblanchon/ArduinoJson // If you like this project, please add a star! #pragma once #include "Configuration.hpp" #include "JsonVariantBase.hpp" #include "TypeTraits/ConstRefOrConstPtr.hpp" #include "TypeTraits/EnableIf.hpp" #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4522) #endif namespace ArduinoJson { template class JsonObjectSubscript : public JsonVariantBase > { // const String& // const std::string& // const char* typedef typename TypeTraits::ConstRefOrConstPtr::type TStringRef; public: FORCE_INLINE JsonObjectSubscript(JsonObject& object, TStringRef key) : _object(object), _key(key) {} FORCE_INLINE JsonObjectSubscript& operator=( const JsonObjectSubscript& src) { _object.set(_key, src); return *this; } template FORCE_INLINE JsonObjectSubscript& operator=(const T& src) { _object.set(_key, src); return *this; } FORCE_INLINE bool success() const { return _object.containsKey(_key); } template FORCE_INLINE typename Internals::JsonVariantAs::type as() const { return _object.get(_key); } template FORCE_INLINE bool is() const { return _object.is(_key); } template FORCE_INLINE bool set(const TValue& value) { return _object.set(_key, value); } template FORCE_INLINE bool set(const TValue& value, uint8_t decimals) { return _object.set(_key, value, decimals); } private: JsonObject& _object; TStringRef _key; }; #if ARDUINOJSON_ENABLE_STD_STREAM template inline std::ostream& operator<<(std::ostream& os, const JsonObjectSubscript& source) { return source.printTo(os); } #endif template inline JsonObjectSubscript JsonObject::operator[](const TString& key) { return JsonObjectSubscript(*this, key); } } // namespace ArduinoJson #ifdef _MSC_VER #pragma warning(pop) #endif