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