// Copyright Benoit Blanchon 2014-2016 // MIT License // // Arduino JSON library // https://github.com/bblanchon/ArduinoJson // If you like this project, please add a star! #pragma once #include "JsonObject.hpp" #include "JsonObjectSubscript.hpp" namespace ArduinoJson { inline JsonVariant JsonObject::get(JsonObjectKey key) const { node_type *node = getNodeAt(key); return node ? node->content.value : JsonVariant(); } template inline T JsonObject::get(JsonObjectKey key) const { node_type *node = getNodeAt(key); return node ? node->content.value.as() : JsonVariant::invalid(); } template inline bool JsonObject::is(JsonObjectKey key) const { node_type *node = getNodeAt(key); return node ? node->content.value.is() : false; } inline JsonObjectSubscript JsonObject::operator[]( const char *key) { return JsonObjectSubscript(*this, key); } inline JsonObjectSubscript JsonObject::operator[]( const String &key) { return JsonObjectSubscript(*this, key); } inline JsonVariant JsonObject::operator[](JsonObjectKey key) const { return get(key); } inline bool JsonObject::containsKey(JsonObjectKey key) const { return getNodeAt(key) != NULL; } inline JsonArray &JsonObject::createNestedArray(const char *key) { return createArrayAt(key); } inline JsonArray &JsonObject::createNestedArray(const String &key) { return createArrayAt(key); } inline JsonObject &JsonObject::createNestedObject(const char *key) { return createObjectAt(key); } inline JsonObject &JsonObject::createNestedObject(const String &key) { return createObjectAt(key); } inline void JsonObject::remove(JsonObjectKey key) { removeNode(getNodeAt(key)); } inline bool JsonObject::set(const char *key, bool value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, float value, uint8_t decimals) { return setNodeAt( key, JsonVariant(value, decimals)); } inline bool JsonObject::set(const char *key, double value, uint8_t decimals) { return setNodeAt( key, JsonVariant(value, decimals)); } inline bool JsonObject::set(const char *key, signed char value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, signed long value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, signed int value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, signed short value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, unsigned char value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, unsigned long value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, unsigned int value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, unsigned short value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, const char *value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, const String &value) { return setNodeAt(key, value); } inline bool JsonObject::set(const char *key, JsonArray &array) { return setNodeAt(key, array); } inline bool JsonObject::set(const char *key, JsonObject &object) { return setNodeAt(key, object); } inline bool JsonObject::set(const char *key, const JsonVariant &value) { return setNodeAt(key, value); } template inline bool JsonObject::set(const char *key, const T &value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, bool value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, float value, uint8_t decimals) { return setNodeAt( key, JsonVariant(value, decimals)); } inline bool JsonObject::set(const String &key, double value, uint8_t decimals) { return setNodeAt( key, JsonVariant(value, decimals)); } inline bool JsonObject::set(const String &key, signed char value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, signed long value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, signed int value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, signed short value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, unsigned char value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, unsigned long value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, unsigned int value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, unsigned short value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, const char *value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, const String &value) { return setNodeAt(key, value); } inline bool JsonObject::set(const String &key, JsonArray &array) { return setNodeAt(key, array); } inline bool JsonObject::set(const String &key, JsonObject &object) { return setNodeAt(key, object); } inline bool JsonObject::set(const String &key, const JsonVariant &value) { return setNodeAt(key, value); } template inline bool JsonObject::set(const String &key, const T &value) { return setNodeAt(key, value); } template inline bool JsonObject::setNodeAt(TKey key, TValue value) { node_type *node = getOrCreateNodeAt(key); if (!node) return false; setNodeKey(node, key); setNodeValue(node, value); return true; } template <> inline void JsonObject::setNodeKey(node_type *node, const char *key) { node->content.key = key; } template <> inline void JsonObject::setNodeKey(node_type *node, const String &key) { node->content.key = _buffer->strdup(key); } template inline void JsonObject::setNodeValue(node_type *node, TValue value) { node->content.value = value; } template <> inline void JsonObject::setNodeValue(node_type *node, const String &value) { node->content.value = _buffer->strdup(value); } template inline const JsonObjectSubscript JsonVariantBase:: operator[](const char *key) const { return asObject()[key]; } template inline const JsonObjectSubscript JsonVariantBase:: operator[](const String &key) const { return asObject()[key]; } template <> inline JsonObject const &JsonVariant::invalid() { return JsonObject::invalid(); } template <> inline JsonObject &JsonVariant::invalid() { return JsonObject::invalid(); } template <> inline JsonObject &JsonVariant::as() const { if (_type == Internals::JSON_OBJECT) return *_content.asObject; return JsonObject::invalid(); } template <> inline const JsonObject &JsonVariant::as() const { if (_type == Internals::JSON_OBJECT) return *_content.asObject; return JsonObject::invalid(); } }