diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index a1a01508..8b7e3594 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -9,7 +9,7 @@ #include "ArduinoJson/deserializeJson.hpp" #include "ArduinoJson/deserializeMsgPack.hpp" -#include "ArduinoJson/Json/Serialization/JsonSerializer.hpp" +#include "ArduinoJson/Json/JsonSerializer.hpp" #include "ArduinoJson/JsonArrayImpl.hpp" #include "ArduinoJson/JsonObjectImpl.hpp" #include "ArduinoJson/JsonVariantImpl.hpp" diff --git a/src/ArduinoJson/TypeTraits/IsVariant.hpp b/src/ArduinoJson/Data/IsVariant.hpp similarity index 57% rename from src/ArduinoJson/TypeTraits/IsVariant.hpp rename to src/ArduinoJson/Data/IsVariant.hpp index f8b299f7..2c543417 100644 --- a/src/ArduinoJson/TypeTraits/IsVariant.hpp +++ b/src/ArduinoJson/Data/IsVariant.hpp @@ -4,7 +4,7 @@ #pragma once -#include "IsBaseOf.hpp" +#include "../Polyfills/type_traits.hpp" namespace ArduinoJson { namespace Internals { @@ -12,6 +12,6 @@ namespace Internals { class JsonVariantTag {}; template -struct IsVariant : IsBaseOf {}; -} -} +struct IsVariant : is_base_of {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Data/ValueSaver.hpp b/src/ArduinoJson/Data/ValueSaver.hpp index 4416ebc9..d3f7e3ae 100644 --- a/src/ArduinoJson/Data/ValueSaver.hpp +++ b/src/ArduinoJson/Data/ValueSaver.hpp @@ -6,8 +6,8 @@ #include "../JsonVariant.hpp" #include "../Memory/JsonBuffer.hpp" +#include "../Polyfills/type_traits.hpp" #include "../Strings/StringTraits.hpp" -#include "../TypeTraits/EnableIf.hpp" namespace ArduinoJson { namespace Internals { @@ -23,7 +23,7 @@ struct ValueSaver { template struct ValueSaver< - Source, typename EnableIf::should_duplicate>::type> { + Source, typename enable_if::should_duplicate>::type> { template static bool save(JsonBuffer* buffer, Destination& dest, Source source) { if (!StringTraits::is_null(source)) { @@ -41,7 +41,7 @@ struct ValueSaver< // const char*, const signed char*, const unsigned char* template struct ValueSaver< - Char*, typename EnableIf::should_duplicate>::type> { + Char*, typename enable_if::should_duplicate>::type> { template static bool save(JsonBuffer*, Destination& dest, Char* source) { dest = reinterpret_cast(source); diff --git a/src/ArduinoJson/DynamicJsonDocument.hpp b/src/ArduinoJson/DynamicJsonDocument.hpp index 884c615d..7f88f76c 100644 --- a/src/ArduinoJson/DynamicJsonDocument.hpp +++ b/src/ArduinoJson/DynamicJsonDocument.hpp @@ -34,8 +34,8 @@ class DynamicJsonDocument { // JsonObject& to() template - typename Internals::EnableIf::value, - JsonObject&>::type + typename Internals::enable_if::value, + JsonObject&>::type to() { clear(); JsonObject* object = new (&_buffer) JsonObject(&_buffer); @@ -46,8 +46,8 @@ class DynamicJsonDocument { // JsonArray& to() template - typename Internals::EnableIf::value, - JsonArray&>::type + typename Internals::enable_if::value, + JsonArray&>::type to() { clear(); JsonArray* array = new (&_buffer) JsonArray(&_buffer); @@ -58,8 +58,8 @@ class DynamicJsonDocument { // JsonVariant& to() template - typename Internals::EnableIf::value, - T&>::type + typename Internals::enable_if::value, + T&>::type to() { clear(); return _root; diff --git a/src/ArduinoJson/Json/Encoding.hpp b/src/ArduinoJson/Json/EscapeSequence.hpp similarity index 90% rename from src/ArduinoJson/Json/Encoding.hpp rename to src/ArduinoJson/Json/EscapeSequence.hpp index a0efa2c7..fd3a760c 100644 --- a/src/ArduinoJson/Json/Encoding.hpp +++ b/src/ArduinoJson/Json/EscapeSequence.hpp @@ -7,7 +7,7 @@ namespace ArduinoJson { namespace Internals { -class Encoding { +class EscapeSequence { public: // Optimized for code size on a 8-bit AVR static char escapeChar(char c) { @@ -33,5 +33,5 @@ class Encoding { return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; } }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Json/Serialization/IndentedPrint.hpp b/src/ArduinoJson/Json/IndentedPrint.hpp similarity index 100% rename from src/ArduinoJson/Json/Serialization/IndentedPrint.hpp rename to src/ArduinoJson/Json/IndentedPrint.hpp diff --git a/src/ArduinoJson/Json/Deserialization/JsonDeserializer.hpp b/src/ArduinoJson/Json/JsonDeserializer.hpp similarity index 95% rename from src/ArduinoJson/Json/Deserialization/JsonDeserializer.hpp rename to src/ArduinoJson/Json/JsonDeserializer.hpp index 3b5d3301..b5457852 100644 --- a/src/ArduinoJson/Json/Deserialization/JsonDeserializer.hpp +++ b/src/ArduinoJson/Json/JsonDeserializer.hpp @@ -4,12 +4,12 @@ #pragma once -#include "../../DeserializationError.hpp" -#include "../../JsonVariant.hpp" -#include "../../Memory/JsonBuffer.hpp" -#include "../../Reading/Reader.hpp" -#include "../../TypeTraits/IsConst.hpp" -#include "../Encoding.hpp" +#include "../DeserializationError.hpp" +#include "../JsonVariant.hpp" +#include "../Memory/JsonBuffer.hpp" +#include "../Polyfills/type_traits.hpp" +#include "../Reading/Reader.hpp" +#include "./EscapeSequence.hpp" namespace ArduinoJson { namespace Internals { @@ -168,7 +168,8 @@ class JsonDeserializer { } DeserializationError parseString(const char **result) { - typename RemoveReference::type::String str = _writer.startString(); + typename remove_reference::type::String str = + _writer.startString(); char c = current(); if (c == '\0') return DeserializationError::IncompleteInput; @@ -188,7 +189,7 @@ class JsonDeserializer { if (c == '\0') return DeserializationError::IncompleteInput; if (c == 'u') return DeserializationError::NotSupported; // replace char - c = Encoding::unescapeChar(c); + c = EscapeSequence::unescapeChar(c); if (c == '\0') return DeserializationError::InvalidInput; move(); } diff --git a/src/ArduinoJson/Json/Serialization/JsonSerializer.hpp b/src/ArduinoJson/Json/JsonSerializer.hpp similarity index 89% rename from src/ArduinoJson/Json/Serialization/JsonSerializer.hpp rename to src/ArduinoJson/Json/JsonSerializer.hpp index cae6ac84..6bcb0ba8 100644 --- a/src/ArduinoJson/Json/Serialization/JsonSerializer.hpp +++ b/src/ArduinoJson/Json/JsonSerializer.hpp @@ -4,15 +4,15 @@ #pragma once -#include "../../Print/DummyPrint.hpp" -#include "../../Print/DynamicStringBuilder.hpp" -#include "../../Print/StaticStringBuilder.hpp" +#include "../Print/DummyPrint.hpp" +#include "../Print/DynamicStringBuilder.hpp" +#include "../Print/StaticStringBuilder.hpp" #include "./IndentedPrint.hpp" #include "./JsonWriter.hpp" #include "./Prettyfier.hpp" #if ARDUINOJSON_ENABLE_STD_STREAM -#include "../../Print/StreamPrintAdapter.hpp" +#include "../Print/StreamPrintAdapter.hpp" #endif namespace ArduinoJson { @@ -96,8 +96,8 @@ class JsonSerializer { } // namespace Internals template -typename Internals::EnableIf::has_append, - size_t>::type +typename Internals::enable_if< + !Internals::StringTraits::has_append, size_t>::type serializeJson(const TSource &source, TDestination &destination) { Internals::JsonWriter writer(destination); Internals::JsonSerializer >::serialize( @@ -126,8 +126,8 @@ size_t serializeJson(const TSource &source, char (&buffer)[N]) { } template -typename Internals::EnableIf::has_append, - size_t>::type +typename Internals::enable_if::has_append, + size_t>::type serializeJson(const TSource &source, TDestination &str) { Internals::DynamicStringBuilder sb(str); return serializeJson(source, sb); @@ -153,16 +153,16 @@ size_t serializeJsonPretty(const TSource &source, char (&buffer)[N]) { } template -typename Internals::EnableIf::has_append, - size_t>::type +typename Internals::enable_if< + !Internals::StringTraits::has_append, size_t>::type serializeJsonPretty(const TSource &source, TDestination &print) { Internals::IndentedPrint indentedPrint(print); return serializeJsonPretty(source, indentedPrint); } template -typename Internals::EnableIf::has_append, - size_t>::type +typename Internals::enable_if::has_append, + size_t>::type serializeJsonPretty(const TSource &source, TDestination &str) { Internals::DynamicStringBuilder sb(str); return serializeJsonPretty(source, sb); diff --git a/src/ArduinoJson/Json/Serialization/JsonWriter.hpp b/src/ArduinoJson/Json/JsonWriter.hpp similarity index 90% rename from src/ArduinoJson/Json/Serialization/JsonWriter.hpp rename to src/ArduinoJson/Json/JsonWriter.hpp index f613f7e5..93d7694c 100644 --- a/src/ArduinoJson/Json/Serialization/JsonWriter.hpp +++ b/src/ArduinoJson/Json/JsonWriter.hpp @@ -5,10 +5,10 @@ #pragma once #include -#include "../../Data/JsonInteger.hpp" -#include "../../Polyfills/attributes.hpp" -#include "../Encoding.hpp" -#include "./FloatParts.hpp" +#include "../Data/JsonInteger.hpp" +#include "../Numbers/FloatParts.hpp" +#include "../Polyfills/attributes.hpp" +#include "./EscapeSequence.hpp" namespace ArduinoJson { namespace Internals { @@ -66,7 +66,7 @@ class JsonWriter { } void writeChar(char c) { - char specialChar = Encoding::escapeChar(c); + char specialChar = EscapeSequence::escapeChar(c); if (specialChar) { writeRaw('\\'); writeRaw(specialChar); @@ -77,14 +77,14 @@ class JsonWriter { template void writeFloat(TFloat value) { - if (isNaN(value)) return writeRaw("NaN"); + if (isnan(value)) return writeRaw("NaN"); if (value < 0.0) { writeRaw('-'); value = -value; } - if (isInfinity(value)) return writeRaw("Infinity"); + if (isinf(value)) return writeRaw("Infinity"); FloatParts parts(value); diff --git a/src/ArduinoJson/Json/Serialization/Prettyfier.hpp b/src/ArduinoJson/Json/Prettyfier.hpp similarity index 100% rename from src/ArduinoJson/Json/Serialization/Prettyfier.hpp rename to src/ArduinoJson/Json/Prettyfier.hpp diff --git a/src/ArduinoJson/JsonArray.hpp b/src/ArduinoJson/JsonArray.hpp index d52430fd..d174c621 100644 --- a/src/ArduinoJson/JsonArray.hpp +++ b/src/ArduinoJson/JsonArray.hpp @@ -9,11 +9,8 @@ #include "Data/ValueSaver.hpp" #include "JsonVariant.hpp" #include "Memory/JsonBufferAllocated.hpp" +#include "Polyfills/type_traits.hpp" #include "Strings/StringTraits.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsArray.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsSame.hpp" // Returns the size (in bytes) of an array with n elements. // Can be very handy to determine the size of a StaticJsonBuffer. @@ -88,7 +85,8 @@ class JsonArray : public Internals::ReferenceType, // bool set(size_t index, TValue value, uint8_t decimals); // TValue = float, double template - typename Internals::EnableIf::value, bool>::type + typename Internals::enable_if::value, + bool>::type set(size_t index, T value, uint8_t decimals) { return set_impl(index, JsonVariant(value, decimals)); } diff --git a/src/ArduinoJson/JsonObject.hpp b/src/ArduinoJson/JsonObject.hpp index def89b95..22c8af8e 100644 --- a/src/ArduinoJson/JsonObject.hpp +++ b/src/ArduinoJson/JsonObject.hpp @@ -9,11 +9,8 @@ #include "Data/ValueSaver.hpp" #include "JsonPair.hpp" #include "Memory/JsonBufferAllocated.hpp" +#include "Polyfills/type_traits.hpp" #include "Strings/StringTraits.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsArray.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsSame.hpp" // Returns the size (in bytes) of an object with n elements. // Can be very handy to determine the size of a StaticJsonBuffer. diff --git a/src/ArduinoJson/JsonObjectSubscript.hpp b/src/ArduinoJson/JsonObjectSubscript.hpp index f323fb32..9d11ac20 100644 --- a/src/ArduinoJson/JsonObjectSubscript.hpp +++ b/src/ArduinoJson/JsonObjectSubscript.hpp @@ -6,7 +6,7 @@ #include "Configuration.hpp" #include "JsonVariantBase.hpp" -#include "TypeTraits/EnableIf.hpp" +#include "Polyfills/type_traits.hpp" #ifdef _MSC_VER #pragma warning(push) @@ -36,7 +36,7 @@ class JsonObjectSubscript // TValue = bool, char, long, int, short, float, double, // std::string, String, JsonArray, JsonObject template - FORCE_INLINE typename EnableIf::value, this_type&>::type + FORCE_INLINE typename enable_if::value, this_type&>::type operator=(const TValue& src) { _object.set(_key, src); return *this; @@ -70,7 +70,7 @@ class JsonObjectSubscript // TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant, // std::string, String, JsonArray, JsonObject template - FORCE_INLINE typename EnableIf::value, bool>::type set( + FORCE_INLINE typename enable_if::value, bool>::type set( const TValue& value) { return _object.set(_key, value); } diff --git a/src/ArduinoJson/JsonVariant.hpp b/src/ArduinoJson/JsonVariant.hpp index 1a79af06..a4ad82ee 100644 --- a/src/ArduinoJson/JsonVariant.hpp +++ b/src/ArduinoJson/JsonVariant.hpp @@ -11,16 +11,8 @@ #include "Data/JsonVariantDefault.hpp" #include "Data/JsonVariantType.hpp" #include "JsonVariantBase.hpp" +#include "Polyfills/type_traits.hpp" #include "RawJson.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsChar.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsIntegral.hpp" -#include "TypeTraits/IsSame.hpp" -#include "TypeTraits/IsSignedIntegral.hpp" -#include "TypeTraits/IsUnsignedIntegral.hpp" -#include "TypeTraits/RemoveConst.hpp" -#include "TypeTraits/RemoveReference.hpp" namespace ArduinoJson { @@ -52,8 +44,9 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonVariant(double value); // JsonVariant(float value); template - JsonVariant(T value, typename Internals::EnableIf< - Internals::IsFloatingPoint::value>::type * = 0) { + JsonVariant(T value, + typename Internals::enable_if< + Internals::is_floating_point::value>::type * = 0) { using namespace Internals; _type = JSON_FLOAT; _content.asFloat = static_cast(value); @@ -68,8 +61,8 @@ class JsonVariant : public Internals::JsonVariantBase { template JsonVariant( T value, - typename Internals::EnableIf::value || - Internals::IsSame::value>::type * = + typename Internals::enable_if::value && + Internals::is_signed::value>::type * = 0) { using namespace Internals; if (value >= 0) { @@ -84,9 +77,11 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonVariant(unsigned int) // JsonVariant(unsigned long) template - JsonVariant(T value, - typename Internals::EnableIf< - Internals::IsUnsignedIntegral::value>::type * = 0) { + JsonVariant( + T value, + typename Internals::enable_if::value && + Internals::is_unsigned::value>::type * = + 0) { using namespace Internals; _type = JSON_POSITIVE_INTEGER; _content.asInteger = static_cast(value); @@ -97,10 +92,8 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonVariant(const signed char*); // JsonVariant(const unsigned char*); template - JsonVariant( - const TChar *value, - typename Internals::EnableIf::value>::type * = - 0) { + JsonVariant(const TChar *value, + typename Internals::enable_if::type * = 0) { _type = Internals::JSON_STRING; _content.asString = reinterpret_cast(value); } @@ -143,13 +136,14 @@ class JsonVariant : public Internals::JsonVariantBase { // unsigned int as() const; // unsigned long as() const; template - const typename Internals::EnableIf::value, T>::type + const typename Internals::enable_if::value, T>::type as() const { return variantAsInteger(); } // bool as() const template - const typename Internals::EnableIf::value, T>::type + const typename Internals::enable_if::value, + T>::type as() const { return variantAsInteger() != 0; } @@ -157,8 +151,8 @@ class JsonVariant : public Internals::JsonVariantBase { // double as() const; // float as() const; template - const typename Internals::EnableIf::value, - T>::type + const typename Internals::enable_if::value, + T>::type as() const { return variantAsFloat(); } @@ -166,9 +160,9 @@ class JsonVariant : public Internals::JsonVariantBase { // const char* as() const; // const char* as() const; template - typename Internals::EnableIf::value || - Internals::IsSame::value, - const char *>::type + typename Internals::enable_if::value || + Internals::is_same::value, + const char *>::type as() const { return variantAsString(); } @@ -176,7 +170,7 @@ class JsonVariant : public Internals::JsonVariantBase { // std::string as() const; // String as() const; template - typename Internals::EnableIf::has_append, T>::type + typename Internals::enable_if::has_append, T>::type as() const { const char *cstr = variantAsString(); if (cstr) return T(cstr); @@ -188,9 +182,9 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonArray& as const; // JsonArray& as const; template - typename Internals::EnableIf< - Internals::IsSame::type, - JsonArray>::value, + typename Internals::enable_if< + Internals::is_same::type, + JsonArray>::value, JsonArray &>::type as() const { return variantAsArray(); @@ -198,9 +192,9 @@ class JsonVariant : public Internals::JsonVariantBase { // // const JsonArray& as const; template - typename Internals::EnableIf< - Internals::IsSame::type, - const JsonArray>::value, + typename Internals::enable_if< + Internals::is_same::type, + const JsonArray>::value, const JsonArray &>::type as() const { return variantAsArray(); @@ -209,9 +203,9 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonObject& as const; // JsonObject& as const; template - typename Internals::EnableIf< - Internals::IsSame::type, - JsonObject>::value, + typename Internals::enable_if< + Internals::is_same::type, + JsonObject>::value, JsonObject &>::type as() const { return variantAsObject(); @@ -220,9 +214,9 @@ class JsonVariant : public Internals::JsonVariantBase { // JsonObject& as const; // JsonObject& as const; template - typename Internals::EnableIf< - Internals::IsSame::type, - const JsonObject>::value, + typename Internals::enable_if< + Internals::is_same::type, + const JsonObject>::value, const JsonObject &>::type as() const { return variantAsObject(); @@ -230,8 +224,8 @@ class JsonVariant : public Internals::JsonVariantBase { // // JsonVariant as const; template - typename Internals::EnableIf::value, - T>::type + typename Internals::enable_if::value, + T>::type as() const { return *this; } @@ -249,22 +243,23 @@ class JsonVariant : public Internals::JsonVariantBase { // bool is() const; // bool is() const; template - typename Internals::EnableIf::value, bool>::type is() - const { + typename Internals::enable_if::value, bool>::type + is() const { return variantIsInteger(); } // // bool is() const; // bool is() const; template - typename Internals::EnableIf::value, bool>::type + typename Internals::enable_if::value, + bool>::type is() const { return variantIsFloat(); } // // bool is() const template - typename Internals::EnableIf::value, bool>::type + typename Internals::enable_if::value, bool>::type is() const { return variantIsBoolean(); } @@ -272,9 +267,9 @@ class JsonVariant : public Internals::JsonVariantBase { // bool is() const; // bool is() const; template - typename Internals::EnableIf::value || - Internals::IsSame::value, - bool>::type + typename Internals::enable_if::value || + Internals::is_same::value, + bool>::type is() const { return variantIsString(); } @@ -283,10 +278,11 @@ class JsonVariant : public Internals::JsonVariantBase { // bool is const; // bool is const; template - typename Internals::EnableIf< - Internals::IsSame::type>::type, - JsonArray>::value, + typename Internals::enable_if< + Internals::is_same< + typename Internals::remove_const< + typename Internals::remove_reference::type>::type, + JsonArray>::value, bool>::type is() const { return variantIsArray(); @@ -296,10 +292,11 @@ class JsonVariant : public Internals::JsonVariantBase { // bool is const; // bool is const; template - typename Internals::EnableIf< - Internals::IsSame::type>::type, - JsonObject>::value, + typename Internals::enable_if< + Internals::is_same< + typename Internals::remove_const< + typename Internals::remove_reference::type>::type, + JsonObject>::value, bool>::type is() const { return variantIsObject(); diff --git a/src/ArduinoJson/JsonVariantComparisons.hpp b/src/ArduinoJson/JsonVariantComparisons.hpp index dbd84d97..39317a67 100644 --- a/src/ArduinoJson/JsonVariantComparisons.hpp +++ b/src/ArduinoJson/JsonVariantComparisons.hpp @@ -4,9 +4,9 @@ #pragma once +#include "Data/IsVariant.hpp" +#include "Polyfills/type_traits.hpp" #include "Strings/StringTraits.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsVariant.hpp" namespace ArduinoJson { namespace Internals { @@ -21,7 +21,7 @@ class JsonVariantComparisons { } template - friend typename EnableIf::value, bool>::type + friend typename enable_if::value, bool>::type operator==(TComparand comparand, const JsonVariantComparisons &variant) { return variant.equals(comparand); } @@ -33,7 +33,7 @@ class JsonVariantComparisons { } template - friend typename EnableIf::value, bool>::type + friend typename enable_if::value, bool>::type operator!=(TComparand comparand, const JsonVariantComparisons &variant) { return !variant.equals(comparand); } @@ -101,16 +101,16 @@ class JsonVariantComparisons { } template - typename EnableIf::has_equals, bool>::type equals( + typename enable_if::has_equals, bool>::type equals( const TString &comparand) const { const char *value = as(); return StringTraits::equals(comparand, value); } template - typename EnableIf::value && - !StringTraits::has_equals, - bool>::type + typename enable_if::value && + !StringTraits::has_equals, + bool>::type equals(const TComparand &comparand) const { return as() == comparand; } diff --git a/src/ArduinoJson/JsonVariantImpl.hpp b/src/ArduinoJson/JsonVariantImpl.hpp index 138827cb..d7ffec08 100644 --- a/src/ArduinoJson/JsonVariantImpl.hpp +++ b/src/ArduinoJson/JsonVariantImpl.hpp @@ -8,10 +8,10 @@ #include "JsonArray.hpp" #include "JsonObject.hpp" #include "JsonVariant.hpp" -#include "Text/isFloat.hpp" -#include "Text/isInteger.hpp" -#include "Text/parseFloat.hpp" -#include "Text/parseInteger.hpp" +#include "Numbers/isFloat.hpp" +#include "Numbers/isInteger.hpp" +#include "Numbers/parseFloat.hpp" +#include "Numbers/parseInteger.hpp" #include // for strcmp diff --git a/src/ArduinoJson/JsonVariantOr.hpp b/src/ArduinoJson/JsonVariantOr.hpp index d8022fcb..912831f7 100644 --- a/src/ArduinoJson/JsonVariantOr.hpp +++ b/src/ArduinoJson/JsonVariantOr.hpp @@ -6,8 +6,7 @@ #include "Data/JsonVariantAs.hpp" #include "Polyfills/attributes.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsIntegral.hpp" +#include "Polyfills/type_traits.hpp" namespace ArduinoJson { namespace Internals { @@ -17,7 +16,7 @@ class JsonVariantOr { public: // Returns the default value if the JsonVariant is undefined of incompatible template - typename EnableIf::value, T>::type operator|( + typename enable_if::value, T>::type operator|( const T &defaultValue) const { if (impl()->template is()) return impl()->template as(); @@ -35,7 +34,7 @@ class JsonVariantOr { // Returns the default value if the JsonVariant is undefined of incompatible // Special case for integers: we also accept double template - typename EnableIf::value, Integer>::type operator|( + typename enable_if::value, Integer>::type operator|( const Integer &defaultValue) const { if (impl()->template is()) return impl()->template as(); diff --git a/src/ArduinoJson/JsonVariantSubscripts.hpp b/src/ArduinoJson/JsonVariantSubscripts.hpp index ec28c686..d75ec052 100644 --- a/src/ArduinoJson/JsonVariantSubscripts.hpp +++ b/src/ArduinoJson/JsonVariantSubscripts.hpp @@ -6,8 +6,8 @@ #include "Data/JsonVariantAs.hpp" #include "Polyfills/attributes.hpp" +#include "Polyfills/type_traits.hpp" #include "Strings/StringTraits.hpp" -#include "TypeTraits/EnableIf.hpp" namespace ArduinoJson { namespace Internals { @@ -43,8 +43,8 @@ class JsonVariantSubscripts { // TKey = const std::string&, const String& template FORCE_INLINE - typename EnableIf::has_equals, - const JsonObjectSubscript >::type + typename enable_if::has_equals, + const JsonObjectSubscript >::type operator[](const TString &key) const { return impl()->template as()[key]; } @@ -52,8 +52,8 @@ class JsonVariantSubscripts { // const JsonObjectSubscript operator[](TKey) const; // TKey = const std::string&, const String& template - FORCE_INLINE typename EnableIf::has_equals, - JsonObjectSubscript >::type + FORCE_INLINE typename enable_if::has_equals, + JsonObjectSubscript >::type operator[](const TString &key) { return impl()->template as()[key]; } @@ -61,8 +61,8 @@ class JsonVariantSubscripts { // JsonObjectSubscript operator[](TKey); // TKey = const char*, const char[N], const FlashStringHelper* template - FORCE_INLINE typename EnableIf::has_equals, - JsonObjectSubscript >::type + FORCE_INLINE typename enable_if::has_equals, + JsonObjectSubscript >::type operator[](const TString *key) { return impl()->template as()[key]; } @@ -71,8 +71,8 @@ class JsonVariantSubscripts { // TKey = const char*, const char[N], const FlashStringHelper* template FORCE_INLINE - typename EnableIf::has_equals, - const JsonObjectSubscript >::type + typename enable_if::has_equals, + const JsonObjectSubscript >::type operator[](const TString *key) const { return impl()->template as()[key]; } diff --git a/src/ArduinoJson/Memory/StaticJsonBuffer.hpp b/src/ArduinoJson/Memory/StaticJsonBuffer.hpp index eb4fc36e..71d6ddbc 100644 --- a/src/ArduinoJson/Memory/StaticJsonBuffer.hpp +++ b/src/ArduinoJson/Memory/StaticJsonBuffer.hpp @@ -4,7 +4,7 @@ #pragma once -#include "../TypeTraits/Max.hpp" +#include "../Polyfills/mpl/max.hpp" #include "JsonBuffer.hpp" namespace ArduinoJson { diff --git a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp index 34dc11de..c043eca3 100644 --- a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp +++ b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp @@ -7,8 +7,8 @@ #include "../DeserializationError.hpp" #include "../JsonVariant.hpp" #include "../Memory/JsonBuffer.hpp" +#include "../Polyfills/type_traits.hpp" #include "../Reading/Reader.hpp" -#include "../TypeTraits/IsConst.hpp" #include "../Writing/Writer.hpp" #include "./endianess.hpp" #include "./ieee754.hpp" @@ -181,7 +181,7 @@ class MsgPackDeserializer { } template - typename EnableIf::type readFloat( + typename enable_if::type readFloat( JsonVariant &variant) { T value; if (!readBytes(value)) return DeserializationError::IncompleteInput; @@ -191,7 +191,7 @@ class MsgPackDeserializer { } template - typename EnableIf::type readDouble( + typename enable_if::type readDouble( JsonVariant &variant) { T value; if (!readBytes(value)) return DeserializationError::IncompleteInput; @@ -201,7 +201,7 @@ class MsgPackDeserializer { } template - typename EnableIf::type readDouble( + typename enable_if::type readDouble( JsonVariant &variant) { uint8_t i[8]; // input is 8 bytes T value; // output is 4 bytes @@ -221,7 +221,8 @@ class MsgPackDeserializer { } DeserializationError readString(JsonVariant &variant, size_t n) { - typename RemoveReference::type::String str = _writer.startString(); + typename remove_reference::type::String str = + _writer.startString(); for (; n; --n) { uint8_t c; if (!readBytes(c)) return DeserializationError::IncompleteInput; diff --git a/src/ArduinoJson/MsgPack/endianess.hpp b/src/ArduinoJson/MsgPack/endianess.hpp index 26f2b906..aa6bb837 100644 --- a/src/ArduinoJson/MsgPack/endianess.hpp +++ b/src/ArduinoJson/MsgPack/endianess.hpp @@ -4,12 +4,11 @@ #pragma once +#include "../Polyfills/type_traits.hpp" + namespace ArduinoJson { namespace Internals { -template -struct integral_constant {}; - template inline void swap(T& a, T& b) { T t(a); diff --git a/src/ArduinoJson/Json/Serialization/FloatParts.hpp b/src/ArduinoJson/Numbers/FloatParts.hpp similarity index 95% rename from src/ArduinoJson/Json/Serialization/FloatParts.hpp rename to src/ArduinoJson/Numbers/FloatParts.hpp index 4f42a9c2..d7c34274 100644 --- a/src/ArduinoJson/Json/Serialization/FloatParts.hpp +++ b/src/ArduinoJson/Numbers/FloatParts.hpp @@ -4,9 +4,9 @@ #pragma once -#include "../../Configuration.hpp" -#include "../../Polyfills/math.hpp" -#include "../../TypeTraits/FloatTraits.hpp" +#include "../Configuration.hpp" +#include "../Polyfills/math.hpp" +#include "./FloatTraits.hpp" namespace ArduinoJson { namespace Internals { diff --git a/src/ArduinoJson/TypeTraits/FloatTraits.hpp b/src/ArduinoJson/Numbers/FloatTraits.hpp similarity index 98% rename from src/ArduinoJson/TypeTraits/FloatTraits.hpp rename to src/ArduinoJson/Numbers/FloatTraits.hpp index 5044807a..a6ebcc12 100644 --- a/src/ArduinoJson/TypeTraits/FloatTraits.hpp +++ b/src/ArduinoJson/Numbers/FloatTraits.hpp @@ -146,5 +146,5 @@ struct FloatTraits { return forge(0x7f800000); } }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Text/isFloat.hpp b/src/ArduinoJson/Numbers/isFloat.hpp similarity index 100% rename from src/ArduinoJson/Text/isFloat.hpp rename to src/ArduinoJson/Numbers/isFloat.hpp diff --git a/src/ArduinoJson/Text/isInteger.hpp b/src/ArduinoJson/Numbers/isInteger.hpp similarity index 100% rename from src/ArduinoJson/Text/isInteger.hpp rename to src/ArduinoJson/Numbers/isInteger.hpp diff --git a/src/ArduinoJson/Text/parseFloat.hpp b/src/ArduinoJson/Numbers/parseFloat.hpp similarity index 97% rename from src/ArduinoJson/Text/parseFloat.hpp rename to src/ArduinoJson/Numbers/parseFloat.hpp index 763ab3d8..e50f9059 100644 --- a/src/ArduinoJson/Text/parseFloat.hpp +++ b/src/ArduinoJson/Numbers/parseFloat.hpp @@ -4,9 +4,9 @@ #pragma once +#include "../Numbers/FloatTraits.hpp" #include "../Polyfills/ctype.hpp" #include "../Polyfills/math.hpp" -#include "../TypeTraits/FloatTraits.hpp" namespace ArduinoJson { namespace Internals { diff --git a/src/ArduinoJson/Text/parseInteger.hpp b/src/ArduinoJson/Numbers/parseInteger.hpp similarity index 100% rename from src/ArduinoJson/Text/parseInteger.hpp rename to src/ArduinoJson/Numbers/parseInteger.hpp diff --git a/src/ArduinoJson/Polyfills/math.hpp b/src/ArduinoJson/Polyfills/math.hpp index 48773edd..32417c0c 100644 --- a/src/ArduinoJson/Polyfills/math.hpp +++ b/src/ArduinoJson/Polyfills/math.hpp @@ -7,13 +7,13 @@ namespace ArduinoJson { namespace Internals { template -bool isNaN(T x) { +bool isnan(T x) { return x != x; } template -bool isInfinity(T x) { +bool isinf(T x) { return x != 0.0 && x * 2 == x; } -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/Max.hpp b/src/ArduinoJson/Polyfills/mpl/max.hpp similarity index 100% rename from src/ArduinoJson/TypeTraits/Max.hpp rename to src/ArduinoJson/Polyfills/mpl/max.hpp diff --git a/src/ArduinoJson/Polyfills/type_traits.hpp b/src/ArduinoJson/Polyfills/type_traits.hpp new file mode 100644 index 00000000..fa5b9e50 --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits.hpp @@ -0,0 +1,18 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "type_traits/enable_if.hpp" +#include "type_traits/integral_constant.hpp" +#include "type_traits/is_array.hpp" +#include "type_traits/is_base_of.hpp" +#include "type_traits/is_const.hpp" +#include "type_traits/is_floating_point.hpp" +#include "type_traits/is_integral.hpp" +#include "type_traits/is_same.hpp" +#include "type_traits/is_signed.hpp" +#include "type_traits/is_unsigned.hpp" +#include "type_traits/remove_const.hpp" +#include "type_traits/remove_reference.hpp" diff --git a/src/ArduinoJson/TypeTraits/EnableIf.hpp b/src/ArduinoJson/Polyfills/type_traits/enable_if.hpp similarity index 74% rename from src/ArduinoJson/TypeTraits/EnableIf.hpp rename to src/ArduinoJson/Polyfills/type_traits/enable_if.hpp index 83fc5e07..70dd92e6 100644 --- a/src/ArduinoJson/TypeTraits/EnableIf.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/enable_if.hpp @@ -9,11 +9,11 @@ namespace Internals { // A meta-function that return the type T if Condition is true. template -struct EnableIf {}; +struct enable_if {}; template -struct EnableIf { +struct enable_if { typedef T type; }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp b/src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp new file mode 100644 index 00000000..7ce931c3 --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +template +struct integral_constant { + static const T value = v; +}; + +typedef integral_constant true_type; +typedef integral_constant false_type; + +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/is_array.hpp b/src/ArduinoJson/Polyfills/type_traits/is_array.hpp new file mode 100644 index 00000000..17075d4a --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/is_array.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +template +struct is_array : false_type {}; + +template +struct is_array : true_type {}; + +template +struct is_array : true_type {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/IsBaseOf.hpp b/src/ArduinoJson/Polyfills/type_traits/is_base_of.hpp similarity index 88% rename from src/ArduinoJson/TypeTraits/IsBaseOf.hpp rename to src/ArduinoJson/Polyfills/type_traits/is_base_of.hpp index bf24e965..be6ddeac 100644 --- a/src/ArduinoJson/TypeTraits/IsBaseOf.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_base_of.hpp @@ -10,7 +10,7 @@ namespace Internals { // A meta-function that returns true if Derived inherits from TBase is an // integral type. template -class IsBaseOf { +class is_base_of { protected: // <- to avoid GCC's "all member functions in class are private" typedef char Yes[1]; typedef char No[2]; @@ -23,5 +23,5 @@ class IsBaseOf { value = sizeof(probe(reinterpret_cast(0))) == sizeof(Yes) }; }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/IsConst.hpp b/src/ArduinoJson/Polyfills/type_traits/is_const.hpp similarity index 61% rename from src/ArduinoJson/TypeTraits/IsConst.hpp rename to src/ArduinoJson/Polyfills/type_traits/is_const.hpp index 512ee5ca..0a2dfda9 100644 --- a/src/ArduinoJson/TypeTraits/IsConst.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_const.hpp @@ -4,18 +4,16 @@ #pragma once +#include "integral_constant.hpp" + namespace ArduinoJson { namespace Internals { // A meta-function that return the type T without the const modifier template -struct IsConst { - static const bool value = false; -}; +struct is_const : false_type {}; template -struct IsConst { - static const bool value = true; -}; -} -} +struct is_const : true_type {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp b/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp new file mode 100644 index 00000000..24e74ab7 --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp @@ -0,0 +1,21 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "integral_constant.hpp" + +namespace ArduinoJson { +namespace Internals { + +template +struct is_floating_point : false_type {}; + +template <> +struct is_floating_point : true_type {}; + +template <> +struct is_floating_point : true_type {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp b/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp new file mode 100644 index 00000000..e97a09cc --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp @@ -0,0 +1,35 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "is_same.hpp" + +namespace ArduinoJson { +namespace Internals { + +// A meta-function that returns true if T is an integral type. +template +struct is_integral { + static const bool value = + is_same::value || is_same::value || + is_same::value || is_same::value || + is_same::value || is_same::value || + is_same::value || is_same::value || +#if ARDUINOJSON_USE_LONG_LONG + is_same::value || + is_same::value || +#endif +#if ARDUINOJSON_USE_INT64 + is_same::value || + is_same::value || +#endif + is_same::value; + // CAUTION: differs from std::is_integral as it doesn't include bool +}; + +template +struct is_integral : is_integral {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/IsSame.hpp b/src/ArduinoJson/Polyfills/type_traits/is_same.hpp similarity index 63% rename from src/ArduinoJson/TypeTraits/IsSame.hpp rename to src/ArduinoJson/Polyfills/type_traits/is_same.hpp index 06567c93..920f5b54 100644 --- a/src/ArduinoJson/TypeTraits/IsSame.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_same.hpp @@ -4,18 +4,16 @@ #pragma once +#include "integral_constant.hpp" + namespace ArduinoJson { namespace Internals { // A meta-function that returns true if types T and U are the same. template -struct IsSame { - static const bool value = false; -}; +struct is_same : false_type {}; template -struct IsSame { - static const bool value = true; -}; -} -} +struct is_same : true_type {}; +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp b/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp new file mode 100644 index 00000000..b145c5ea --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp @@ -0,0 +1,44 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "integral_constant.hpp" +namespace ArduinoJson { +namespace Internals { + +template +struct is_signed : false_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +template <> +struct is_signed : true_type {}; + +#if ARDUINOJSON_USE_LONG_LONG +template <> +struct is_signed : true_type {}; +#endif +#if ARDUINOJSON_USE_INT64 +template <> +struct is_signed : true_type {}; +#endif +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp b/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp new file mode 100644 index 00000000..4de418d0 --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp @@ -0,0 +1,38 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "integral_constant.hpp" +namespace ArduinoJson { +namespace Internals { + +template +struct is_unsigned : false_type {}; + +template <> +struct is_unsigned : true_type {}; + +template <> +struct is_unsigned : true_type {}; + +template <> +struct is_unsigned : true_type {}; + +template <> +struct is_unsigned : true_type {}; + +template <> +struct is_unsigned : true_type {}; + +#if ARDUINOJSON_USE_LONG_LONG +template <> +struct is_unsigned : true_type {}; +#endif +#if ARDUINOJSON_USE_INT64 +template <> +struct is_unsigned : true_type {}; +#endif +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/RemoveConst.hpp b/src/ArduinoJson/Polyfills/type_traits/remove_const.hpp similarity index 73% rename from src/ArduinoJson/TypeTraits/RemoveConst.hpp rename to src/ArduinoJson/Polyfills/type_traits/remove_const.hpp index 39d4cb5a..9cb7421b 100644 --- a/src/ArduinoJson/TypeTraits/RemoveConst.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/remove_const.hpp @@ -9,12 +9,12 @@ namespace Internals { // A meta-function that return the type T without the const modifier template -struct RemoveConst { +struct remove_const { typedef T type; }; template -struct RemoveConst { +struct remove_const { typedef T type; }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/TypeTraits/RemoveReference.hpp b/src/ArduinoJson/Polyfills/type_traits/remove_reference.hpp similarity index 73% rename from src/ArduinoJson/TypeTraits/RemoveReference.hpp rename to src/ArduinoJson/Polyfills/type_traits/remove_reference.hpp index 395a1288..f0103dd2 100644 --- a/src/ArduinoJson/TypeTraits/RemoveReference.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/remove_reference.hpp @@ -9,12 +9,12 @@ namespace Internals { // A meta-function that return the type T without the reference modifier. template -struct RemoveReference { +struct remove_reference { typedef T type; }; template -struct RemoveReference { +struct remove_reference { typedef T type; }; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/StaticJsonDocument.hpp b/src/ArduinoJson/StaticJsonDocument.hpp index b111485c..beab5ce4 100644 --- a/src/ArduinoJson/StaticJsonDocument.hpp +++ b/src/ArduinoJson/StaticJsonDocument.hpp @@ -35,8 +35,8 @@ class StaticJsonDocument { // JsonObject& to() template - typename Internals::EnableIf::value, - JsonObject&>::type + typename Internals::enable_if::value, + JsonObject&>::type to() { clear(); JsonObject* object = new (&_buffer) JsonObject(&_buffer); @@ -47,8 +47,8 @@ class StaticJsonDocument { // JsonArray& to() template - typename Internals::EnableIf::value, - JsonArray&>::type + typename Internals::enable_if::value, + JsonArray&>::type to() { clear(); JsonArray* array = new (&_buffer) JsonArray(&_buffer); @@ -59,8 +59,8 @@ class StaticJsonDocument { // JsonVariant to() template - typename Internals::EnableIf::value, - T&>::type + typename Internals::enable_if::value, + T&>::type to() { clear(); return _root; diff --git a/src/ArduinoJson/Strings/CharPointer.hpp b/src/ArduinoJson/Strings/CharPointer.hpp index 2b804ab3..07a08284 100644 --- a/src/ArduinoJson/Strings/CharPointer.hpp +++ b/src/ArduinoJson/Strings/CharPointer.hpp @@ -30,13 +30,13 @@ struct CharPointerTraits { static const bool has_append = false; static const bool has_equals = true; - static const bool should_duplicate = !IsConst::value; + static const bool should_duplicate = !is_const::value; }; // char*, unsigned char*, signed char* // const char*, const unsigned char*, const signed char* template -struct StringTraits::value>::type> +struct StringTraits::type> : CharPointerTraits {}; -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/src/ArduinoJson/Strings/StringTraits.hpp b/src/ArduinoJson/Strings/StringTraits.hpp index 5201c172..8b62e978 100644 --- a/src/ArduinoJson/Strings/StringTraits.hpp +++ b/src/ArduinoJson/Strings/StringTraits.hpp @@ -6,11 +6,7 @@ #include #include "../Configuration.hpp" -#include "../TypeTraits/EnableIf.hpp" -#include "../TypeTraits/IsBaseOf.hpp" -#include "../TypeTraits/IsChar.hpp" -#include "../TypeTraits/IsConst.hpp" -#include "../TypeTraits/RemoveReference.hpp" +#include "../Polyfills/type_traits.hpp" namespace ArduinoJson { namespace Internals { @@ -26,8 +22,8 @@ struct StringTraits : StringTraits {}; template struct StringTraits : StringTraits {}; -} -} +} // namespace Internals +} // namespace ArduinoJson #include "CharPointer.hpp" #include "FlashString.hpp" diff --git a/src/ArduinoJson/TypeTraits/IsArray.hpp b/src/ArduinoJson/TypeTraits/IsArray.hpp deleted file mode 100644 index 25992311..00000000 --- a/src/ArduinoJson/TypeTraits/IsArray.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that return the type T without the const modifier -template -struct IsArray { - static const bool value = false; -}; -template -struct IsArray { - static const bool value = true; -}; -template -struct IsArray { - static const bool value = true; -}; -} -} diff --git a/src/ArduinoJson/TypeTraits/IsChar.hpp b/src/ArduinoJson/TypeTraits/IsChar.hpp deleted file mode 100644 index d97cec21..00000000 --- a/src/ArduinoJson/TypeTraits/IsChar.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that returns true if T is a charater -template -struct IsChar { - static const bool value = IsSame::value || - IsSame::value || - IsSame::value; -}; - -template -struct IsChar : IsChar {}; -} -} diff --git a/src/ArduinoJson/TypeTraits/IsFloatingPoint.hpp b/src/ArduinoJson/TypeTraits/IsFloatingPoint.hpp deleted file mode 100644 index e41a6824..00000000 --- a/src/ArduinoJson/TypeTraits/IsFloatingPoint.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that returns true if T is a floating point type -template -struct IsFloatingPoint { - static const bool value = IsSame::value || IsSame::value; -}; -} -} diff --git a/src/ArduinoJson/TypeTraits/IsIntegral.hpp b/src/ArduinoJson/TypeTraits/IsIntegral.hpp deleted file mode 100644 index 17ae5f28..00000000 --- a/src/ArduinoJson/TypeTraits/IsIntegral.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "IsSame.hpp" -#include "IsSignedIntegral.hpp" -#include "IsUnsignedIntegral.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that returns true if T is an integral type. -template -struct IsIntegral { - static const bool value = IsSignedIntegral::value || - IsUnsignedIntegral::value || - IsSame::value; - // CAUTION: differs from std::is_integral as it doesn't include bool -}; - -template -struct IsIntegral : IsIntegral {}; -} -} diff --git a/src/ArduinoJson/TypeTraits/IsSignedIntegral.hpp b/src/ArduinoJson/TypeTraits/IsSignedIntegral.hpp deleted file mode 100644 index 7334eb9c..00000000 --- a/src/ArduinoJson/TypeTraits/IsSignedIntegral.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that returns true if T is an integral type. -template -struct IsSignedIntegral { - static const bool value = - IsSame::value || IsSame::value || - IsSame::value || IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - IsSame::value || -#endif -#if ARDUINOJSON_USE_INT64 - IsSame::value || -#endif - false; -}; -} -} diff --git a/src/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp b/src/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp deleted file mode 100644 index 938423f5..00000000 --- a/src/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A meta-function that returns true if T is an integral type. -template -struct IsUnsignedIntegral { - static const bool value = - IsSame::value || IsSame::value || - IsSame::value || IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - IsSame::value || -#endif -#if ARDUINOJSON_USE_INT64 - IsSame::value || -#endif - false; -}; -} -} diff --git a/src/ArduinoJson/Writing/Writer.hpp b/src/ArduinoJson/Writing/Writer.hpp index 7a529279..66c57a53 100644 --- a/src/ArduinoJson/Writing/Writer.hpp +++ b/src/ArduinoJson/Writing/Writer.hpp @@ -21,7 +21,7 @@ struct Writer { template struct Writer::value>::type> { + typename enable_if::value>::type> { typedef StringWriter type; static type create(TJsonBuffer&, TChar* input) { diff --git a/src/ArduinoJson/deserializeJson.hpp b/src/ArduinoJson/deserializeJson.hpp index b0eafc8b..d4e11834 100644 --- a/src/ArduinoJson/deserializeJson.hpp +++ b/src/ArduinoJson/deserializeJson.hpp @@ -4,7 +4,7 @@ #pragma once -#include "Json/Deserialization/JsonDeserializer.hpp" +#include "Json/JsonDeserializer.hpp" #include "Reading/Reader.hpp" #include "Writing/Writer.hpp" @@ -13,8 +13,8 @@ namespace ArduinoJson { // TDocument = DynamicJsonDocument, StaticJsonDocument // TString = const std::string&, const String& template -typename Internals::EnableIf::value, - DeserializationError>::type +typename Internals::enable_if::value, + DeserializationError>::type deserializeJson(TDocument &doc, const TString &input) { using namespace Internals; return makeJsonDeserializer(&doc.buffer(), makeReader(input), diff --git a/src/ArduinoJson/deserializeMsgPack.hpp b/src/ArduinoJson/deserializeMsgPack.hpp index 9256a411..7c38cdc5 100644 --- a/src/ArduinoJson/deserializeMsgPack.hpp +++ b/src/ArduinoJson/deserializeMsgPack.hpp @@ -13,8 +13,8 @@ namespace ArduinoJson { // TDocument = DynamicJsonDocument, StaticJsonDocument // TString = const std::string&, const String& template -typename Internals::EnableIf::value, - DeserializationError>::type +typename Internals::enable_if::value, + DeserializationError>::type deserializeMsgPack(TDocument &doc, const TString &input) { using namespace Internals; return makeMsgPackDeserializer(&doc.buffer(), makeReader(input), diff --git a/test/JsonWriter/writeFloat.cpp b/test/JsonWriter/writeFloat.cpp index aa06552b..73bc1912 100644 --- a/test/JsonWriter/writeFloat.cpp +++ b/test/JsonWriter/writeFloat.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/JsonWriter/writeString.cpp b/test/JsonWriter/writeString.cpp index eded06e3..104bc104 100644 --- a/test/JsonWriter/writeString.cpp +++ b/test/JsonWriter/writeString.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/Misc/FloatParts.cpp b/test/Misc/FloatParts.cpp index d9cf18a1..f3e10a74 100644 --- a/test/Misc/FloatParts.cpp +++ b/test/Misc/FloatParts.cpp @@ -2,7 +2,7 @@ // Copyright Benoit Blanchon 2014-2018 // MIT License -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/Misc/TypeTraits.cpp b/test/Misc/TypeTraits.cpp index 8d730b21..41cdebbc 100644 --- a/test/Misc/TypeTraits.cpp +++ b/test/Misc/TypeTraits.cpp @@ -7,21 +7,21 @@ using namespace ArduinoJson::Internals; -TEST_CASE("TypeTraits") { - SECTION("IsBaseOf") { +TEST_CASE("Polyfills/type_traits") { + SECTION("is_base_of") { REQUIRE_FALSE( - static_cast(IsBaseOf::value)); + static_cast(is_base_of::value)); REQUIRE( - static_cast(IsBaseOf::value)); + static_cast(is_base_of::value)); REQUIRE(static_cast( - IsBaseOf >, - JsonObjectSubscript >::value)); + is_base_of >, + JsonObjectSubscript >::value)); } - SECTION("IsArray") { - REQUIRE_FALSE((IsArray::value)); - REQUIRE((IsArray::value)); - REQUIRE((IsArray::value)); + SECTION("is_array") { + REQUIRE_FALSE((is_array::value)); + REQUIRE((is_array::value)); + REQUIRE((is_array::value)); } SECTION("IsVariant") { @@ -30,8 +30,30 @@ TEST_CASE("TypeTraits") { REQUIRE(static_cast(IsVariant::value)); } - SECTION("IsConst") { - REQUIRE_FALSE((IsConst::value)); - REQUIRE((IsConst::value)); + SECTION("is_const") { + CHECK(is_const::value == false); + CHECK(is_const::value == true); + } + + SECTION("is_signed") { + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == false); + } + + SECTION("is_unsigned") { + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); } } diff --git a/test/Polyfills/isFloat.cpp b/test/Polyfills/isFloat.cpp index f4fbe16b..3d77ac49 100644 --- a/test/Polyfills/isFloat.cpp +++ b/test/Polyfills/isFloat.cpp @@ -2,7 +2,7 @@ // Copyright Benoit Blanchon 2014-2018 // MIT License -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/Polyfills/isInteger.cpp b/test/Polyfills/isInteger.cpp index 8cc74dd1..a2f11fc9 100644 --- a/test/Polyfills/isInteger.cpp +++ b/test/Polyfills/isInteger.cpp @@ -2,7 +2,7 @@ // Copyright Benoit Blanchon 2014-2018 // MIT License -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/Polyfills/parseFloat.cpp b/test/Polyfills/parseFloat.cpp index bd481ea2..18cb0cfb 100644 --- a/test/Polyfills/parseFloat.cpp +++ b/test/Polyfills/parseFloat.cpp @@ -2,7 +2,7 @@ // Copyright Benoit Blanchon 2014-2018 // MIT License -#include +#include #include using namespace ArduinoJson::Internals; diff --git a/test/Polyfills/parseInteger.cpp b/test/Polyfills/parseInteger.cpp index afac3bf5..786834b1 100644 --- a/test/Polyfills/parseInteger.cpp +++ b/test/Polyfills/parseInteger.cpp @@ -3,7 +3,7 @@ // MIT License #include -#include +#include #include using namespace ArduinoJson::Internals;