mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2026-05-05 04:15:24 +02:00
Replace add() with add<T>() (add(T) is still supported)
This commit is contained in:
@@ -41,10 +41,21 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
return JsonArrayConst(data_, resources_);
|
||||
}
|
||||
|
||||
// Appends a new (empty) element to the array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
template <typename T>
|
||||
typename detail::enable_if<!detail::is_same<T, JsonVariant>::value, T>::type
|
||||
add() const {
|
||||
return add<JsonVariant>().to<T>();
|
||||
}
|
||||
|
||||
// Appends a new (null) element to the array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
JsonVariant add() const {
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_same<T, JsonVariant>::value, T>::type
|
||||
add() const {
|
||||
return JsonVariant(detail::ArrayData::addElement(data_, resources_),
|
||||
resources_);
|
||||
}
|
||||
@@ -53,14 +64,14 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(const T& value) const {
|
||||
return add().set(value);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// Appends a value to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(T* value) const {
|
||||
return add().set(value);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// Returns an iterator to the first element of the array.
|
||||
@@ -126,7 +137,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
// Creates an array and appends it to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/createnestedarray/
|
||||
FORCE_INLINE JsonArray createNestedArray() const {
|
||||
return add().to<JsonArray>();
|
||||
return add<JsonArray>();
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
|
||||
inline JsonObject JsonArray::createNestedObject() const {
|
||||
return add().to<JsonObject>();
|
||||
return add<JsonObject>();
|
||||
}
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
@@ -19,12 +19,12 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TDerived>
|
||||
inline JsonArray VariantRefBase<TDerived>::createNestedArray() const {
|
||||
return add().template to<JsonArray>();
|
||||
return add<JsonArray>();
|
||||
}
|
||||
|
||||
template <typename TDerived>
|
||||
inline JsonObject VariantRefBase<TDerived>::createNestedObject() const {
|
||||
return add().template to<JsonObject>();
|
||||
return add<JsonObject>();
|
||||
}
|
||||
|
||||
template <typename TDerived>
|
||||
|
||||
@@ -34,7 +34,7 @@ inline typename detail::enable_if<
|
||||
copyArray(const T* src, size_t len, const TDestination& dst) {
|
||||
bool ok = true;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
ok &= copyArray(src[i], dst.add());
|
||||
ok &= copyArray(src[i], dst.template add<JsonVariant>());
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Creates an array and appends it to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedarray/
|
||||
JsonArray createNestedArray() {
|
||||
return add().to<JsonArray>();
|
||||
return add<JsonArray>();
|
||||
}
|
||||
|
||||
// Creates an array and adds it to the root object.
|
||||
@@ -181,7 +181,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Creates an object and appends it to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedobject/
|
||||
JsonObject createNestedObject() {
|
||||
return add().to<JsonObject>();
|
||||
return add<JsonObject>();
|
||||
}
|
||||
|
||||
// Creates an object and adds it to the root object.
|
||||
@@ -264,10 +264,21 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
return JsonVariantConst(data_.getElement(index, &resources_), &resources_);
|
||||
}
|
||||
|
||||
// Appends a new (empty) element to the root array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
template <typename T>
|
||||
typename detail::enable_if<!detail::is_same<T, JsonVariant>::value, T>::type
|
||||
add() {
|
||||
return add<JsonVariant>().to<T>();
|
||||
}
|
||||
|
||||
// Appends a new (null) element to the root array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
FORCE_INLINE JsonVariant add() {
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_same<T, JsonVariant>::value, T>::type
|
||||
add() {
|
||||
return JsonVariant(data_.addElement(&resources_), &resources_);
|
||||
}
|
||||
|
||||
@@ -275,14 +286,14 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
template <typename TValue>
|
||||
FORCE_INLINE bool add(const TValue& value) {
|
||||
return add().set(value);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// Appends a value to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE bool add(TChar* value) {
|
||||
return add().set(value);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// Removes an element of the root array.
|
||||
|
||||
@@ -87,7 +87,9 @@ ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TDerived>
|
||||
inline JsonVariant VariantRefBase<TDerived>::add() const {
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, JsonVariant>::value, T>::type
|
||||
VariantRefBase<TDerived>::add() const {
|
||||
return JsonVariant(
|
||||
detail::VariantData::addElement(getOrCreateData(), getResourceManager()),
|
||||
getResourceManager());
|
||||
|
||||
@@ -136,23 +136,32 @@ class VariantRefBase : public VariantTag {
|
||||
return VariantData::nesting(getData(), getResourceManager());
|
||||
}
|
||||
|
||||
// Appends a new (empty) element to the array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/add/
|
||||
template <typename T>
|
||||
typename enable_if<!is_same<T, JsonVariant>::value, T>::type add() const {
|
||||
return add<JsonVariant>().template to<T>();
|
||||
}
|
||||
|
||||
// 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;
|
||||
template <typename T>
|
||||
typename enable_if<is_same<T, JsonVariant>::value, T>::type 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);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// 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);
|
||||
return add<JsonVariant>().set(value);
|
||||
}
|
||||
|
||||
// Removes an element of the array.
|
||||
@@ -261,7 +270,6 @@ class VariantRefBase : public VariantTag {
|
||||
return VariantAttorney::getOrCreateData(derived());
|
||||
}
|
||||
|
||||
private:
|
||||
FORCE_INLINE ArduinoJson::JsonVariant getVariant() const;
|
||||
|
||||
FORCE_INLINE ArduinoJson::JsonVariantConst getVariantConst() const {
|
||||
|
||||
Reference in New Issue
Block a user