mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 18:57:32 +02:00
Add VariantImpl::isUnbound()
This commit is contained in:
@ -45,7 +45,7 @@ template <template <typename> class TDeserializer, typename TDestination,
|
|||||||
DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
||||||
TOptions options) {
|
TOptions options) {
|
||||||
auto impl = VariantAttorney::getOrCreateImpl(dst);
|
auto impl = VariantAttorney::getOrCreateImpl(dst);
|
||||||
if (impl.getData() == nullptr)
|
if (impl.isUnbound())
|
||||||
return DeserializationError::NoMemory;
|
return DeserializationError::NoMemory;
|
||||||
auto resources = impl.getResourceManager();
|
auto resources = impl.getResourceManager();
|
||||||
dst.clear();
|
dst.clear();
|
||||||
|
@ -232,7 +232,7 @@ class StringBuilderPrint : public Print {
|
|||||||
|
|
||||||
inline void convertToJson(const ::Printable& src, JsonVariant dst) {
|
inline void convertToJson(const ::Printable& src, JsonVariant dst) {
|
||||||
auto impl = detail::VariantAttorney::getImpl(dst);
|
auto impl = detail::VariantAttorney::getImpl(dst);
|
||||||
if (!impl.getData())
|
if (impl.isUnbound())
|
||||||
return;
|
return;
|
||||||
impl.clear();
|
impl.clear();
|
||||||
detail::StringBuilderPrint print(impl.getResourceManager());
|
detail::StringBuilderPrint print(impl.getResourceManager());
|
||||||
|
@ -52,8 +52,7 @@ struct Converter<JsonVariant> : private detail::VariantAttorney {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool checkJson(JsonVariant src) {
|
static bool checkJson(JsonVariant src) {
|
||||||
auto data = getImpl(src).getData();
|
return !getImpl(src).isUnbound();
|
||||||
return !!data;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,8 +67,7 @@ struct Converter<JsonVariantConst> : private detail::VariantAttorney {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool checkJson(JsonVariantConst src) {
|
static bool checkJson(JsonVariantConst src) {
|
||||||
auto data = getImpl(src).getData();
|
return !getImpl(src).isUnbound();
|
||||||
return !!data;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class JsonVariantConst : public detail::VariantTag,
|
|||||||
|
|
||||||
// Returns true if the reference is unbound.
|
// Returns true if the reference is unbound.
|
||||||
bool isUnbound() const {
|
bool isUnbound() const {
|
||||||
return impl_.getData() == nullptr;
|
return impl_.isUnbound();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the depth (nesting level) of the value.
|
// Returns the depth (nesting level) of the value.
|
||||||
|
@ -319,6 +319,10 @@ class VariantImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isUnbound() const {
|
||||||
|
return !data_;
|
||||||
|
}
|
||||||
|
|
||||||
bool isNull() const {
|
bool isNull() const {
|
||||||
return type() == VariantType::Null;
|
return type() == VariantType::Null;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class VariantRefBase : public VariantTag {
|
|||||||
|
|
||||||
// Returns true if the reference is unbound.
|
// Returns true if the reference is unbound.
|
||||||
bool isUnbound() const {
|
bool isUnbound() const {
|
||||||
return !getImpl().getData();
|
return getImpl().isUnbound();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Casts the value to the specified type.
|
// Casts the value to the specified type.
|
||||||
|
@ -145,7 +145,7 @@ template <typename TDerived>
|
|||||||
template <typename T, enable_if_t<is_same<T, JsonArray>::value, int>>
|
template <typename T, enable_if_t<is_same<T, JsonArray>::value, int>>
|
||||||
inline JsonArray VariantRefBase<TDerived>::to() const {
|
inline JsonArray VariantRefBase<TDerived>::to() const {
|
||||||
auto impl = getOrCreateImpl();
|
auto impl = getOrCreateImpl();
|
||||||
if (!impl.getData())
|
if (impl.isUnbound())
|
||||||
return JsonArray();
|
return JsonArray();
|
||||||
impl.clear();
|
impl.clear();
|
||||||
impl.getData()->toArray();
|
impl.getData()->toArray();
|
||||||
@ -156,7 +156,7 @@ template <typename TDerived>
|
|||||||
template <typename T, enable_if_t<is_same<T, JsonObject>::value, int>>
|
template <typename T, enable_if_t<is_same<T, JsonObject>::value, int>>
|
||||||
JsonObject VariantRefBase<TDerived>::to() const {
|
JsonObject VariantRefBase<TDerived>::to() const {
|
||||||
auto impl = getOrCreateImpl();
|
auto impl = getOrCreateImpl();
|
||||||
if (!impl.getData())
|
if (impl.isUnbound())
|
||||||
return JsonObject();
|
return JsonObject();
|
||||||
impl.clear();
|
impl.clear();
|
||||||
impl.getData()->toObject();
|
impl.getData()->toObject();
|
||||||
|
Reference in New Issue
Block a user