Skip to content

Commit

Permalink
Renamed JsonVariant::invalid<T>() to JsonVariant::defaultValue<T>()
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed May 18, 2016
1 parent a3a2ca4 commit 9b3e3a3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HEAD
----

* Added `JsonVariant::success()` (issue #279)
* Renamed `JsonVariant::invalid<T>()` to `JsonVariant::defaultValue<T>()`

v5.4.0
------
Expand Down
6 changes: 3 additions & 3 deletions include/ArduinoJson/JsonArray.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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();
}

Expand Down
9 changes: 4 additions & 5 deletions include/ArduinoJson/JsonObject.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 5 additions & 2 deletions include/ArduinoJson/JsonVariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions include/ArduinoJson/JsonVariant.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9b3e3a3

Please sign in to comment.