2015-05-23 15:32:50 +02:00
|
|
|
// Copyright Benoit Blanchon 2014-2015
|
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "JsonObject.hpp"
|
|
|
|
#include "JsonObjectSubscript.hpp"
|
|
|
|
|
|
|
|
namespace ArduinoJson {
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline JsonVariant JsonObject::get(JsonObjectKey key) const {
|
2015-05-23 15:32:50 +02:00
|
|
|
node_type *node = getNodeAt(key);
|
|
|
|
return node ? node->content.value : JsonVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-05-25 15:38:58 +02:00
|
|
|
inline T JsonObject::get(JsonObjectKey key) const {
|
2015-05-23 15:32:50 +02:00
|
|
|
node_type *node = getNodeAt(key);
|
|
|
|
return node ? node->content.value.as<T>() : JsonVariant::invalid<T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-05-25 15:38:58 +02:00
|
|
|
inline bool JsonObject::is(JsonObjectKey key) const {
|
2015-05-23 15:32:50 +02:00
|
|
|
node_type *node = getNodeAt(key);
|
|
|
|
return node ? node->content.value.is<T>() : false;
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline JsonObjectSubscript JsonObject::operator[](JsonObjectKey key) {
|
2015-05-23 15:32:50 +02:00
|
|
|
return JsonObjectSubscript(*this, key);
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline const JsonObjectSubscript JsonObject::operator[](
|
|
|
|
JsonObjectKey key) const {
|
2015-05-23 15:32:50 +02:00
|
|
|
return JsonObjectSubscript(*const_cast<JsonObject *>(this), key);
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline bool JsonObject::containsKey(JsonObjectKey key) const {
|
2015-05-23 15:32:50 +02:00
|
|
|
return getNodeAt(key) != NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline void JsonObject::remove(JsonObjectKey key) {
|
|
|
|
removeNode(getNodeAt(key));
|
|
|
|
}
|
2015-05-23 15:32:50 +02:00
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
inline bool JsonObject::set(JsonObjectKey key, const JsonVariant value) {
|
2015-05-23 15:32:50 +02:00
|
|
|
node_type *node = getOrCreateNodeAt(key);
|
|
|
|
if (!node) return false;
|
|
|
|
|
|
|
|
node->content.key = key;
|
|
|
|
node->content.value = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename TImplem>
|
|
|
|
inline const JsonObjectSubscript JsonVariantBase<TImplem>::operator[](
|
|
|
|
const char *key) const {
|
|
|
|
return asObject()[key];
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:38:58 +02:00
|
|
|
template <typename TImplem>
|
|
|
|
inline const JsonObjectSubscript JsonVariantBase<TImplem>::operator[](
|
|
|
|
const String &key) const {
|
|
|
|
return asObject()[key];
|
|
|
|
}
|
|
|
|
|
2015-05-23 15:32:50 +02:00
|
|
|
template <>
|
|
|
|
inline JsonObject const &JsonVariant::invalid<JsonObject const &>() {
|
|
|
|
return JsonObject::invalid();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline JsonObject &JsonVariant::invalid<JsonObject &>() {
|
|
|
|
return JsonObject::invalid();
|
|
|
|
}
|
|
|
|
}
|