Renamed JsonValue to JsonVariant

This commit is contained in:
Benoit Blanchon
2014-11-04 09:51:25 +01:00
parent 699292b058
commit 09f6d059a7
31 changed files with 175 additions and 175 deletions

View File

@ -6,7 +6,7 @@
#pragma once
#include "../JsonValue.hpp"
#include "../JsonVariant.hpp"
namespace ArduinoJson {
namespace Internals {
@ -15,7 +15,7 @@ struct JsonArrayNode {
JsonArrayNode() : next(NULL) {}
JsonArrayNode* next;
JsonValue value;
JsonVariant value;
};
}
}

View File

@ -25,10 +25,10 @@ class JsonParser {
bool skip(const char *wordToSkip);
void skipSpaces();
void parseAnythingTo(JsonValue &destination);
inline void parseBooleanTo(JsonValue &destination);
inline void parseNullTo(JsonValue &destination);
inline void parseNumberTo(JsonValue &destination);
void parseAnythingTo(JsonVariant &destination);
inline void parseBooleanTo(JsonVariant &destination);
inline void parseNullTo(JsonVariant &destination);
inline void parseNumberTo(JsonVariant &destination);
inline const char *parseString();
JsonBuffer *_buffer;

View File

@ -13,7 +13,7 @@ class JsonObject;
namespace Internals {
union JsonValueContent {
union JsonVariantContent {
bool asBoolean;
double asDouble;
long asLong;

View File

@ -9,7 +9,7 @@
namespace ArduinoJson {
namespace Internals {
enum JsonValueType {
enum JsonVariantType {
JSON_UNDEFINED,
JSON_INVALID,
JSON_ARRAY,

View File

@ -24,7 +24,7 @@ class JsonArray : public JsonPrintable<JsonArray>,
friend class JsonBuffer;
public:
typedef JsonValue value_type;
typedef JsonVariant value_type;
typedef JsonArrayIterator iterator;
typedef JsonArrayConstIterator const_iterator;

View File

@ -15,8 +15,8 @@ class JsonArrayConstIterator {
explicit JsonArrayConstIterator(Internals::JsonArrayNode *node)
: _node(node) {}
const JsonValue &operator*() const { return _node->value; }
const JsonValue *operator->() { return &_node->value; }
const JsonVariant &operator*() const { return _node->value; }
const JsonVariant *operator->() { return &_node->value; }
bool operator==(const JsonArrayConstIterator &other) const {
return _node == other._node;

View File

@ -14,8 +14,8 @@ class JsonArrayIterator {
public:
explicit JsonArrayIterator(Internals::JsonArrayNode *node) : _node(node) {}
JsonValue &operator*() const { return _node->value; }
JsonValue *operator->() { return &_node->value; }
JsonVariant &operator*() const { return _node->value; }
JsonVariant *operator->() { return &_node->value; }
bool operator==(const JsonArrayIterator &other) const {
return _node == other._node;

View File

@ -6,7 +6,7 @@
#pragma once
#include "JsonValue.hpp"
#include "JsonVariant.hpp"
namespace ArduinoJson {
class JsonArray;

View File

@ -33,10 +33,10 @@ class JsonObject : public JsonPrintable<JsonObject>,
bool success() const { return _buffer != NULL; }
int size() const;
JsonValue &at(key_type key);
const JsonValue &at(key_type key) const;
JsonValue &operator[](key_type key);
const JsonValue &operator[](key_type key) const { return at(key); }
JsonVariant &at(key_type key);
const JsonVariant &at(key_type key) const;
JsonVariant &operator[](key_type key);
const JsonVariant &operator[](key_type key) const { return at(key); }
void remove(key_type key);
@ -65,7 +65,7 @@ class JsonObject : public JsonPrintable<JsonObject>,
// constructor is private, instance must be created via JsonBuffer
JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
JsonValue &add(key_type key) { return (*this)[key]; }
JsonVariant &add(key_type key) { return (*this)[key]; }
Internals::JsonObjectNode *createNode(key_type key);
void addNode(Internals::JsonObjectNode *nodeToAdd);
void removeNode(Internals::JsonObjectNode *nodeToRemove);

View File

@ -6,7 +6,7 @@
#pragma once
#include "JsonValue.hpp"
#include "JsonVariant.hpp"
namespace ArduinoJson {
@ -14,6 +14,6 @@ struct JsonPair {
JsonPair(const char* k) : key(k) {}
const char* key;
JsonValue value;
JsonVariant value;
};
}

View File

@ -9,8 +9,8 @@
#include <stddef.h>
#include <stdint.h> // for uint8_t
#include "Internals/JsonValueContent.hpp"
#include "Internals/JsonValueType.hpp"
#include "Internals/JsonVariantContent.hpp"
#include "Internals/JsonVariantType.hpp"
namespace ArduinoJson {
@ -21,9 +21,9 @@ namespace Internals {
class JsonWriter;
}
class JsonValue {
class JsonVariant {
public:
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
JsonVariant() : _type(Internals::JSON_UNDEFINED) {}
void set(bool value);
void set(double value, uint8_t decimals = 2);
@ -40,17 +40,17 @@ class JsonValue {
void set(JsonObject &object);
template <typename T>
JsonValue &operator=(T value) {
JsonVariant &operator=(T value) {
set(value);
return *this;
}
JsonValue &operator=(JsonArray &array) {
JsonVariant &operator=(JsonArray &array) {
set(array);
return *this;
}
JsonValue &operator=(JsonObject &object) {
JsonVariant &operator=(JsonObject &object) {
set(object);
return *this;
}
@ -84,7 +84,7 @@ class JsonValue {
return false;
}
static JsonValue &invalid() { return _invalid; }
static JsonVariant &invalid() { return _invalid; }
bool success() { return _type != Internals::JSON_INVALID; }
@ -92,80 +92,80 @@ class JsonValue {
void writeTo(T &writer) const;
private:
JsonValue(Internals::JsonValueType type) : _type(type) {}
JsonVariant(Internals::JsonVariantType type) : _type(type) {}
Internals::JsonValueType _type;
Internals::JsonValueContent _content;
static JsonValue _invalid;
Internals::JsonVariantType _type;
Internals::JsonVariantContent _content;
static JsonVariant _invalid;
};
template <>
inline bool JsonValue::is<long>() const {
inline bool JsonVariant::is<long>() const {
return _type == Internals::JSON_LONG;
}
template <>
inline bool JsonValue::is<double>() const {
inline bool JsonVariant::is<double>() const {
return _type >= Internals::JSON_DOUBLE_0_DECIMALS;
}
template <typename T>
inline bool operator==(const JsonValue &left, T right) {
inline bool operator==(const JsonVariant &left, T right) {
return left.as<T>() == right;
}
template <typename T>
inline bool operator==(T left, const JsonValue &right) {
inline bool operator==(T left, const JsonVariant &right) {
return left == right.as<T>();
}
template <typename T>
inline bool operator!=(const JsonValue &left, T right) {
inline bool operator!=(const JsonVariant &left, T right) {
return left.as<T>() != right;
}
template <typename T>
inline bool operator!=(T left, const JsonValue &right) {
inline bool operator!=(T left, const JsonVariant &right) {
return left != right.as<T>();
}
template <typename T>
inline bool operator<=(const JsonValue &left, T right) {
inline bool operator<=(const JsonVariant &left, T right) {
return left.as<T>() <= right;
}
template <typename T>
inline bool operator<=(T left, const JsonValue &right) {
inline bool operator<=(T left, const JsonVariant &right) {
return left <= right.as<T>();
}
template <typename T>
inline bool operator>=(const JsonValue &left, T right) {
inline bool operator>=(const JsonVariant &left, T right) {
return left.as<T>() >= right;
}
template <typename T>
inline bool operator>=(T left, const JsonValue &right) {
inline bool operator>=(T left, const JsonVariant &right) {
return left >= right.as<T>();
}
template <typename T>
inline bool operator<(const JsonValue &left, T right) {
inline bool operator<(const JsonVariant &left, T right) {
return left.as<T>() < right;
}
template <typename T>
inline bool operator<(T left, const JsonValue &right) {
inline bool operator<(T left, const JsonVariant &right) {
return left < right.as<T>();
}
template <typename T>
inline bool operator>(const JsonValue &left, T right) {
inline bool operator>(const JsonVariant &left, T right) {
return left.as<T>() > right;
}
template <typename T>
inline bool operator>(T left, const JsonValue &right) {
inline bool operator>(T left, const JsonVariant &right) {
return left > right.as<T>();
}
}