forked from bblanchon/ArduinoJson
Reorganized polyfills
This commit is contained in:
@ -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"
|
||||
|
@ -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 <typename T>
|
||||
struct IsVariant : IsBaseOf<JsonVariantTag, T> {};
|
||||
}
|
||||
}
|
||||
struct IsVariant : is_base_of<JsonVariantTag, T> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -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 <typename Source>
|
||||
struct ValueSaver<
|
||||
Source, typename EnableIf<StringTraits<Source>::should_duplicate>::type> {
|
||||
Source, typename enable_if<StringTraits<Source>::should_duplicate>::type> {
|
||||
template <typename Destination>
|
||||
static bool save(JsonBuffer* buffer, Destination& dest, Source source) {
|
||||
if (!StringTraits<Source>::is_null(source)) {
|
||||
@ -41,7 +41,7 @@ struct ValueSaver<
|
||||
// const char*, const signed char*, const unsigned char*
|
||||
template <typename Char>
|
||||
struct ValueSaver<
|
||||
Char*, typename EnableIf<!StringTraits<Char*>::should_duplicate>::type> {
|
||||
Char*, typename enable_if<!StringTraits<Char*>::should_duplicate>::type> {
|
||||
template <typename Destination>
|
||||
static bool save(JsonBuffer*, Destination& dest, Char* source) {
|
||||
dest = reinterpret_cast<const char*>(source);
|
||||
|
@ -34,7 +34,7 @@ class DynamicJsonDocument {
|
||||
|
||||
// JsonObject& to<JsonObject>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonObject>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonObject>::value,
|
||||
JsonObject&>::type
|
||||
to() {
|
||||
clear();
|
||||
@ -46,7 +46,7 @@ class DynamicJsonDocument {
|
||||
|
||||
// JsonArray& to<JsonArray>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonArray>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonArray>::value,
|
||||
JsonArray&>::type
|
||||
to() {
|
||||
clear();
|
||||
@ -58,7 +58,7 @@ class DynamicJsonDocument {
|
||||
|
||||
// JsonVariant& to<JsonVariant>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonVariant>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value,
|
||||
T&>::type
|
||||
to() {
|
||||
clear();
|
||||
|
@ -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
|
@ -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<TWriter>::type::String str = _writer.startString();
|
||||
typename remove_reference<TWriter>::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();
|
||||
}
|
@ -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 TSource, typename TDestination>
|
||||
typename Internals::EnableIf<!Internals::StringTraits<TDestination>::has_append,
|
||||
size_t>::type
|
||||
typename Internals::enable_if<
|
||||
!Internals::StringTraits<TDestination>::has_append, size_t>::type
|
||||
serializeJson(const TSource &source, TDestination &destination) {
|
||||
Internals::JsonWriter<TDestination> writer(destination);
|
||||
Internals::JsonSerializer<Internals::JsonWriter<TDestination> >::serialize(
|
||||
@ -126,7 +126,7 @@ size_t serializeJson(const TSource &source, char (&buffer)[N]) {
|
||||
}
|
||||
|
||||
template <typename TSource, typename TDestination>
|
||||
typename Internals::EnableIf<Internals::StringTraits<TDestination>::has_append,
|
||||
typename Internals::enable_if<Internals::StringTraits<TDestination>::has_append,
|
||||
size_t>::type
|
||||
serializeJson(const TSource &source, TDestination &str) {
|
||||
Internals::DynamicStringBuilder<TDestination> sb(str);
|
||||
@ -153,15 +153,15 @@ size_t serializeJsonPretty(const TSource &source, char (&buffer)[N]) {
|
||||
}
|
||||
|
||||
template <typename TSource, typename TDestination>
|
||||
typename Internals::EnableIf<!Internals::StringTraits<TDestination>::has_append,
|
||||
size_t>::type
|
||||
typename Internals::enable_if<
|
||||
!Internals::StringTraits<TDestination>::has_append, size_t>::type
|
||||
serializeJsonPretty(const TSource &source, TDestination &print) {
|
||||
Internals::IndentedPrint<TDestination> indentedPrint(print);
|
||||
return serializeJsonPretty(source, indentedPrint);
|
||||
}
|
||||
|
||||
template <typename TSource, typename TDestination>
|
||||
typename Internals::EnableIf<Internals::StringTraits<TDestination>::has_append,
|
||||
typename Internals::enable_if<Internals::StringTraits<TDestination>::has_append,
|
||||
size_t>::type
|
||||
serializeJsonPretty(const TSource &source, TDestination &str) {
|
||||
Internals::DynamicStringBuilder<TDestination> sb(str);
|
@ -5,10 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#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 <typename TFloat>
|
||||
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<TFloat> parts(value);
|
||||
|
@ -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 T>
|
||||
typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value, bool>::type
|
||||
typename Internals::enable_if<Internals::is_floating_point<T>::value,
|
||||
bool>::type
|
||||
set(size_t index, T value, uint8_t decimals) {
|
||||
return set_impl<const JsonVariant &>(index, JsonVariant(value, decimals));
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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 <typename TValue>
|
||||
FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, this_type&>::type
|
||||
FORCE_INLINE typename enable_if<!is_array<TValue>::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 <typename TValue>
|
||||
FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, bool>::type set(
|
||||
FORCE_INLINE typename enable_if<!is_array<TValue>::value, bool>::type set(
|
||||
const TValue& value) {
|
||||
return _object.set(_key, value);
|
||||
}
|
||||
|
@ -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> {
|
||||
// JsonVariant(double value);
|
||||
// JsonVariant(float value);
|
||||
template <typename T>
|
||||
JsonVariant(T value, typename Internals::EnableIf<
|
||||
Internals::IsFloatingPoint<T>::value>::type * = 0) {
|
||||
JsonVariant(T value,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_floating_point<T>::value>::type * = 0) {
|
||||
using namespace Internals;
|
||||
_type = JSON_FLOAT;
|
||||
_content.asFloat = static_cast<JsonFloat>(value);
|
||||
@ -68,8 +61,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
template <typename T>
|
||||
JsonVariant(
|
||||
T value,
|
||||
typename Internals::EnableIf<Internals::IsSignedIntegral<T>::value ||
|
||||
Internals::IsSame<T, char>::value>::type * =
|
||||
typename Internals::enable_if<Internals::is_integral<T>::value &&
|
||||
Internals::is_signed<T>::value>::type * =
|
||||
0) {
|
||||
using namespace Internals;
|
||||
if (value >= 0) {
|
||||
@ -84,9 +77,11 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// JsonVariant(unsigned int)
|
||||
// JsonVariant(unsigned long)
|
||||
template <typename T>
|
||||
JsonVariant(T value,
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsUnsignedIntegral<T>::value>::type * = 0) {
|
||||
JsonVariant(
|
||||
T value,
|
||||
typename Internals::enable_if<Internals::is_integral<T>::value &&
|
||||
Internals::is_unsigned<T>::value>::type * =
|
||||
0) {
|
||||
using namespace Internals;
|
||||
_type = JSON_POSITIVE_INTEGER;
|
||||
_content.asInteger = static_cast<JsonUInt>(value);
|
||||
@ -97,10 +92,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// JsonVariant(const signed char*);
|
||||
// JsonVariant(const unsigned char*);
|
||||
template <typename TChar>
|
||||
JsonVariant(
|
||||
const TChar *value,
|
||||
typename Internals::EnableIf<Internals::IsChar<TChar>::value>::type * =
|
||||
0) {
|
||||
JsonVariant(const TChar *value,
|
||||
typename Internals::enable_if<sizeof(TChar) == 1>::type * = 0) {
|
||||
_type = Internals::JSON_STRING;
|
||||
_content.asString = reinterpret_cast<const char *>(value);
|
||||
}
|
||||
@ -143,13 +136,14 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// unsigned int as<unsigned int>() const;
|
||||
// unsigned long as<unsigned long>() const;
|
||||
template <typename T>
|
||||
const typename Internals::EnableIf<Internals::IsIntegral<T>::value, T>::type
|
||||
const typename Internals::enable_if<Internals::is_integral<T>::value, T>::type
|
||||
as() const {
|
||||
return variantAsInteger<T>();
|
||||
}
|
||||
// bool as<bool>() const
|
||||
template <typename T>
|
||||
const typename Internals::EnableIf<Internals::IsSame<T, bool>::value, T>::type
|
||||
const typename Internals::enable_if<Internals::is_same<T, bool>::value,
|
||||
T>::type
|
||||
as() const {
|
||||
return variantAsInteger<int>() != 0;
|
||||
}
|
||||
@ -157,7 +151,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// double as<double>() const;
|
||||
// float as<float>() const;
|
||||
template <typename T>
|
||||
const typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value,
|
||||
const typename Internals::enable_if<Internals::is_floating_point<T>::value,
|
||||
T>::type
|
||||
as() const {
|
||||
return variantAsFloat<T>();
|
||||
@ -166,8 +160,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// const char* as<const char*>() const;
|
||||
// const char* as<char*>() const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, const char *>::value ||
|
||||
Internals::IsSame<T, char *>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, const char *>::value ||
|
||||
Internals::is_same<T, char *>::value,
|
||||
const char *>::type
|
||||
as() const {
|
||||
return variantAsString();
|
||||
@ -176,7 +170,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// std::string as<std::string>() const;
|
||||
// String as<String>() const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::StringTraits<T>::has_append, T>::type
|
||||
typename Internals::enable_if<Internals::StringTraits<T>::has_append, T>::type
|
||||
as() const {
|
||||
const char *cstr = variantAsString();
|
||||
if (cstr) return T(cstr);
|
||||
@ -188,8 +182,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// JsonArray& as<JsonArray> const;
|
||||
// JsonArray& as<JsonArray&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveReference<T>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<typename Internals::remove_reference<T>::type,
|
||||
JsonArray>::value,
|
||||
JsonArray &>::type
|
||||
as() const {
|
||||
@ -198,8 +192,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
//
|
||||
// const JsonArray& as<const JsonArray&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveReference<T>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<typename Internals::remove_reference<T>::type,
|
||||
const JsonArray>::value,
|
||||
const JsonArray &>::type
|
||||
as() const {
|
||||
@ -209,8 +203,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// JsonObject& as<JsonObject> const;
|
||||
// JsonObject& as<JsonObject&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveReference<T>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<typename Internals::remove_reference<T>::type,
|
||||
JsonObject>::value,
|
||||
JsonObject &>::type
|
||||
as() const {
|
||||
@ -220,8 +214,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// JsonObject& as<const JsonObject> const;
|
||||
// JsonObject& as<const JsonObject&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveReference<T>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<typename Internals::remove_reference<T>::type,
|
||||
const JsonObject>::value,
|
||||
const JsonObject &>::type
|
||||
as() const {
|
||||
@ -230,7 +224,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
//
|
||||
// JsonVariant as<JsonVariant> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonVariant>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value,
|
||||
T>::type
|
||||
as() const {
|
||||
return *this;
|
||||
@ -249,22 +243,23 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// bool is<unsigned int>() const;
|
||||
// bool is<unsigned long>() const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsIntegral<T>::value, bool>::type is()
|
||||
const {
|
||||
typename Internals::enable_if<Internals::is_integral<T>::value, bool>::type
|
||||
is() const {
|
||||
return variantIsInteger();
|
||||
}
|
||||
//
|
||||
// bool is<double>() const;
|
||||
// bool is<float>() const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value, bool>::type
|
||||
typename Internals::enable_if<Internals::is_floating_point<T>::value,
|
||||
bool>::type
|
||||
is() const {
|
||||
return variantIsFloat();
|
||||
}
|
||||
//
|
||||
// bool is<bool>() const
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, bool>::value, bool>::type
|
||||
typename Internals::enable_if<Internals::is_same<T, bool>::value, bool>::type
|
||||
is() const {
|
||||
return variantIsBoolean();
|
||||
}
|
||||
@ -272,8 +267,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// bool is<const char*>() const;
|
||||
// bool is<char*>() const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, const char *>::value ||
|
||||
Internals::IsSame<T, char *>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, const char *>::value ||
|
||||
Internals::is_same<T, char *>::value,
|
||||
bool>::type
|
||||
is() const {
|
||||
return variantIsString();
|
||||
@ -283,9 +278,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// bool is<JsonArray&> const;
|
||||
// bool is<const JsonArray&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveConst<
|
||||
typename Internals::RemoveReference<T>::type>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<
|
||||
typename Internals::remove_const<
|
||||
typename Internals::remove_reference<T>::type>::type,
|
||||
JsonArray>::value,
|
||||
bool>::type
|
||||
is() const {
|
||||
@ -296,9 +292,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
||||
// bool is<JsonObject&> const;
|
||||
// bool is<const JsonObject&> const;
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<
|
||||
Internals::IsSame<typename Internals::RemoveConst<
|
||||
typename Internals::RemoveReference<T>::type>::type,
|
||||
typename Internals::enable_if<
|
||||
Internals::is_same<
|
||||
typename Internals::remove_const<
|
||||
typename Internals::remove_reference<T>::type>::type,
|
||||
JsonObject>::value,
|
||||
bool>::type
|
||||
is() const {
|
||||
|
@ -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 <typename TComparand>
|
||||
friend typename EnableIf<!IsVariant<TComparand>::value, bool>::type
|
||||
friend typename enable_if<!IsVariant<TComparand>::value, bool>::type
|
||||
operator==(TComparand comparand, const JsonVariantComparisons &variant) {
|
||||
return variant.equals(comparand);
|
||||
}
|
||||
@ -33,7 +33,7 @@ class JsonVariantComparisons {
|
||||
}
|
||||
|
||||
template <typename TComparand>
|
||||
friend typename EnableIf<!IsVariant<TComparand>::value, bool>::type
|
||||
friend typename enable_if<!IsVariant<TComparand>::value, bool>::type
|
||||
operator!=(TComparand comparand, const JsonVariantComparisons &variant) {
|
||||
return !variant.equals(comparand);
|
||||
}
|
||||
@ -101,14 +101,14 @@ class JsonVariantComparisons {
|
||||
}
|
||||
|
||||
template <typename TString>
|
||||
typename EnableIf<StringTraits<TString>::has_equals, bool>::type equals(
|
||||
typename enable_if<StringTraits<TString>::has_equals, bool>::type equals(
|
||||
const TString &comparand) const {
|
||||
const char *value = as<const char *>();
|
||||
return StringTraits<TString>::equals(comparand, value);
|
||||
}
|
||||
|
||||
template <typename TComparand>
|
||||
typename EnableIf<!IsVariant<TComparand>::value &&
|
||||
typename enable_if<!IsVariant<TComparand>::value &&
|
||||
!StringTraits<TComparand>::has_equals,
|
||||
bool>::type
|
||||
equals(const TComparand &comparand) const {
|
||||
|
@ -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 <string.h> // for strcmp
|
||||
|
||||
|
@ -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 T>
|
||||
typename EnableIf<!IsIntegral<T>::value, T>::type operator|(
|
||||
typename enable_if<!is_integral<T>::value, T>::type operator|(
|
||||
const T &defaultValue) const {
|
||||
if (impl()->template is<T>())
|
||||
return impl()->template as<T>();
|
||||
@ -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 Integer>
|
||||
typename EnableIf<IsIntegral<Integer>::value, Integer>::type operator|(
|
||||
typename enable_if<is_integral<Integer>::value, Integer>::type operator|(
|
||||
const Integer &defaultValue) const {
|
||||
if (impl()->template is<double>())
|
||||
return impl()->template as<Integer>();
|
||||
|
@ -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,7 +43,7 @@ class JsonVariantSubscripts {
|
||||
// TKey = const std::string&, const String&
|
||||
template <typename TString>
|
||||
FORCE_INLINE
|
||||
typename EnableIf<StringTraits<TString>::has_equals,
|
||||
typename enable_if<StringTraits<TString>::has_equals,
|
||||
const JsonObjectSubscript<const TString &> >::type
|
||||
operator[](const TString &key) const {
|
||||
return impl()->template as<JsonObject>()[key];
|
||||
@ -52,7 +52,7 @@ class JsonVariantSubscripts {
|
||||
// const JsonObjectSubscript operator[](TKey) const;
|
||||
// TKey = const std::string&, const String&
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename EnableIf<StringTraits<TString>::has_equals,
|
||||
FORCE_INLINE typename enable_if<StringTraits<TString>::has_equals,
|
||||
JsonObjectSubscript<const TString &> >::type
|
||||
operator[](const TString &key) {
|
||||
return impl()->template as<JsonObject>()[key];
|
||||
@ -61,7 +61,7 @@ class JsonVariantSubscripts {
|
||||
// JsonObjectSubscript operator[](TKey);
|
||||
// TKey = const char*, const char[N], const FlashStringHelper*
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename EnableIf<StringTraits<const TString *>::has_equals,
|
||||
FORCE_INLINE typename enable_if<StringTraits<const TString *>::has_equals,
|
||||
JsonObjectSubscript<const TString *> >::type
|
||||
operator[](const TString *key) {
|
||||
return impl()->template as<JsonObject>()[key];
|
||||
@ -71,7 +71,7 @@ class JsonVariantSubscripts {
|
||||
// TKey = const char*, const char[N], const FlashStringHelper*
|
||||
template <typename TString>
|
||||
FORCE_INLINE
|
||||
typename EnableIf<StringTraits<TString *>::has_equals,
|
||||
typename enable_if<StringTraits<TString *>::has_equals,
|
||||
const JsonObjectSubscript<const TString *> >::type
|
||||
operator[](const TString *key) const {
|
||||
return impl()->template as<JsonObject>()[key];
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../TypeTraits/Max.hpp"
|
||||
#include "../Polyfills/mpl/max.hpp"
|
||||
#include "JsonBuffer.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
@ -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 T>
|
||||
typename EnableIf<sizeof(T) == 4, DeserializationError>::type readFloat(
|
||||
typename enable_if<sizeof(T) == 4, DeserializationError>::type readFloat(
|
||||
JsonVariant &variant) {
|
||||
T value;
|
||||
if (!readBytes(value)) return DeserializationError::IncompleteInput;
|
||||
@ -191,7 +191,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 8, DeserializationError>::type readDouble(
|
||||
typename enable_if<sizeof(T) == 8, DeserializationError>::type readDouble(
|
||||
JsonVariant &variant) {
|
||||
T value;
|
||||
if (!readBytes(value)) return DeserializationError::IncompleteInput;
|
||||
@ -201,7 +201,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 4, DeserializationError>::type readDouble(
|
||||
typename enable_if<sizeof(T) == 4, DeserializationError>::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<TWriter>::type::String str = _writer.startString();
|
||||
typename remove_reference<TWriter>::type::String str =
|
||||
_writer.startString();
|
||||
for (; n; --n) {
|
||||
uint8_t c;
|
||||
if (!readBytes(c)) return DeserializationError::IncompleteInput;
|
||||
|
@ -4,12 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Polyfills/type_traits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <class T, T v>
|
||||
struct integral_constant {};
|
||||
|
||||
template <typename T>
|
||||
inline void swap(T& a, T& b) {
|
||||
T t(a);
|
||||
|
@ -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 {
|
@ -146,5 +146,5 @@ struct FloatTraits<T, 4 /*32bits*/> {
|
||||
return forge(0x7f800000);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -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 {
|
@ -7,13 +7,13 @@
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
template <typename T>
|
||||
bool isNaN(T x) {
|
||||
bool isnan(T x) {
|
||||
return x != x;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool isInfinity(T x) {
|
||||
bool isinf(T x) {
|
||||
return x != 0.0 && x * 2 == x;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
18
src/ArduinoJson/Polyfills/type_traits.hpp
Normal file
18
src/ArduinoJson/Polyfills/type_traits.hpp
Normal file
@ -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"
|
@ -9,11 +9,11 @@ namespace Internals {
|
||||
|
||||
// A meta-function that return the type T if Condition is true.
|
||||
template <bool Condition, typename T = void>
|
||||
struct EnableIf {};
|
||||
struct enable_if {};
|
||||
|
||||
template <typename T>
|
||||
struct EnableIf<true, T> {
|
||||
struct enable_if<true, T> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
19
src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp
Normal file
19
src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename T, T v>
|
||||
struct integral_constant {
|
||||
static const T value = v;
|
||||
};
|
||||
|
||||
typedef integral_constant<bool, true> true_type;
|
||||
typedef integral_constant<bool, false> false_type;
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
19
src/ArduinoJson/Polyfills/type_traits/is_array.hpp
Normal file
19
src/ArduinoJson/Polyfills/type_traits/is_array.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename T>
|
||||
struct is_array : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_array<T[]> : true_type {};
|
||||
|
||||
template <typename T, size_t N>
|
||||
struct is_array<T[N]> : true_type {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -10,7 +10,7 @@ namespace Internals {
|
||||
// A meta-function that returns true if Derived inherits from TBase is an
|
||||
// integral type.
|
||||
template <typename TBase, typename TDerived>
|
||||
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<TDerived *>(0))) == sizeof(Yes)
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -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 <typename T>
|
||||
struct IsConst {
|
||||
static const bool value = false;
|
||||
};
|
||||
struct is_const : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsConst<const T> {
|
||||
static const bool value = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
struct is_const<const T> : true_type {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
21
src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp
Normal file
21
src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp
Normal file
@ -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 <typename>
|
||||
struct is_floating_point : false_type {};
|
||||
|
||||
template <>
|
||||
struct is_floating_point<float> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_floating_point<double> : true_type {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
35
src/ArduinoJson/Polyfills/type_traits/is_integral.hpp
Normal file
35
src/ArduinoJson/Polyfills/type_traits/is_integral.hpp
Normal file
@ -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 <typename T>
|
||||
struct is_integral {
|
||||
static const bool value =
|
||||
is_same<T, signed char>::value || is_same<T, unsigned char>::value ||
|
||||
is_same<T, signed short>::value || is_same<T, unsigned short>::value ||
|
||||
is_same<T, signed int>::value || is_same<T, unsigned int>::value ||
|
||||
is_same<T, signed long>::value || is_same<T, unsigned long>::value ||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
is_same<T, unsigned long long>::value ||
|
||||
is_same<T, signed long long>::value ||
|
||||
#endif
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
is_same<T, unsigned __int64>::value ||
|
||||
is_same<T, signed __int64>::value ||
|
||||
#endif
|
||||
is_same<T, char>::value;
|
||||
// CAUTION: differs from std::is_integral as it doesn't include bool
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_integral<const T> : is_integral<T> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -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 <typename T, typename U>
|
||||
struct IsSame {
|
||||
static const bool value = false;
|
||||
};
|
||||
struct is_same : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsSame<T, T> {
|
||||
static const bool value = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
struct is_same<T, T> : true_type {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
44
src/ArduinoJson/Polyfills/type_traits/is_signed.hpp
Normal file
44
src/ArduinoJson/Polyfills/type_traits/is_signed.hpp
Normal file
@ -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 <typename>
|
||||
struct is_signed : false_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<char> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<signed char> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<signed short> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<signed int> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<signed long> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<float> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_signed<double> : true_type {};
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
template <>
|
||||
struct is_signed<signed long long> : true_type {};
|
||||
#endif
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
template <>
|
||||
struct is_signed<signed __int64> : true_type {};
|
||||
#endif
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
38
src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp
Normal file
38
src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp
Normal file
@ -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 <typename>
|
||||
struct is_unsigned : false_type {};
|
||||
|
||||
template <>
|
||||
struct is_unsigned<bool> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_unsigned<unsigned char> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_unsigned<unsigned short> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_unsigned<unsigned int> : true_type {};
|
||||
|
||||
template <>
|
||||
struct is_unsigned<unsigned long> : true_type {};
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
template <>
|
||||
struct is_unsigned<unsigned long long> : true_type {};
|
||||
#endif
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
template <>
|
||||
struct is_unsigned<unsigned __int64> : true_type {};
|
||||
#endif
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -9,12 +9,12 @@ namespace Internals {
|
||||
|
||||
// A meta-function that return the type T without the const modifier
|
||||
template <typename T>
|
||||
struct RemoveConst {
|
||||
struct remove_const {
|
||||
typedef T type;
|
||||
};
|
||||
template <typename T>
|
||||
struct RemoveConst<const T> {
|
||||
struct remove_const<const T> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -9,12 +9,12 @@ namespace Internals {
|
||||
|
||||
// A meta-function that return the type T without the reference modifier.
|
||||
template <typename T>
|
||||
struct RemoveReference {
|
||||
struct remove_reference {
|
||||
typedef T type;
|
||||
};
|
||||
template <typename T>
|
||||
struct RemoveReference<T&> {
|
||||
struct remove_reference<T&> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -35,7 +35,7 @@ class StaticJsonDocument {
|
||||
|
||||
// JsonObject& to<JsonObject>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonObject>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonObject>::value,
|
||||
JsonObject&>::type
|
||||
to() {
|
||||
clear();
|
||||
@ -47,7 +47,7 @@ class StaticJsonDocument {
|
||||
|
||||
// JsonArray& to<JsonArray>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonArray>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonArray>::value,
|
||||
JsonArray&>::type
|
||||
to() {
|
||||
clear();
|
||||
@ -59,7 +59,7 @@ class StaticJsonDocument {
|
||||
|
||||
// JsonVariant to<JsonVariant>()
|
||||
template <typename T>
|
||||
typename Internals::EnableIf<Internals::IsSame<T, JsonVariant>::value,
|
||||
typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value,
|
||||
T&>::type
|
||||
to() {
|
||||
clear();
|
||||
|
@ -30,13 +30,13 @@ struct CharPointerTraits {
|
||||
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = !IsConst<TChar>::value;
|
||||
static const bool should_duplicate = !is_const<TChar>::value;
|
||||
};
|
||||
|
||||
// char*, unsigned char*, signed char*
|
||||
// const char*, const unsigned char*, const signed char*
|
||||
template <typename TChar>
|
||||
struct StringTraits<TChar*, typename EnableIf<IsChar<TChar>::value>::type>
|
||||
struct StringTraits<TChar*, typename enable_if<sizeof(TChar) == 1>::type>
|
||||
: CharPointerTraits<TChar> {};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
@ -6,11 +6,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#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<const TString, void> : StringTraits<TString> {};
|
||||
|
||||
template <typename TString>
|
||||
struct StringTraits<TString&, void> : StringTraits<TString> {};
|
||||
}
|
||||
}
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#include "CharPointer.hpp"
|
||||
#include "FlashString.hpp"
|
||||
|
@ -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 <typename T>
|
||||
struct IsArray {
|
||||
static const bool value = false;
|
||||
};
|
||||
template <typename T>
|
||||
struct IsArray<T[]> {
|
||||
static const bool value = true;
|
||||
};
|
||||
template <typename T, size_t N>
|
||||
struct IsArray<T[N]> {
|
||||
static const bool value = true;
|
||||
};
|
||||
}
|
||||
}
|
@ -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 <typename T>
|
||||
struct IsChar {
|
||||
static const bool value = IsSame<T, char>::value ||
|
||||
IsSame<T, signed char>::value ||
|
||||
IsSame<T, unsigned char>::value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsChar<const T> : IsChar<T> {};
|
||||
}
|
||||
}
|
@ -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 <typename T>
|
||||
struct IsFloatingPoint {
|
||||
static const bool value = IsSame<T, float>::value || IsSame<T, double>::value;
|
||||
};
|
||||
}
|
||||
}
|
@ -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 <typename T>
|
||||
struct IsIntegral {
|
||||
static const bool value = IsSignedIntegral<T>::value ||
|
||||
IsUnsignedIntegral<T>::value ||
|
||||
IsSame<T, char>::value;
|
||||
// CAUTION: differs from std::is_integral as it doesn't include bool
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsIntegral<const T> : IsIntegral<T> {};
|
||||
}
|
||||
}
|
@ -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 <typename T>
|
||||
struct IsSignedIntegral {
|
||||
static const bool value =
|
||||
IsSame<T, signed char>::value || IsSame<T, signed short>::value ||
|
||||
IsSame<T, signed int>::value || IsSame<T, signed long>::value ||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
IsSame<T, signed long long>::value ||
|
||||
#endif
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
IsSame<T, signed __int64>::value ||
|
||||
#endif
|
||||
false;
|
||||
};
|
||||
}
|
||||
}
|
@ -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 <typename T>
|
||||
struct IsUnsignedIntegral {
|
||||
static const bool value =
|
||||
IsSame<T, unsigned char>::value || IsSame<T, unsigned short>::value ||
|
||||
IsSame<T, unsigned int>::value || IsSame<T, unsigned long>::value ||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
IsSame<T, unsigned long long>::value ||
|
||||
#endif
|
||||
#if ARDUINOJSON_USE_INT64
|
||||
IsSame<T, unsigned __int64>::value ||
|
||||
#endif
|
||||
false;
|
||||
};
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ struct Writer {
|
||||
|
||||
template <typename TJsonBuffer, typename TChar>
|
||||
struct Writer<TJsonBuffer, TChar*,
|
||||
typename EnableIf<!IsConst<TChar>::value>::type> {
|
||||
typename enable_if<!is_const<TChar>::value>::type> {
|
||||
typedef StringWriter<TChar> type;
|
||||
|
||||
static type create(TJsonBuffer&, TChar* input) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Json/Deserialization/JsonDeserializer.hpp"
|
||||
#include "Json/JsonDeserializer.hpp"
|
||||
#include "Reading/Reader.hpp"
|
||||
#include "Writing/Writer.hpp"
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ArduinoJson {
|
||||
// TDocument = DynamicJsonDocument, StaticJsonDocument
|
||||
// TString = const std::string&, const String&
|
||||
template <typename TDocument, typename TString>
|
||||
typename Internals::EnableIf<!Internals::IsArray<TString>::value,
|
||||
typename Internals::enable_if<!Internals::is_array<TString>::value,
|
||||
DeserializationError>::type
|
||||
deserializeJson(TDocument &doc, const TString &input) {
|
||||
using namespace Internals;
|
||||
|
@ -13,7 +13,7 @@ namespace ArduinoJson {
|
||||
// TDocument = DynamicJsonDocument, StaticJsonDocument
|
||||
// TString = const std::string&, const String&
|
||||
template <typename TDocument, typename TString>
|
||||
typename Internals::EnableIf<!Internals::IsArray<TString>::value,
|
||||
typename Internals::enable_if<!Internals::is_array<TString>::value,
|
||||
DeserializationError>::type
|
||||
deserializeMsgPack(TDocument &doc, const TString &input) {
|
||||
using namespace Internals;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <ArduinoJson/Json/Serialization/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Json/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Print/DynamicStringBuilder.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <ArduinoJson/Json/Serialization/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Json/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Print/StaticStringBuilder.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Json/Serialization/FloatParts.hpp>
|
||||
#include <ArduinoJson/Numbers/FloatParts.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -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<bool>(IsBaseOf<std::istream, std::ostringstream>::value));
|
||||
static_cast<bool>(is_base_of<std::istream, std::ostringstream>::value));
|
||||
REQUIRE(
|
||||
static_cast<bool>(IsBaseOf<std::istream, std::istringstream>::value));
|
||||
static_cast<bool>(is_base_of<std::istream, std::istringstream>::value));
|
||||
REQUIRE(static_cast<bool>(
|
||||
IsBaseOf<JsonVariantBase<JsonObjectSubscript<const char*> >,
|
||||
is_base_of<JsonVariantBase<JsonObjectSubscript<const char*> >,
|
||||
JsonObjectSubscript<const char*> >::value));
|
||||
}
|
||||
|
||||
SECTION("IsArray") {
|
||||
REQUIRE_FALSE((IsArray<const char*>::value));
|
||||
REQUIRE((IsArray<const char[]>::value));
|
||||
REQUIRE((IsArray<const char[10]>::value));
|
||||
SECTION("is_array") {
|
||||
REQUIRE_FALSE((is_array<const char*>::value));
|
||||
REQUIRE((is_array<const char[]>::value));
|
||||
REQUIRE((is_array<const char[10]>::value));
|
||||
}
|
||||
|
||||
SECTION("IsVariant") {
|
||||
@ -30,8 +30,30 @@ TEST_CASE("TypeTraits") {
|
||||
REQUIRE(static_cast<bool>(IsVariant<JsonVariant>::value));
|
||||
}
|
||||
|
||||
SECTION("IsConst") {
|
||||
REQUIRE_FALSE((IsConst<char>::value));
|
||||
REQUIRE((IsConst<const char>::value));
|
||||
SECTION("is_const") {
|
||||
CHECK(is_const<char>::value == false);
|
||||
CHECK(is_const<const char>::value == true);
|
||||
}
|
||||
|
||||
SECTION("is_signed") {
|
||||
CHECK(is_signed<char>::value == true);
|
||||
CHECK(is_signed<signed char>::value == true);
|
||||
CHECK(is_signed<signed int>::value == true);
|
||||
CHECK(is_signed<signed short>::value == true);
|
||||
CHECK(is_signed<signed long>::value == true);
|
||||
CHECK(is_signed<float>::value == true);
|
||||
CHECK(is_signed<double>::value == true);
|
||||
CHECK(is_signed<bool>::value == false);
|
||||
}
|
||||
|
||||
SECTION("is_unsigned") {
|
||||
CHECK(is_unsigned<unsigned char>::value == true);
|
||||
CHECK(is_unsigned<unsigned int>::value == true);
|
||||
CHECK(is_unsigned<unsigned short>::value == true);
|
||||
CHECK(is_unsigned<unsigned long>::value == true);
|
||||
CHECK(is_unsigned<bool>::value == true);
|
||||
CHECK(is_unsigned<char>::value == false);
|
||||
CHECK(is_unsigned<float>::value == false);
|
||||
CHECK(is_unsigned<double>::value == false);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Text/isFloat.hpp>
|
||||
#include <ArduinoJson/Numbers/isFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Text/isInteger.hpp>
|
||||
#include <ArduinoJson/Numbers/isInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Text/parseFloat.hpp>
|
||||
#include <ArduinoJson/Numbers/parseFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
@ -3,7 +3,7 @@
|
||||
// MIT License
|
||||
|
||||
#include <stdint.h>
|
||||
#include <ArduinoJson/Text/parseInteger.hpp>
|
||||
#include <ArduinoJson/Numbers/parseInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
Reference in New Issue
Block a user