mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 08:48:30 +01:00
Renamed JsonValue to JsonVariant
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "../../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../../include/ArduinoJson/JsonBuffer.hpp"
|
||||
#include "../../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../../include/ArduinoJson/Internals/QuotedString.hpp"
|
||||
|
||||
@@ -39,7 +39,7 @@ bool JsonParser::skip(const char *wordToSkip) {
|
||||
return *charToSkip == '\0';
|
||||
}
|
||||
|
||||
void JsonParser::parseAnythingTo(JsonValue &destination) {
|
||||
void JsonParser::parseAnythingTo(JsonVariant &destination) {
|
||||
skipSpaces();
|
||||
|
||||
switch (*_ptr) {
|
||||
@@ -91,7 +91,7 @@ JsonArray &JsonParser::parseArray() {
|
||||
if (skip(']')) return array; // empty array
|
||||
|
||||
for (;;) {
|
||||
JsonValue &child = array.add();
|
||||
JsonVariant &child = array.add();
|
||||
|
||||
parseAnythingTo(child);
|
||||
if (!child.success()) return JsonArray::invalid(); // child parsing failed
|
||||
@@ -102,16 +102,16 @@ JsonArray &JsonParser::parseArray() {
|
||||
}
|
||||
}
|
||||
|
||||
void JsonParser::parseBooleanTo(JsonValue &destination) {
|
||||
void JsonParser::parseBooleanTo(JsonVariant &destination) {
|
||||
bool value = *_ptr == 't';
|
||||
|
||||
if (skip(value ? "true" : "false"))
|
||||
destination = value;
|
||||
else
|
||||
destination = JsonValue::invalid();
|
||||
destination = JsonVariant::invalid();
|
||||
}
|
||||
|
||||
void JsonParser::parseNumberTo(JsonValue &destination) {
|
||||
void JsonParser::parseNumberTo(JsonVariant &destination) {
|
||||
char *endOfLong;
|
||||
long longValue = strtol(_ptr, &endOfLong, 10);
|
||||
|
||||
@@ -126,11 +126,11 @@ void JsonParser::parseNumberTo(JsonValue &destination) {
|
||||
}
|
||||
}
|
||||
|
||||
void JsonParser::parseNullTo(JsonValue &destination) {
|
||||
void JsonParser::parseNullTo(JsonVariant &destination) {
|
||||
if (skip("null"))
|
||||
destination = static_cast<const char *>(NULL);
|
||||
else
|
||||
destination = JsonValue::invalid();
|
||||
destination = JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonObject &JsonParser::parseObject() {
|
||||
@@ -148,7 +148,7 @@ JsonObject &JsonParser::parseObject() {
|
||||
|
||||
if (!skip(':')) break; // colon is missing
|
||||
|
||||
JsonValue &value = object[key];
|
||||
JsonVariant &value = object[key];
|
||||
|
||||
parseAnythingTo(value);
|
||||
if (!value.success()) break; // value parsing failed
|
||||
|
||||
@@ -22,15 +22,15 @@ int JsonArray::size() const {
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
JsonValue &JsonArray::at(int index) const {
|
||||
JsonVariant &JsonArray::at(int index) const {
|
||||
JsonArrayNode *node = _firstNode;
|
||||
while (node && index--) node = node->next;
|
||||
return node ? node->value : JsonValue::invalid();
|
||||
return node ? node->value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonValue &JsonArray::add() {
|
||||
JsonVariant &JsonArray::add() {
|
||||
JsonArrayNode *node = createNode();
|
||||
if (!node) return JsonValue::invalid();
|
||||
if (!node) return JsonVariant::invalid();
|
||||
|
||||
addNode(node);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PlacementNew.hpp"
|
||||
#include "../include/ArduinoJson/Internals/JsonParser.hpp"
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "../include/ArduinoJson/JsonBuffer.hpp"
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||
#include "../include/ArduinoJson/Internals/StringBuilder.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PlacementNew.hpp"
|
||||
@@ -26,19 +26,19 @@ int JsonObject::size() const {
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
JsonValue &JsonObject::at(const char *key) {
|
||||
JsonVariant &JsonObject::at(const char *key) {
|
||||
JsonObjectNode *node = getNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
const JsonValue &JsonObject::at(const char *key) const {
|
||||
const JsonVariant &JsonObject::at(const char *key) const {
|
||||
JsonObjectNode *node = getNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
JsonValue &JsonObject::operator[](const char *key) {
|
||||
JsonVariant &JsonObject::operator[](const char *key) {
|
||||
JsonObjectNode *node = getOrCreateNodeAt(key);
|
||||
return node ? node->pair.value : JsonValue::invalid();
|
||||
return node ? node->pair.value : JsonVariant::invalid();
|
||||
}
|
||||
|
||||
void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include "../include/ArduinoJson/JsonValue.hpp"
|
||||
#include "../include/ArduinoJson/JsonVariant.hpp"
|
||||
#include "../include/ArduinoJson/JsonArray.hpp"
|
||||
#include "../include/ArduinoJson/JsonObject.hpp"
|
||||
#include "../include/ArduinoJson/Internals/PrettyJsonWriter.hpp"
|
||||
@@ -12,70 +12,70 @@
|
||||
using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonValue::_invalid(JSON_INVALID);
|
||||
JsonVariant JsonVariant::_invalid(JSON_INVALID);
|
||||
|
||||
JsonValue::operator JsonArray &() const {
|
||||
JsonVariant::operator JsonArray &() const {
|
||||
return _type == JSON_ARRAY ? *_content.asArray : JsonArray::invalid();
|
||||
}
|
||||
|
||||
JsonValue::operator JsonObject &() const {
|
||||
JsonVariant::operator JsonObject &() const {
|
||||
return _type == JSON_OBJECT ? *_content.asObject : JsonObject::invalid();
|
||||
}
|
||||
|
||||
JsonValue::operator bool() const {
|
||||
JsonVariant::operator bool() const {
|
||||
return _type == JSON_BOOLEAN ? _content.asBoolean : false;
|
||||
}
|
||||
|
||||
JsonValue::operator const char *() const {
|
||||
JsonVariant::operator const char *() const {
|
||||
return _type == JSON_STRING ? _content.asString : NULL;
|
||||
}
|
||||
|
||||
JsonValue::operator double() const {
|
||||
JsonVariant::operator double() const {
|
||||
return _type >= JSON_DOUBLE_0_DECIMALS ? _content.asDouble : 0;
|
||||
}
|
||||
|
||||
JsonValue::operator long() const {
|
||||
JsonVariant::operator long() const {
|
||||
return _type == JSON_LONG ? _content.asLong : 0;
|
||||
}
|
||||
|
||||
void JsonValue::set(bool value) {
|
||||
void JsonVariant::set(bool value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = Internals::JSON_BOOLEAN;
|
||||
_content.asBoolean = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(const char *value) {
|
||||
void JsonVariant::set(const char *value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_STRING;
|
||||
_content.asString = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(double value, uint8_t decimals) {
|
||||
void JsonVariant::set(double value, uint8_t decimals) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = static_cast<JsonValueType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
||||
_type = static_cast<JsonVariantType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
||||
_content.asDouble = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(long value) {
|
||||
void JsonVariant::set(long value) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_LONG;
|
||||
_content.asLong = value;
|
||||
}
|
||||
|
||||
void JsonValue::set(JsonArray &array) {
|
||||
void JsonVariant::set(JsonArray &array) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_ARRAY;
|
||||
_content.asArray = &array;
|
||||
}
|
||||
|
||||
void JsonValue::set(JsonObject &object) {
|
||||
void JsonVariant::set(JsonObject &object) {
|
||||
if (_type == JSON_INVALID) return;
|
||||
_type = JSON_OBJECT;
|
||||
_content.asObject = &object;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void JsonValue::writeTo(T &writer) const {
|
||||
void JsonVariant::writeTo(T &writer) const {
|
||||
switch (_type) {
|
||||
case JSON_ARRAY:
|
||||
_content.asArray->writeTo(writer);
|
||||
@@ -103,5 +103,5 @@ void JsonValue::writeTo(T &writer) const {
|
||||
}
|
||||
}
|
||||
|
||||
template void JsonValue::writeTo(JsonWriter &) const;
|
||||
template void JsonValue::writeTo(PrettyJsonWriter &) const;
|
||||
template void JsonVariant::writeTo(JsonWriter &) const;
|
||||
template void JsonVariant::writeTo(PrettyJsonWriter &) const;
|
||||
Reference in New Issue
Block a user