mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 02:37:35 +02:00
JsonObjectConst: replace ObjectData*
member with VariantData*
This commit is contained in:
@ -33,7 +33,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator JsonObjectConst() const {
|
operator JsonObjectConst() const {
|
||||||
return JsonObjectConst(data_, resources_);
|
return JsonObjectConst(collectionToVariant(data_), resources_);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator JsonVariantConst() const {
|
operator JsonVariantConst() const {
|
||||||
|
@ -22,7 +22,7 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
JsonObjectConst() : data_(0), resources_(0) {}
|
JsonObjectConst() : data_(0), resources_(0) {}
|
||||||
|
|
||||||
// INTERNAL USE ONLY
|
// INTERNAL USE ONLY
|
||||||
JsonObjectConst(const detail::ObjectData* data,
|
JsonObjectConst(const detail::VariantData* data,
|
||||||
const detail::ResourceManager* resources)
|
const detail::ResourceManager* resources)
|
||||||
: data_(data), resources_(resources) {}
|
: data_(data), resources_(resources) {}
|
||||||
|
|
||||||
@ -33,13 +33,13 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
// Returns true if the reference is unbound.
|
// Returns true if the reference is unbound.
|
||||||
// https://arduinojson.org/v7/api/jsonobjectconst/isnull/
|
// https://arduinojson.org/v7/api/jsonobjectconst/isnull/
|
||||||
bool isNull() const {
|
bool isNull() const {
|
||||||
return data_ == 0;
|
return !data_ || !data_->isObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the reference is bound.
|
// Returns true if the reference is bound.
|
||||||
// https://arduinojson.org/v7/api/jsonobjectconst/isnull/
|
// https://arduinojson.org/v7/api/jsonobjectconst/isnull/
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
return data_ != 0;
|
return !isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the depth (nesting level) of the object.
|
// Returns the depth (nesting level) of the object.
|
||||||
@ -57,9 +57,10 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
// Returns an iterator to the first key-value pair of the object.
|
// Returns an iterator to the first key-value pair of the object.
|
||||||
// https://arduinojson.org/v7/api/jsonobjectconst/begin/
|
// https://arduinojson.org/v7/api/jsonobjectconst/begin/
|
||||||
iterator begin() const {
|
iterator begin() const {
|
||||||
if (!data_)
|
auto obj = detail::VariantData::asObject(data_);
|
||||||
|
if (!obj)
|
||||||
return iterator();
|
return iterator();
|
||||||
return iterator(data_->createIterator(resources_), resources_);
|
return iterator(obj->createIterator(resources_), resources_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns an iterator following the last key-value pair of the object.
|
// Returns an iterator following the last key-value pair of the object.
|
||||||
@ -74,8 +75,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
detail::enable_if_t<detail::IsString<TString>::value, int> = 0>
|
||||||
ARDUINOJSON_DEPRECATED("use obj[key].is<T>() instead")
|
ARDUINOJSON_DEPRECATED("use obj[key].is<T>() instead")
|
||||||
bool containsKey(const TString& key) const {
|
bool containsKey(const TString& key) const {
|
||||||
return detail::ObjectData::getMember(data_, detail::adaptString(key),
|
return detail::VariantData::getMember(data_, detail::adaptString(key),
|
||||||
resources_) != 0;
|
resources_) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED: use obj["key"].is<T>() instead
|
// DEPRECATED: use obj["key"].is<T>() instead
|
||||||
@ -83,8 +84,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
ARDUINOJSON_DEPRECATED("use obj[\"key\"].is<T>() instead")
|
ARDUINOJSON_DEPRECATED("use obj[\"key\"].is<T>() instead")
|
||||||
bool containsKey(TChar* key) const {
|
bool containsKey(TChar* key) const {
|
||||||
return detail::ObjectData::getMember(data_, detail::adaptString(key),
|
return detail::VariantData::getMember(data_, detail::adaptString(key),
|
||||||
resources_) != 0;
|
resources_) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED: use obj[key].is<T>() instead
|
// DEPRECATED: use obj[key].is<T>() instead
|
||||||
@ -101,7 +102,7 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
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(detail::ObjectData::getMember(
|
return JsonVariantConst(detail::VariantData::getMember(
|
||||||
data_, detail::adaptString(key), resources_),
|
data_, detail::adaptString(key), resources_),
|
||||||
resources_);
|
resources_);
|
||||||
}
|
}
|
||||||
@ -113,7 +114,7 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
!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(detail::ObjectData::getMember(
|
return JsonVariantConst(detail::VariantData::getMember(
|
||||||
data_, detail::adaptString(key), resources_),
|
data_, detail::adaptString(key), resources_),
|
||||||
resources_);
|
resources_);
|
||||||
}
|
}
|
||||||
@ -137,10 +138,10 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const detail::VariantData* getData() const {
|
const detail::VariantData* getData() const {
|
||||||
return collectionToVariant(data_);
|
return data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const detail::ObjectData* data_;
|
const detail::VariantData* data_;
|
||||||
const detail::ResourceManager* resources_;
|
const detail::ResourceManager* resources_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -369,9 +369,7 @@ struct Converter<JsonObjectConst> : private detail::VariantAttorney {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static JsonObjectConst fromJson(JsonVariantConst src) {
|
static JsonObjectConst fromJson(JsonVariantConst src) {
|
||||||
auto data = getData(src);
|
return JsonObjectConst(getData(src), getResourceManager(src));
|
||||||
auto object = data != 0 ? data->asObject() : nullptr;
|
|
||||||
return JsonObjectConst(object, getResourceManager(src));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkJson(JsonVariantConst src) {
|
static bool checkJson(JsonVariantConst src) {
|
||||||
|
@ -35,7 +35,8 @@ class VisitorAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result_type visit(const ObjectData& value) {
|
result_type visit(const ObjectData& value) {
|
||||||
return visitor_->visit(JsonObjectConst(&value, resources_));
|
return visitor_->visit(
|
||||||
|
JsonObjectConst(collectionToVariant(&value), resources_));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -292,6 +292,10 @@ class VariantData {
|
|||||||
return const_cast<VariantData*>(this)->asObject();
|
return const_cast<VariantData*>(this)->asObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const ObjectData* asObject(const VariantData* var) {
|
||||||
|
return var ? var->asObject() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
JsonString asRawString() const {
|
JsonString asRawString() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case VariantType::RawString:
|
case VariantType::RawString:
|
||||||
|
Reference in New Issue
Block a user