// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once #include #include namespace ARDUINOJSON_NAMESPACE { class ArrayRef; class ArrayConstRef; class ObjectRef; class ObjectConstRef; class VariantRef; class VariantConstRef; // A metafunction that returns the type of the value returned by // VariantRef::as() template struct VariantAs { typedef T type; }; template <> struct VariantAs { typedef const char* type; }; // A metafunction that returns the type of the value returned by // VariantRef::as() template struct VariantConstAs { typedef typename VariantAs::type type; }; template <> struct VariantConstAs { typedef VariantConstRef type; }; template <> struct VariantConstAs { typedef ObjectConstRef type; }; template <> struct VariantConstAs { typedef ArrayConstRef type; }; // --- template inline typename enable_if::value && !is_same::value, T>::type variantAs(const VariantData* data) { ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T); return data != 0 ? data->asIntegral() : T(0); } template inline typename enable_if::value, T>::type variantAs( const VariantData* data) { return data != 0 ? static_cast(data->asIntegral()) : T(); } template inline typename enable_if::value, T>::type variantAs( const VariantData* data) { return data != 0 ? data->asBoolean() : false; } template inline typename enable_if::value, T>::type variantAs( const VariantData* data) { return data != 0 ? data->asFloat() : T(0); } template inline typename enable_if::value || is_same::value, const char*>::type variantAs(const VariantData* data) { return data != 0 ? data->asString() : 0; } template T variantAs(VariantData* data, MemoryPool*) { // By default use the read-only conversion. // There are specializations for // - ArrayRef return variantAs(data); } template inline typename enable_if::value, T>::type variantAs( const VariantData* data); template inline typename enable_if::value, T>::type variantAs( const VariantData* data); template inline typename enable_if::value, T>::type variantAs(const VariantData* data); template inline typename enable_if::value, T>::type variantAs( const VariantData* data); } // namespace ARDUINOJSON_NAMESPACE