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