|
@@ -21,10 +21,22 @@ class JsonObjectSubscript;
|
|
|
template <typename TImpl>
|
|
template <typename TImpl>
|
|
|
class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
public:
|
|
public:
|
|
|
- // DEPRECATED: use as<char*>() instead
|
|
|
|
|
|
|
+#if ARDUINOJSON_ENABLE_DEPRECATED
|
|
|
|
|
+ DEPRECATED("use as<JsonArray>() instead")
|
|
|
|
|
+ FORCE_INLINE JsonArray &asArray() const {
|
|
|
|
|
+ return as<JsonArray>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DEPRECATED("use as<JsonObject>() instead")
|
|
|
|
|
+ FORCE_INLINE JsonObject &asObject() const {
|
|
|
|
|
+ return as<JsonObject>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DEPRECATED("use as<char*>() instead")
|
|
|
FORCE_INLINE const char *asString() const {
|
|
FORCE_INLINE const char *asString() const {
|
|
|
return as<const char *>();
|
|
return as<const char *>();
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
// Gets the variant as an array.
|
|
// Gets the variant as an array.
|
|
|
// Returns a reference to the JsonArray or JsonArray::invalid() if the
|
|
// Returns a reference to the JsonArray or JsonArray::invalid() if the
|
|
@@ -34,11 +46,6 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
return as<JsonArray &>();
|
|
return as<JsonArray &>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // DEPRECATED: use as<JsonArray>() instead
|
|
|
|
|
- FORCE_INLINE JsonArray &asArray() const {
|
|
|
|
|
- return as<JsonArray &>();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// Gets the variant as an object.
|
|
// Gets the variant as an object.
|
|
|
// Returns a reference to the JsonObject or JsonObject::invalid() if the
|
|
// Returns a reference to the JsonObject or JsonObject::invalid() if the
|
|
|
// variant is not an object.
|
|
// variant is not an object.
|
|
@@ -46,11 +53,6 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
return as<JsonObject &>();
|
|
return as<JsonObject &>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // DEPRECATED: use as<JsonObject>() instead
|
|
|
|
|
- FORCE_INLINE JsonObject &asObject() const {
|
|
|
|
|
- return as<JsonObject &>();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
FORCE_INLINE operator T() const {
|
|
FORCE_INLINE operator T() const {
|
|
|
return as<T>();
|
|
return as<T>();
|
|
@@ -65,7 +67,7 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
// Returns the size of the array or object if the variant has that type.
|
|
// Returns the size of the array or object if the variant has that type.
|
|
|
// Returns 0 if the variant is neither an array nor an object
|
|
// Returns 0 if the variant is neither an array nor an object
|
|
|
size_t size() const {
|
|
size_t size() const {
|
|
|
- return asArray().size() + asObject().size();
|
|
|
|
|
|
|
+ return as<JsonArray>().size() + as<JsonObject>().size();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Mimics an array.
|
|
// Mimics an array.
|
|
@@ -86,7 +88,7 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
Internals::StringTraits<TString>::has_equals,
|
|
Internals::StringTraits<TString>::has_equals,
|
|
|
const JsonObjectSubscript<const TString &> >::type
|
|
const JsonObjectSubscript<const TString &> >::type
|
|
|
operator[](const TString &key) const {
|
|
operator[](const TString &key) const {
|
|
|
- return asObject()[key];
|
|
|
|
|
|
|
+ return as<JsonObject>()[key];
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
|
// const JsonObjectSubscript operator[](TKey) const;
|
|
// const JsonObjectSubscript operator[](TKey) const;
|
|
@@ -96,7 +98,7 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
Internals::StringTraits<TString>::has_equals,
|
|
Internals::StringTraits<TString>::has_equals,
|
|
|
JsonObjectSubscript<const TString &> >::type
|
|
JsonObjectSubscript<const TString &> >::type
|
|
|
operator[](const TString &key) {
|
|
operator[](const TString &key) {
|
|
|
- return asObject()[key];
|
|
|
|
|
|
|
+ return as<JsonObject>()[key];
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
|
// JsonObjectSubscript operator[](TKey);
|
|
// JsonObjectSubscript operator[](TKey);
|
|
@@ -106,7 +108,7 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
Internals::StringTraits<TString *>::has_equals,
|
|
Internals::StringTraits<TString *>::has_equals,
|
|
|
JsonObjectSubscript<const TString *> >::type
|
|
JsonObjectSubscript<const TString *> >::type
|
|
|
operator[](const TString *key) {
|
|
operator[](const TString *key) {
|
|
|
- return asObject()[key];
|
|
|
|
|
|
|
+ return as<JsonObject>()[key];
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
|
// JsonObjectSubscript operator[](TKey);
|
|
// JsonObjectSubscript operator[](TKey);
|
|
@@ -116,7 +118,7 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
|
|
Internals::StringTraits<TString *>::has_equals,
|
|
Internals::StringTraits<TString *>::has_equals,
|
|
|
const JsonObjectSubscript<const TString *> >::type
|
|
const JsonObjectSubscript<const TString *> >::type
|
|
|
operator[](const TString *key) const {
|
|
operator[](const TString *key) const {
|
|
|
- return asObject()[key];
|
|
|
|
|
|
|
+ return as<JsonObject>()[key];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
private:
|