mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-09-25 14:30:56 +02:00
Extract asObject()
Before: 9874, 8796, 9694, 12634, 9970 After: 9874, 8736, 9694, 12634, 9970 Target: 9800, 8458, 9634, 12290, 9702
This commit is contained in:
@@ -165,7 +165,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
ARDUINOJSON_DEPRECATED("use doc[\"key\"].is<T>() instead")
|
ARDUINOJSON_DEPRECATED("use doc[\"key\"].is<T>() instead")
|
||||||
bool containsKey(TChar* key) const {
|
bool containsKey(TChar* key) const {
|
||||||
return getVariantImpl().getMember(detail::adaptString(key)) != 0;
|
return getObjectImpl().getMember(detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED: use obj[key].is<T>() instead
|
// DEPRECATED: use obj[key].is<T>() instead
|
||||||
@@ -174,7 +174,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
||||||
ARDUINOJSON_DEPRECATED("use doc[key].is<T>() instead")
|
ARDUINOJSON_DEPRECATED("use doc[key].is<T>() instead")
|
||||||
bool containsKey(const TString& key) const {
|
bool containsKey(const TString& key) const {
|
||||||
return getVariantImpl().getMember(detail::adaptString(key)) != 0;
|
return getObjectImpl().getMember(detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED: use obj[key].is<T>() instead
|
// DEPRECATED: use obj[key].is<T>() instead
|
||||||
@@ -211,8 +211,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
template <typename TString,
|
template <typename TString,
|
||||||
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
||||||
JsonVariantConst operator[](const TString& key) const {
|
JsonVariantConst operator[](const TString& key) const {
|
||||||
return JsonVariantConst(
|
return JsonVariantConst(getObjectImpl().getMember(detail::adaptString(key)),
|
||||||
getVariantImpl().getMember(detail::adaptString(key)), &resources_);
|
&resources_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a root object's member.
|
// Gets a root object's member.
|
||||||
@@ -222,8 +222,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
!detail::is_const<TChar>::value,
|
!detail::is_const<TChar>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
JsonVariantConst operator[](TChar* key) const {
|
JsonVariantConst operator[](TChar* key) const {
|
||||||
return JsonVariantConst(
|
return JsonVariantConst(getObjectImpl().getMember(detail::adaptString(key)),
|
||||||
getVariantImpl().getMember(detail::adaptString(key)), &resources_);
|
&resources_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets or sets a root array's element.
|
// Gets or sets a root array's element.
|
||||||
@@ -300,7 +300,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
!detail::is_const<TChar>::value,
|
!detail::is_const<TChar>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
void remove(TChar* key) {
|
void remove(TChar* key) {
|
||||||
getVariantImpl().removeMember(detail::adaptString(key));
|
getObjectImpl().removeMember(detail::adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes a member of the root object.
|
// Removes a member of the root object.
|
||||||
@@ -308,7 +308,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
template <typename TString,
|
template <typename TString,
|
||||||
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
||||||
void remove(const TString& key) {
|
void remove(const TString& key) {
|
||||||
getVariantImpl().removeMember(detail::adaptString(key));
|
getObjectImpl().removeMember(detail::adaptString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes a member of the root object or an element of the root array.
|
// Removes a member of the root object or an element of the root array.
|
||||||
@@ -416,6 +416,10 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
return &data_;
|
return &data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detail::ObjectImpl getObjectImpl() const {
|
||||||
|
return detail::VariantImpl::asObject(&data_, &resources_);
|
||||||
|
}
|
||||||
|
|
||||||
mutable detail::ResourceManager resources_;
|
mutable detail::ResourceManager resources_;
|
||||||
mutable detail::VariantData data_;
|
mutable detail::VariantData data_;
|
||||||
};
|
};
|
||||||
|
@@ -295,8 +295,14 @@ class VariantImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectImpl asObject() {
|
ObjectImpl asObject() {
|
||||||
return ObjectImpl(isObject() ? &data_->content.asCollection : nullptr,
|
return asObject(data_, resources_);
|
||||||
resources_);
|
}
|
||||||
|
|
||||||
|
static ObjectImpl asObject(VariantData* data, ResourceManager* resources) {
|
||||||
|
return ObjectImpl(data && data->type == VariantType::Object
|
||||||
|
? &data->content.asCollection
|
||||||
|
: nullptr,
|
||||||
|
resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonString asRawString() const {
|
JsonString asRawString() const {
|
||||||
|
Reference in New Issue
Block a user