|
|
@@ -25,18 +25,26 @@ class VariantRefBase : public VariantTag {
|
|
|
friend class VariantAttorney;
|
|
|
|
|
|
public:
|
|
|
+ // Sets the value to null.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the previous value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/clear/
|
|
|
FORCE_INLINE void clear() const {
|
|
|
variantSetNull(getData());
|
|
|
}
|
|
|
|
|
|
+ // Returns true if the value is null or the reference is unbound.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/isnull/
|
|
|
FORCE_INLINE bool isNull() const {
|
|
|
return variantIsNull(getData());
|
|
|
}
|
|
|
|
|
|
+ // Returns true if the reference is unbound.
|
|
|
FORCE_INLINE bool isUnbound() const {
|
|
|
return !getData();
|
|
|
}
|
|
|
|
|
|
+ // Casts the value to the specified type.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/as/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<!is_same<T, char*>::value &&
|
|
|
!is_same<T, char>::value &&
|
|
|
@@ -46,12 +54,16 @@ class VariantRefBase : public VariantTag {
|
|
|
return Converter<T>::fromJson(getVariantConst());
|
|
|
}
|
|
|
|
|
|
+ // Casts the value to the specified type.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/as/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
|
|
|
as() const {
|
|
|
return Converter<T>::fromJson(getVariant());
|
|
|
}
|
|
|
|
|
|
+ // Deprecated: use as<const char*>() instead.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/as/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<is_same<T, char*>::value, const char*>::type
|
|
|
ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()")
|
|
|
@@ -59,6 +71,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return as<const char*>();
|
|
|
}
|
|
|
|
|
|
+ // Deprecated: use as<int8_t>() or as<uint8_t>() instead.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/as/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<is_same<T, char>::value, char>::type
|
|
|
ARDUINOJSON_DEPRECATED(
|
|
|
@@ -72,22 +86,28 @@ class VariantRefBase : public VariantTag {
|
|
|
return as<T>();
|
|
|
}
|
|
|
|
|
|
- // Change the type of the variant
|
|
|
- //
|
|
|
- // JsonArray to<JsonArray>()
|
|
|
+ // Sets the value to an empty array.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the previous value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/to/
|
|
|
template <typename T>
|
|
|
typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type to() const;
|
|
|
- //
|
|
|
- // JsonObject to<JsonObject>()
|
|
|
+
|
|
|
+ // Sets the value to an empty object.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the previous value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/to/
|
|
|
template <typename T>
|
|
|
typename enable_if<is_same<T, JsonObject>::value, JsonObject>::type to()
|
|
|
const;
|
|
|
- //
|
|
|
- // JsonVariant to<JsonVariant>()
|
|
|
+
|
|
|
+ // Sets the value to null.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the previous value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/to/
|
|
|
template <typename T>
|
|
|
typename enable_if<is_same<T, JsonVariant>::value, JsonVariant>::type to()
|
|
|
const;
|
|
|
|
|
|
+ // Returns true if the value is of the specified type.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/is/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE
|
|
|
typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
|
|
|
@@ -95,6 +115,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return Converter<T>::checkJson(getVariant());
|
|
|
}
|
|
|
|
|
|
+ // Returns true if the value is of the specified type.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/is/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<!ConverterNeedsWriteableRef<T>::value &&
|
|
|
!is_same<T, char*>::value &&
|
|
|
@@ -104,6 +126,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return Converter<T>::checkJson(getVariantConst());
|
|
|
}
|
|
|
|
|
|
+ // Deprecated: use is<const char*>() instead.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/is/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<is_same<T, char*>::value, bool>::type
|
|
|
ARDUINOJSON_DEPRECATED("Replace is<char*>() with is<const char*>()")
|
|
|
@@ -111,6 +135,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return is<const char*>();
|
|
|
}
|
|
|
|
|
|
+ // Deprecated: use is<int8_t>() or is<uint8_t>() instead.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/is/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE typename enable_if<is_same<T, char>::value, bool>::type
|
|
|
ARDUINOJSON_DEPRECATED(
|
|
|
@@ -119,6 +145,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return is<signed char>();
|
|
|
}
|
|
|
|
|
|
+ // Shallow copies the specified value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/shallowcopy/
|
|
|
FORCE_INLINE void shallowCopy(JsonVariantConst target) {
|
|
|
VariantData* data = getOrCreateData();
|
|
|
if (!data)
|
|
|
@@ -130,6 +158,8 @@ class VariantRefBase : public VariantTag {
|
|
|
data->setNull();
|
|
|
}
|
|
|
|
|
|
+ // Copies the specified value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/set/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE bool set(const T& value) const {
|
|
|
Converter<T>::toJson(value, getOrCreateVariant());
|
|
|
@@ -137,6 +167,8 @@ class VariantRefBase : public VariantTag {
|
|
|
return pool && !pool->overflowed();
|
|
|
}
|
|
|
|
|
|
+ // Copies the specified value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/set/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE bool set(T* value) const {
|
|
|
Converter<T*>::toJson(value, getOrCreateVariant());
|
|
|
@@ -144,45 +176,62 @@ class VariantRefBase : public VariantTag {
|
|
|
return pool && !pool->overflowed();
|
|
|
}
|
|
|
|
|
|
+ // Deprecated: use int8_t or uint8_t instead
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/set/
|
|
|
bool ARDUINOJSON_DEPRECATED(
|
|
|
"Support for char is deprecated, use int8_t or uint8_t instead")
|
|
|
set(char value) const;
|
|
|
|
|
|
+ // Returns the size of the array or object.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/size/
|
|
|
FORCE_INLINE size_t size() const {
|
|
|
return variantSize(getData());
|
|
|
}
|
|
|
|
|
|
+ // Returns the number of bytes occupied by the value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/memoryusage/
|
|
|
FORCE_INLINE size_t memoryUsage() const {
|
|
|
VariantData* data = getData();
|
|
|
return data ? data->memoryUsage() : 0;
|
|
|
}
|
|
|
|
|
|
+ // Returns the depth (nesting level) of the value.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/nesting/
|
|
|
FORCE_INLINE size_t nesting() const {
|
|
|
return variantNesting(getData());
|
|
|
}
|
|
|
|
|
|
+ // Appends a new (null) element to the array.
|
|
|
+ // Returns a reference to the new element.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/add/
|
|
|
FORCE_INLINE JsonVariant add() const;
|
|
|
|
|
|
+ // Appends a value to the array.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/add/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE bool add(const T& value) const {
|
|
|
return add().set(value);
|
|
|
}
|
|
|
- //
|
|
|
- // bool add(TValue);
|
|
|
- // TValue = char*, const char*, const __FlashStringHelper*
|
|
|
+
|
|
|
+ // Appends a value to the array.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/add/
|
|
|
template <typename T>
|
|
|
FORCE_INLINE bool add(T* value) const {
|
|
|
return add().set(value);
|
|
|
}
|
|
|
|
|
|
+ // Removes an element of the array.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the removed element.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/remove/
|
|
|
FORCE_INLINE void remove(size_t index) const {
|
|
|
VariantData* data = getData();
|
|
|
if (data)
|
|
|
data->remove(index);
|
|
|
}
|
|
|
- // remove(char*) const
|
|
|
- // remove(const char*) const
|
|
|
- // remove(const __FlashStringHelper*) const
|
|
|
+
|
|
|
+ // Removes a member of the object.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the removed element.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/remove/
|
|
|
template <typename TChar>
|
|
|
FORCE_INLINE typename enable_if<IsString<TChar*>::value>::type remove(
|
|
|
TChar* key) const {
|
|
|
@@ -190,8 +239,10 @@ class VariantRefBase : public VariantTag {
|
|
|
if (data)
|
|
|
data->remove(adaptString(key));
|
|
|
}
|
|
|
- // remove(const std::string&) const
|
|
|
- // remove(const String&) const
|
|
|
+
|
|
|
+ // Removes a member of the object.
|
|
|
+ // ⚠️ Doesn't release the memory associated with the removed element.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/remove/
|
|
|
template <typename TString>
|
|
|
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
|
|
const TString& key) const {
|
|
|
@@ -200,37 +251,61 @@ class VariantRefBase : public VariantTag {
|
|
|
data->remove(adaptString(key));
|
|
|
}
|
|
|
|
|
|
+ // Creates an array and appends it to the array.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
|
|
FORCE_INLINE JsonArray createNestedArray() const;
|
|
|
+
|
|
|
+ // Creates an object and appends it to the array.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
|
|
FORCE_INLINE JsonObject createNestedObject() const;
|
|
|
+
|
|
|
+ // Gets or sets an array element.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/subscript/
|
|
|
FORCE_INLINE ElementProxy<TDerived> operator[](size_t index) const;
|
|
|
|
|
|
+ // Returns true if the object contains the specified key.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/containskey/
|
|
|
template <typename TString>
|
|
|
FORCE_INLINE typename enable_if<IsString<TString>::value, bool>::type
|
|
|
containsKey(const TString& key) const;
|
|
|
|
|
|
+ // Returns true if the object contains the specified key.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/containskey/
|
|
|
template <typename TChar>
|
|
|
FORCE_INLINE typename enable_if<IsString<TChar*>::value, bool>::type
|
|
|
containsKey(TChar* key) const;
|
|
|
|
|
|
+ // Gets or sets an object member.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/subscript/
|
|
|
template <typename TString>
|
|
|
FORCE_INLINE typename enable_if<IsString<TString>::value,
|
|
|
MemberProxy<TDerived, TString> >::type
|
|
|
operator[](const TString& key) const;
|
|
|
|
|
|
+ // Gets or sets an object member.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/subscript/
|
|
|
template <typename TChar>
|
|
|
FORCE_INLINE typename enable_if<IsString<TChar*>::value,
|
|
|
MemberProxy<TDerived, TChar*> >::type
|
|
|
operator[](TChar* key) const;
|
|
|
|
|
|
+ // Creates an array and adds it to the object.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
|
|
template <typename TString>
|
|
|
FORCE_INLINE JsonArray createNestedArray(const TString& key) const;
|
|
|
|
|
|
+ // Creates an array and adds it to the object.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
|
|
template <typename TChar>
|
|
|
FORCE_INLINE JsonArray createNestedArray(TChar* key) const;
|
|
|
|
|
|
+ // Creates an object and adds it to the object.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
|
|
template <typename TString>
|
|
|
JsonObject createNestedObject(const TString& key) const;
|
|
|
|
|
|
+ // Creates an object and adds it to the object.
|
|
|
+ // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
|
|
template <typename TChar>
|
|
|
JsonObject createNestedObject(TChar* key) const;
|
|
|
|