forked from bblanchon/ArduinoJson
Renamed JsonVariant::invalid<T>()
to JsonVariant::defaultValue<T>()
This commit is contained in:
@ -5,6 +5,7 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* Added `JsonVariant::success()` (issue #279)
|
* Added `JsonVariant::success()` (issue #279)
|
||||||
|
* Renamed `JsonVariant::invalid<T>()` to `JsonVariant::defaultValue<T>()`
|
||||||
|
|
||||||
v5.4.0
|
v5.4.0
|
||||||
------
|
------
|
||||||
|
@ -55,7 +55,7 @@ inline JsonVariant JsonArray::get(size_t index) const {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline T JsonArray::get(size_t index) const {
|
inline T JsonArray::get(size_t index) const {
|
||||||
node_type *node = getNodeAt(index);
|
node_type *node = getNodeAt(index);
|
||||||
return node ? node->content.as<T>() : JsonVariant::invalid<T>();
|
return node ? node->content.as<T>() : JsonVariant::defaultValue<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -71,12 +71,12 @@ inline const JsonArraySubscript JsonVariantBase<TImplem>::operator[](
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline JsonArray &JsonVariant::invalid<JsonArray &>() {
|
inline JsonArray &JsonVariant::defaultValue<JsonArray &>() {
|
||||||
return JsonArray::invalid();
|
return JsonArray::invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline JsonArray const &JsonVariant::invalid<JsonArray const &>() {
|
inline JsonArray const &JsonVariant::defaultValue<JsonArray const &>() {
|
||||||
return JsonArray::invalid();
|
return JsonArray::invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ inline JsonVariant JsonObject::get(JsonObjectKey key) const {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline T JsonObject::get(JsonObjectKey key) const {
|
inline T JsonObject::get(JsonObjectKey key) const {
|
||||||
node_type *node = getNodeAt(key.c_str());
|
node_type *node = getNodeAt(key.c_str());
|
||||||
return node ? node->content.value.as<T>() : JsonVariant::invalid<T>();
|
return node ? node->content.value.as<T>() : JsonVariant::defaultValue<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -57,8 +57,7 @@ inline bool JsonObject::setNodeAt(JsonObjectKey key, T value) {
|
|||||||
node_type *node = getNodeAt(key.c_str());
|
node_type *node = getNodeAt(key.c_str());
|
||||||
if (!node) {
|
if (!node) {
|
||||||
node = addNewNode();
|
node = addNewNode();
|
||||||
if (!node || !setNodeKey(node, key))
|
if (!node || !setNodeKey(node, key)) return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return setNodeValue<T>(node, value);
|
return setNodeValue<T>(node, value);
|
||||||
}
|
}
|
||||||
@ -104,12 +103,12 @@ operator[](const String &key) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline JsonObject const &JsonVariant::invalid<JsonObject const &>() {
|
inline JsonObject const &JsonVariant::defaultValue<JsonObject const &>() {
|
||||||
return JsonObject::invalid();
|
return JsonObject::invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline JsonObject &JsonVariant::invalid<JsonObject &>() {
|
inline JsonObject &JsonVariant::defaultValue<JsonObject &>() {
|
||||||
return JsonObject::invalid();
|
return JsonObject::invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,14 +256,17 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
|
|||||||
return isObject();
|
return isObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if the variant has a value
|
||||||
bool success() const { return _type != Internals::JSON_UNDEFINED; }
|
bool success() const { return _type != Internals::JSON_UNDEFINED; }
|
||||||
|
|
||||||
// Serialize the variant to a JsonWriter
|
// Serialize the variant to a JsonWriter
|
||||||
void writeTo(Internals::JsonWriter &writer) const;
|
void writeTo(Internals::JsonWriter &writer) const;
|
||||||
|
|
||||||
// TODO: rename
|
// Value returned if the variant has an incompatible type
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T invalid();
|
static T defaultValue() {
|
||||||
|
return T();
|
||||||
|
}
|
||||||
|
|
||||||
const char *asString() const;
|
const char *asString() const;
|
||||||
JsonArray &asArray() const;
|
JsonArray &asArray() const;
|
||||||
|
@ -41,11 +41,6 @@ inline JsonVariant::JsonVariant(JsonObject &object) {
|
|||||||
_content.asObject = &object;
|
_content.asObject = &object;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline T JsonVariant::invalid() {
|
|
||||||
return T();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Internals::JsonInteger JsonVariant::asInteger() const {
|
inline Internals::JsonInteger JsonVariant::asInteger() const {
|
||||||
using namespace Internals;
|
using namespace Internals;
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
|
Reference in New Issue
Block a user