From 4f6253aa9fec99260b8bb7b9b2e9003f5259b600 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Sep 2018 10:02:07 +0200 Subject: Import arduinojson and ubjson. Only partially working at the moment --- include/lib/ArduinoJson/TypeTraits/EnableIf.hpp | 19 +++ include/lib/ArduinoJson/TypeTraits/FloatTraits.hpp | 171 +++++++++++++++++++++ include/lib/ArduinoJson/TypeTraits/IsArray.hpp | 24 +++ include/lib/ArduinoJson/TypeTraits/IsBaseOf.hpp | 27 ++++ include/lib/ArduinoJson/TypeTraits/IsChar.hpp | 23 +++ include/lib/ArduinoJson/TypeTraits/IsConst.hpp | 21 +++ .../lib/ArduinoJson/TypeTraits/IsFloatingPoint.hpp | 18 +++ include/lib/ArduinoJson/TypeTraits/IsIntegral.hpp | 26 ++++ include/lib/ArduinoJson/TypeTraits/IsSame.hpp | 21 +++ .../ArduinoJson/TypeTraits/IsSignedIntegral.hpp | 28 ++++ .../ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp | 28 ++++ include/lib/ArduinoJson/TypeTraits/IsVariant.hpp | 17 ++ include/lib/ArduinoJson/TypeTraits/RemoveConst.hpp | 20 +++ .../lib/ArduinoJson/TypeTraits/RemoveReference.hpp | 20 +++ 14 files changed, 463 insertions(+) create mode 100644 include/lib/ArduinoJson/TypeTraits/EnableIf.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/FloatTraits.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsArray.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsBaseOf.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsChar.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsConst.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsFloatingPoint.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsIntegral.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsSame.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsSignedIntegral.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/IsVariant.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/RemoveConst.hpp create mode 100644 include/lib/ArduinoJson/TypeTraits/RemoveReference.hpp (limited to 'include/lib/ArduinoJson/TypeTraits') diff --git a/include/lib/ArduinoJson/TypeTraits/EnableIf.hpp b/include/lib/ArduinoJson/TypeTraits/EnableIf.hpp new file mode 100644 index 0000000..83fc5e0 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/EnableIf.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +// A meta-function that return the type T if Condition is true. +template +struct EnableIf {}; + +template +struct EnableIf { + typedef T type; +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/FloatTraits.hpp b/include/lib/ArduinoJson/TypeTraits/FloatTraits.hpp new file mode 100644 index 0000000..648cc82 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/FloatTraits.hpp @@ -0,0 +1,171 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include +#include // for size_t +#include "../Configuration.hpp" +#include "../Polyfills/math.hpp" + +namespace ArduinoJson { +namespace Internals { + +template +struct FloatTraits {}; + +template +struct FloatTraits { + typedef int64_t mantissa_type; + static const short mantissa_bits = 52; + static const mantissa_type mantissa_max = + (static_cast(1) << mantissa_bits) - 1; + + typedef int16_t exponent_type; + static const exponent_type exponent_max = 308; + + template + static T make_float(T m, TExponent e) { + if (e > 0) { + for (uint8_t index = 0; e != 0; index++) { + if (e & 1) m *= positiveBinaryPowerOfTen(index); + e >>= 1; + } + } else { + e = TExponent(-e); + for (uint8_t index = 0; e != 0; index++) { + if (e & 1) m *= negativeBinaryPowerOfTen(index); + e >>= 1; + } + } + return m; + } + + static T positiveBinaryPowerOfTen(int index) { + static T factors[] = { + 1e1, + 1e2, + 1e4, + 1e8, + 1e16, + forge(0x4693B8B5, 0xB5056E17), // 1e32 + forge(0x4D384F03, 0xE93FF9F5), // 1e64 + forge(0x5A827748, 0xF9301D32), // 1e128 + forge(0x75154FDD, 0x7F73BF3C) // 1e256 + }; + return factors[index]; + } + + static T negativeBinaryPowerOfTen(int index) { + static T factors[] = { + forge(0x3FB99999, 0x9999999A), // 1e-1 + forge(0x3F847AE1, 0x47AE147B), // 1e-2 + forge(0x3F1A36E2, 0xEB1C432D), // 1e-4 + forge(0x3E45798E, 0xE2308C3A), // 1e-8 + forge(0x3C9CD2B2, 0x97D889BC), // 1e-16 + forge(0x3949F623, 0xD5A8A733), // 1e-32 + forge(0x32A50FFD, 0x44F4A73D), // 1e-64 + forge(0x255BBA08, 0xCF8C979D), // 1e-128 + forge(0x0AC80628, 0x64AC6F43) // 1e-256 + }; + return factors[index]; + } + + static T negativeBinaryPowerOfTenPlusOne(int index) { + static T factors[] = { + 1e0, + forge(0x3FB99999, 0x9999999A), // 1e-1 + forge(0x3F50624D, 0xD2F1A9FC), // 1e-3 + forge(0x3E7AD7F2, 0x9ABCAF48), // 1e-7 + forge(0x3CD203AF, 0x9EE75616), // 1e-15 + forge(0x398039D6, 0x65896880), // 1e-31 + forge(0x32DA53FC, 0x9631D10D), // 1e-63 + forge(0x25915445, 0x81B7DEC2), // 1e-127 + forge(0x0AFE07B2, 0x7DD78B14) // 1e-255 + }; + return factors[index]; + } + + static T nan() { + return forge(0x7ff80000, 0x00000000); + } + + static T inf() { + return forge(0x7ff00000, 0x00000000); + } + + // constructs a double floating point values from its binary representation + // we use this function to workaround platforms with single precision literals + // (for example, when -fsingle-precision-constant is passed to GCC) + static T forge(uint32_t msb, uint32_t lsb) { + union { + uint64_t integerBits; + T floatBits; + }; + integerBits = (uint64_t(msb) << 32) | lsb; + return floatBits; + } +}; + +template +struct FloatTraits { + typedef int32_t mantissa_type; + static const short mantissa_bits = 23; + static const mantissa_type mantissa_max = + (static_cast(1) << mantissa_bits) - 1; + + typedef int8_t exponent_type; + static const exponent_type exponent_max = 38; + + template + static T make_float(T m, TExponent e) { + if (e > 0) { + for (uint8_t index = 0; e != 0; index++) { + if (e & 1) m *= positiveBinaryPowerOfTen(index); + e >>= 1; + } + } else { + e = -e; + for (uint8_t index = 0; e != 0; index++) { + if (e & 1) m *= negativeBinaryPowerOfTen(index); + e >>= 1; + } + } + return m; + } + + static T positiveBinaryPowerOfTen(int index) { + static T factors[] = {1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f}; + return factors[index]; + } + + static T negativeBinaryPowerOfTen(int index) { + static T factors[] = {1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f}; + return factors[index]; + } + + static T negativeBinaryPowerOfTenPlusOne(int index) { + static T factors[] = {1e0f, 1e-1f, 1e-3f, 1e-7f, 1e-15f, 1e-31f}; + return factors[index]; + } + + static T forge(uint32_t bits) { + union { + uint32_t integerBits; + T floatBits; + }; + integerBits = bits; + return floatBits; + } + + static T nan() { + return forge(0x7fc00000); + } + + static T inf() { + return forge(0x7f800000); + } +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/IsArray.hpp b/include/lib/ArduinoJson/TypeTraits/IsArray.hpp new file mode 100644 index 0000000..2599231 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsArray.hpp @@ -0,0 +1,24 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsBaseOf.hpp b/include/lib/ArduinoJson/TypeTraits/IsBaseOf.hpp new file mode 100644 index 0000000..bf24e96 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsBaseOf.hpp @@ -0,0 +1,27 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +// A meta-function that returns true if Derived inherits from TBase is an +// integral type. +template +class IsBaseOf { + protected: // <- to avoid GCC's "all member functions in class are private" + typedef char Yes[1]; + typedef char No[2]; + + static Yes &probe(const TBase *); + static No &probe(...); + + public: + enum { + value = sizeof(probe(reinterpret_cast(0))) == sizeof(Yes) + }; +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/IsChar.hpp b/include/lib/ArduinoJson/TypeTraits/IsChar.hpp new file mode 100644 index 0000000..d97cec2 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsChar.hpp @@ -0,0 +1,23 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsConst.hpp b/include/lib/ArduinoJson/TypeTraits/IsConst.hpp new file mode 100644 index 0000000..512ee5c --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsConst.hpp @@ -0,0 +1,21 @@ +// 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 IsConst { + static const bool value = false; +}; + +template +struct IsConst { + static const bool value = true; +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/IsFloatingPoint.hpp b/include/lib/ArduinoJson/TypeTraits/IsFloatingPoint.hpp new file mode 100644 index 0000000..e41a682 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsFloatingPoint.hpp @@ -0,0 +1,18 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsIntegral.hpp b/include/lib/ArduinoJson/TypeTraits/IsIntegral.hpp new file mode 100644 index 0000000..17ae5f2 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsIntegral.hpp @@ -0,0 +1,26 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsSame.hpp b/include/lib/ArduinoJson/TypeTraits/IsSame.hpp new file mode 100644 index 0000000..06567c9 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsSame.hpp @@ -0,0 +1,21 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +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; +}; + +template +struct IsSame { + static const bool value = true; +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/IsSignedIntegral.hpp b/include/lib/ArduinoJson/TypeTraits/IsSignedIntegral.hpp new file mode 100644 index 0000000..7334eb9 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsSignedIntegral.hpp @@ -0,0 +1,28 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp b/include/lib/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp new file mode 100644 index 0000000..938423f --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp @@ -0,0 +1,28 @@ +// 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/include/lib/ArduinoJson/TypeTraits/IsVariant.hpp b/include/lib/ArduinoJson/TypeTraits/IsVariant.hpp new file mode 100644 index 0000000..f8b299f --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/IsVariant.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "IsBaseOf.hpp" + +namespace ArduinoJson { +namespace Internals { + +class JsonVariantTag {}; + +template +struct IsVariant : IsBaseOf {}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/RemoveConst.hpp b/include/lib/ArduinoJson/TypeTraits/RemoveConst.hpp new file mode 100644 index 0000000..39d4cb5 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/RemoveConst.hpp @@ -0,0 +1,20 @@ +// 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 RemoveConst { + typedef T type; +}; +template +struct RemoveConst { + typedef T type; +}; +} +} diff --git a/include/lib/ArduinoJson/TypeTraits/RemoveReference.hpp b/include/lib/ArduinoJson/TypeTraits/RemoveReference.hpp new file mode 100644 index 0000000..395a128 --- /dev/null +++ b/include/lib/ArduinoJson/TypeTraits/RemoveReference.hpp @@ -0,0 +1,20 @@ +// 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 reference modifier. +template +struct RemoveReference { + typedef T type; +}; +template +struct RemoveReference { + typedef T type; +}; +} +} -- cgit v1.2.3