Prechádzať zdrojové kódy

Add `VariantImpl::isUnbound()`

Benoit Blanchon 6 mesiacov pred
rodič
commit
7b7ee6cdeb

+ 1 - 1
src/ArduinoJson/Deserialization/deserialize.hpp

@@ -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();

+ 1 - 1
src/ArduinoJson/Variant/ConverterImpl.hpp

@@ -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());

+ 2 - 4
src/ArduinoJson/Variant/JsonVariant.hpp

@@ -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();
   }
 };
 

+ 1 - 1
src/ArduinoJson/Variant/JsonVariantConst.hpp

@@ -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.

+ 4 - 0
src/ArduinoJson/Variant/VariantImpl.hpp

@@ -319,6 +319,10 @@ class VariantImpl {
     }
   }
 
+  bool isUnbound() const {
+    return !data_;
+  }
+
   bool isNull() const {
     return type() == VariantType::Null;
   }

+ 1 - 1
src/ArduinoJson/Variant/VariantRefBase.hpp

@@ -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.

+ 2 - 2
src/ArduinoJson/Variant/VariantRefBaseImpl.hpp

@@ -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();