forked from bblanchon/ArduinoJson
@@ -114,6 +114,15 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
detail::ArrayData::removeElement(data_, index, resources_);
|
||||
}
|
||||
|
||||
// Removes the element at the specified index.
|
||||
// https://arduinojson.org/v7/api/jsonarray/remove/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value>::type remove(
|
||||
TVariant variant) const {
|
||||
if (variant.template is<size_t>())
|
||||
remove(variant.template as<size_t>());
|
||||
}
|
||||
|
||||
// Removes all the elements of the array.
|
||||
// https://arduinojson.org/v7/api/jsonarray/clear/
|
||||
void clear() const {
|
||||
@@ -122,8 +131,23 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
|
||||
// Gets or sets the element at the specified index.
|
||||
// https://arduinojson.org/v7/api/jsonarray/subscript/
|
||||
detail::ElementProxy<JsonArray> operator[](size_t index) const {
|
||||
return {*this, index};
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_integral<T>::value,
|
||||
detail::ElementProxy<JsonArray>>::type
|
||||
operator[](T index) const {
|
||||
return {*this, size_t(index)};
|
||||
}
|
||||
|
||||
// Gets or sets the element at the specified index.
|
||||
// https://arduinojson.org/v7/api/jsonarray/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
detail::ElementProxy<JsonArray>>::type
|
||||
operator[](const TVariant& variant) const {
|
||||
if (variant.template is<size_t>())
|
||||
return operator[](variant.template as<size_t>());
|
||||
else
|
||||
return {*this, size_t(-1)};
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
|
||||
@@ -45,9 +45,25 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
|
||||
|
||||
// Returns the element at the specified index.
|
||||
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
|
||||
JsonVariantConst operator[](size_t index) const {
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_integral<T>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](T index) const {
|
||||
return JsonVariantConst(
|
||||
detail::ArrayData::getElement(data_, index, resources_), resources_);
|
||||
detail::ArrayData::getElement(data_, size_t(index), resources_),
|
||||
resources_);
|
||||
}
|
||||
|
||||
// Returns the element at the specified index.
|
||||
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TVariant& variant) const {
|
||||
if (variant.template is<size_t>())
|
||||
return operator[](variant.template as<size_t>());
|
||||
else
|
||||
return JsonVariantConst();
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
|
||||
@@ -163,10 +163,19 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Returns true if the root object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsondocument/containskey/
|
||||
template <typename TString>
|
||||
bool containsKey(const TString& key) const {
|
||||
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return data_.getMember(detail::adaptString(key), &resources_) != 0;
|
||||
}
|
||||
|
||||
// Returns true if the root object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsondocument/containskey/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value, bool>::type
|
||||
containsKey(const TVariant& key) const {
|
||||
return containsKey(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// Gets or sets a root object's member.
|
||||
// https://arduinojson.org/v7/api/jsondocument/subscript/
|
||||
template <typename TString>
|
||||
@@ -207,8 +216,11 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
|
||||
// Gets or sets a root array's element.
|
||||
// https://arduinojson.org/v7/api/jsondocument/subscript/
|
||||
detail::ElementProxy<JsonDocument&> operator[](size_t index) {
|
||||
return {*this, index};
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_integral<T>::value,
|
||||
detail::ElementProxy<JsonDocument&>>::type
|
||||
operator[](T index) {
|
||||
return {*this, size_t(index)};
|
||||
}
|
||||
|
||||
// Gets a root array's member.
|
||||
@@ -217,6 +229,19 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
return JsonVariantConst(data_.getElement(index, &resources_), &resources_);
|
||||
}
|
||||
|
||||
// Gets or sets a root object's member.
|
||||
// https://arduinojson.org/v7/api/jsondocument/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return operator[](key.template as<const char*>());
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
return {};
|
||||
}
|
||||
|
||||
// Appends a new (empty) element to the root array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v7/api/jsondocument/add/
|
||||
@@ -251,8 +276,11 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
|
||||
// Removes an element of the root array.
|
||||
// https://arduinojson.org/v7/api/jsondocument/remove/
|
||||
void remove(size_t index) {
|
||||
detail::VariantData::removeElement(getData(), index, getResourceManager());
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_integral<T>::value>::type remove(
|
||||
T index) {
|
||||
detail::VariantData::removeElement(getData(), size_t(index),
|
||||
getResourceManager());
|
||||
}
|
||||
|
||||
// Removes a member of the root object.
|
||||
@@ -267,13 +295,23 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Removes a member of the root object.
|
||||
// https://arduinojson.org/v7/api/jsondocument/remove/
|
||||
template <typename TString>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TString>::value>::type remove(
|
||||
const TString& key) {
|
||||
detail::VariantData::removeMember(getData(), detail::adaptString(key),
|
||||
getResourceManager());
|
||||
}
|
||||
|
||||
// Removes a member of the root object or an element of the root array.
|
||||
// https://arduinojson.org/v7/api/jsondocument/remove/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value>::type remove(
|
||||
const TVariant& key) {
|
||||
if (key.template is<const char*>())
|
||||
remove(key.template as<const char*>());
|
||||
if (key.template is<size_t>())
|
||||
remove(key.template as<size_t>());
|
||||
}
|
||||
|
||||
operator JsonVariant() {
|
||||
return getVariant();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// Gets or sets the member with specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/subscript/
|
||||
template <typename TString>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TString>::value,
|
||||
detail::MemberProxy<JsonObject, TString>>::type
|
||||
operator[](const TString& key) const {
|
||||
@@ -112,13 +111,24 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// Gets or sets the member with specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/subscript/
|
||||
template <typename TChar>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TChar*>::value,
|
||||
detail::MemberProxy<JsonObject, TChar*>>::type
|
||||
operator[](TChar* key) const {
|
||||
return {*this, key};
|
||||
}
|
||||
|
||||
// Gets or sets the member with specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
detail::MemberProxy<JsonObject, const char*>>::type
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return {*this, key.template as<const char*>()};
|
||||
else
|
||||
return {*this, nullptr};
|
||||
}
|
||||
|
||||
// Removes the member at the specified iterator.
|
||||
// https://arduinojson.org/v7/api/jsonobject/remove/
|
||||
FORCE_INLINE void remove(iterator it) const {
|
||||
@@ -128,11 +138,21 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// Removes the member with the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/remove/
|
||||
template <typename TString>
|
||||
FORCE_INLINE void remove(const TString& key) const {
|
||||
typename detail::enable_if<detail::IsString<TString>::value>::type remove(
|
||||
const TString& key) const {
|
||||
detail::ObjectData::removeMember(data_, detail::adaptString(key),
|
||||
resources_);
|
||||
}
|
||||
|
||||
// Removes the member with the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/remove/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value>::type remove(
|
||||
const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
remove(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// Removes the member with the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/remove/
|
||||
template <typename TChar>
|
||||
@@ -144,7 +164,6 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/containskey/
|
||||
template <typename TString>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return detail::ObjectData::getMember(data_, detail::adaptString(key),
|
||||
@@ -154,13 +173,20 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/containskey/
|
||||
template <typename TChar>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TChar*>::value, bool>::type
|
||||
containsKey(TChar* key) const {
|
||||
return detail::ObjectData::getMember(data_, detail::adaptString(key),
|
||||
resources_) != 0;
|
||||
}
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobject/containskey/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value, bool>::type
|
||||
containsKey(const TVariant& key) const {
|
||||
return containsKey(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// DEPRECATED: use obj[key].to<JsonArray>() instead
|
||||
template <typename TChar>
|
||||
ARDUINOJSON_DEPRECATED("use obj[key].to<JsonArray>() instead")
|
||||
|
||||
@@ -71,7 +71,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobjectconst/containskey/
|
||||
template <typename TString>
|
||||
bool containsKey(const TString& key) const {
|
||||
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return detail::ObjectData::getMember(data_, detail::adaptString(key),
|
||||
resources_) != 0;
|
||||
}
|
||||
@@ -84,6 +85,14 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
resources_) != 0;
|
||||
}
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobjectconst/containskey/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value, bool>::type
|
||||
containsKey(const TVariant& key) const {
|
||||
return containsKey(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// Gets the member with specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobjectconst/subscript/
|
||||
template <typename TString>
|
||||
@@ -106,6 +115,18 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
resources_);
|
||||
}
|
||||
|
||||
// Gets the member with specified key.
|
||||
// https://arduinojson.org/v7/api/jsonobjectconst/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return operator[](key.template as<const char*>());
|
||||
else
|
||||
return JsonVariantConst();
|
||||
}
|
||||
|
||||
// DEPRECATED: always returns zero
|
||||
ARDUINOJSON_DEPRECATED("always returns zero")
|
||||
size_t memoryUsage() const {
|
||||
|
||||
@@ -14,7 +14,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename T>
|
||||
struct is_enum {
|
||||
static const bool value = is_convertible<T, int>::value &&
|
||||
static const bool value = is_convertible<T, long long>::value &&
|
||||
!is_class<T>::value && !is_integral<T>::value &&
|
||||
!is_floating_point<T>::value;
|
||||
};
|
||||
|
||||
@@ -86,9 +86,13 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
|
||||
// Gets array's element at specified index.
|
||||
// https://arduinojson.org/v7/api/jsonvariantconst/subscript/
|
||||
JsonVariantConst operator[](size_t index) const {
|
||||
template <typename T>
|
||||
typename detail::enable_if<detail::is_integral<T>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](T index) const {
|
||||
return JsonVariantConst(
|
||||
detail::VariantData::getElement(data_, index, resources_), resources_);
|
||||
detail::VariantData::getElement(data_, size_t(index), resources_),
|
||||
resources_);
|
||||
}
|
||||
|
||||
// Gets object's member with specified key.
|
||||
@@ -113,10 +117,22 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
resources_);
|
||||
}
|
||||
|
||||
// Gets object's member with specified key or the array's element at the
|
||||
// specified index.
|
||||
// https://arduinojson.org/v7/api/jsonvariantconst/subscript/
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
else
|
||||
return operator[](key.template as<const char*>());
|
||||
}
|
||||
|
||||
// Returns true if tge object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonvariantconst/containskey/
|
||||
template <typename TString>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return detail::VariantData::getMember(getData(), detail::adaptString(key),
|
||||
@@ -126,13 +142,18 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
// Returns true if tge object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonvariantconst/containskey/
|
||||
template <typename TChar>
|
||||
|
||||
typename detail::enable_if<detail::IsString<TChar*>::value, bool>::type
|
||||
containsKey(TChar* key) const {
|
||||
return detail::VariantData::getMember(getData(), detail::adaptString(key),
|
||||
resources_) != 0;
|
||||
}
|
||||
|
||||
template <typename TVariant>
|
||||
typename detail::enable_if<detail::IsVariant<TVariant>::value, bool>::type
|
||||
containsKey(const TVariant& key) const {
|
||||
return containsKey(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// DEPRECATED: always returns zero
|
||||
ARDUINOJSON_DEPRECATED("always returns zero")
|
||||
size_t memoryUsage() const {
|
||||
|
||||
@@ -169,6 +169,17 @@ class VariantRefBase : public VariantTag {
|
||||
getResourceManager());
|
||||
}
|
||||
|
||||
// Removes a member of the object or an element of the array.
|
||||
// https://arduinojson.org/v7/api/jsonvariant/remove/
|
||||
template <typename TVariant>
|
||||
typename enable_if<IsVariant<TVariant>::value>::type remove(
|
||||
const TVariant& key) const {
|
||||
if (key.template is<size_t>())
|
||||
remove(key.template as<size_t>());
|
||||
else
|
||||
remove(key.template as<const char*>());
|
||||
}
|
||||
|
||||
// Gets or sets an array element.
|
||||
// https://arduinojson.org/v7/api/jsonvariant/subscript/
|
||||
ElementProxy<TDerived> operator[](size_t index) const;
|
||||
@@ -185,6 +196,12 @@ class VariantRefBase : public VariantTag {
|
||||
typename enable_if<IsString<TChar*>::value, bool>::type containsKey(
|
||||
TChar* key) const;
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v7/api/jsonvariant/containskey/
|
||||
template <typename TVariant>
|
||||
typename enable_if<IsVariant<TVariant>::value, bool>::type containsKey(
|
||||
const TVariant& key) const;
|
||||
|
||||
// Gets or sets an object member.
|
||||
// https://arduinojson.org/v7/api/jsonvariant/subscript/
|
||||
template <typename TString>
|
||||
@@ -199,6 +216,17 @@ class VariantRefBase : public VariantTag {
|
||||
MemberProxy<TDerived, TChar*>>::type
|
||||
operator[](TChar* key) const;
|
||||
|
||||
// Gets an object member or an array element.
|
||||
// https://arduinojson.org/v7/api/jsonvariant/subscript/
|
||||
template <typename TVariant>
|
||||
typename enable_if<IsVariant<TVariant>::value, JsonVariantConst>::type
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
else
|
||||
return operator[](key.template as<const char*>());
|
||||
}
|
||||
|
||||
// DEPRECATED: use add<JsonVariant>() instead
|
||||
ARDUINOJSON_DEPRECATED("use add<JsonVariant>() instead")
|
||||
JsonVariant add() const;
|
||||
|
||||
@@ -90,6 +90,13 @@ VariantRefBase<TDerived>::containsKey(TChar* key) const {
|
||||
getResourceManager()) != 0;
|
||||
}
|
||||
|
||||
template <typename TDerived>
|
||||
template <typename TVariant>
|
||||
inline typename enable_if<IsVariant<TVariant>::value, bool>::type
|
||||
VariantRefBase<TDerived>::containsKey(const TVariant& key) const {
|
||||
return containsKey(key.template as<const char*>());
|
||||
}
|
||||
|
||||
template <typename TDerived>
|
||||
inline JsonVariant VariantRefBase<TDerived>::getVariant() const {
|
||||
return JsonVariant(getData(), getResourceManager());
|
||||
|
||||
Reference in New Issue
Block a user