mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Allow mixed configuration in compilation units (issue #809)
This commit is contained in:
		| @@ -5,6 +5,7 @@ HEAD | ||||
| ---- | ||||
|  | ||||
| * Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant` | ||||
| * Allow mixed configuration in compilation units (issue #809) | ||||
|  | ||||
| v6.4.0-beta (2018-09-11) | ||||
| ----------- | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "ArduinoJson/version.hpp" | ||||
| #include "ArduinoJson/Namespace.hpp" | ||||
|  | ||||
| #include "ArduinoJson/DynamicJsonDocument.hpp" | ||||
| #include "ArduinoJson/StaticJsonDocument.hpp" | ||||
| @@ -24,3 +24,16 @@ | ||||
| #include "ArduinoJson/Json/PrettyJsonSerializer.hpp" | ||||
| #include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" | ||||
| #include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| using ARDUINOJSON_NAMESPACE::DeserializationError; | ||||
| using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; | ||||
| using ARDUINOJSON_NAMESPACE::JsonArray; | ||||
| using ARDUINOJSON_NAMESPACE::JsonFloat; | ||||
| using ARDUINOJSON_NAMESPACE::JsonInteger; | ||||
| using ARDUINOJSON_NAMESPACE::JsonObject; | ||||
| using ARDUINOJSON_NAMESPACE::JsonUInt; | ||||
| using ARDUINOJSON_NAMESPACE::JsonVariant; | ||||
| using ARDUINOJSON_NAMESPACE::serialized; | ||||
| using ARDUINOJSON_NAMESPACE::StaticJsonDocument; | ||||
| }  // namespace ArduinoJson | ||||
|   | ||||
| @@ -4,6 +4,18 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #if defined(_MSC_VER) | ||||
| #define ARDUINOJSON_HAS_INT64 1 | ||||
| #else | ||||
| #define ARDUINOJSON_HAS_INT64 0 | ||||
| #endif | ||||
|  | ||||
| #if __cplusplus >= 201103L | ||||
| #define ARDUINOJSON_HAS_LONG_LONG 1 | ||||
| #else | ||||
| #define ARDUINOJSON_HAS_LONG_LONG 0 | ||||
| #endif | ||||
|  | ||||
| // Small or big machine? | ||||
| #ifndef ARDUINOJSON_EMBEDDED_MODE | ||||
| #if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \ | ||||
| @@ -25,9 +37,6 @@ | ||||
| #ifndef ARDUINOJSON_USE_LONG_LONG | ||||
| #define ARDUINOJSON_USE_LONG_LONG 0 | ||||
| #endif | ||||
| #ifndef ARDUINOJSON_USE_INT64 | ||||
| #define ARDUINOJSON_USE_INT64 0 | ||||
| #endif | ||||
|  | ||||
| // Embedded systems usually don't have std::string | ||||
| #ifndef ARDUINOJSON_ENABLE_STD_STRING | ||||
| @@ -53,22 +62,13 @@ | ||||
|  | ||||
| // Use long long when available | ||||
| #ifndef ARDUINOJSON_USE_LONG_LONG | ||||
| #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) | ||||
| #if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 | ||||
| #define ARDUINOJSON_USE_LONG_LONG 1 | ||||
| #else | ||||
| #define ARDUINOJSON_USE_LONG_LONG 0 | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| // Use _int64 on old versions of Visual Studio | ||||
| #ifndef ARDUINOJSON_USE_INT64 | ||||
| #if defined(_MSC_VER) && _MSC_VER <= 1700 | ||||
| #define ARDUINOJSON_USE_INT64 1 | ||||
| #else | ||||
| #define ARDUINOJSON_USE_INT64 0 | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| // On a computer, we can use std::string | ||||
| #ifndef ARDUINOJSON_ENABLE_STD_STRING | ||||
| #define ARDUINOJSON_ENABLE_STD_STRING 1 | ||||
| @@ -141,10 +141,6 @@ | ||||
| #define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 | ||||
| #endif | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 | ||||
| #error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together | ||||
| #endif | ||||
|  | ||||
| #ifndef ARDUINOJSON_LITTLE_ENDIAN | ||||
| #if defined(_MSC_VER) ||                                                      \ | ||||
|     (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ | ||||
|   | ||||
| @@ -6,12 +6,10 @@ | ||||
|  | ||||
| #include "../Polyfills/type_traits.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class JsonVariantTag {}; | ||||
|  | ||||
| template <typename T> | ||||
| struct IsVariant : is_base_of<JsonVariantTag, T> {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,13 +6,11 @@ | ||||
|  | ||||
| #include "../Configuration.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| #if ARDUINOJSON_USE_DOUBLE | ||||
| typedef double JsonFloat; | ||||
| #else | ||||
| typedef float JsonFloat; | ||||
| #endif | ||||
| } | ||||
| } | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,18 +6,13 @@ | ||||
|  | ||||
| #include "../Configuration.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
| typedef long long JsonInteger; | ||||
| typedef unsigned long long JsonUInt; | ||||
| #elif ARDUINOJSON_USE_INT64 | ||||
| typedef __int64 JsonInteger; | ||||
| typedef unsigned _int64 JsonUInt; | ||||
| typedef int64_t JsonInteger; | ||||
| typedef uint64_t JsonUInt; | ||||
| #else | ||||
| typedef long JsonInteger; | ||||
| typedef unsigned long JsonUInt; | ||||
| #endif | ||||
| } | ||||
| } | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A metafunction that returns the type of the value returned by | ||||
| // JsonVariant::as<T>() | ||||
| @@ -19,5 +18,4 @@ struct JsonVariantAs<char*> { | ||||
|   typedef const char* type; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
| #include "JsonFloat.hpp" | ||||
| #include "JsonInteger.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| struct JsonObjectData { | ||||
|   struct Slot* head; | ||||
|   struct Slot* tail; | ||||
| @@ -40,5 +39,4 @@ union JsonVariantContent { | ||||
|   } asRaw; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "JsonVariantContent.hpp" | ||||
| #include "JsonVariantType.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // this struct must be a POD type to prevent error calling offsetof on clang | ||||
| struct JsonVariantData { | ||||
| @@ -31,5 +30,4 @@ inline JsonVariantData *getVariantData(JsonObjectData *obj) { | ||||
|   return reinterpret_cast<JsonVariantData *>(reinterpret_cast<char *>(obj) - | ||||
|                                              offset); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,13 +4,11 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class JsonArray; | ||||
| class JsonObject; | ||||
| class JsonVariant; | ||||
|  | ||||
| namespace Internals { | ||||
|  | ||||
| // A metafunction that returns the type of the value returned by | ||||
| // JsonVariant::to<T>() | ||||
| template <typename T> | ||||
| @@ -29,5 +27,4 @@ struct JsonVariantTo<JsonVariant> { | ||||
|   typedef JsonVariant type; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,10 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
|  | ||||
| namespace Internals { | ||||
|  | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| // Enumerated type to know the current type of a JsonVariant. | ||||
| // The value determines which member of JsonVariantContent is used. | ||||
| enum JsonVariantType { | ||||
| @@ -23,5 +20,4 @@ enum JsonVariantType { | ||||
|   JSON_OBJECT, | ||||
|   JSON_FLOAT | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "../Memory/AllocableInMemoryPool.hpp" | ||||
| #include "JsonVariantData.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| struct Slot : AllocableInMemoryPool { | ||||
|   JsonVariantData value; | ||||
| @@ -17,5 +16,4 @@ struct Slot : AllocableInMemoryPool { | ||||
|   const char* key; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
|  | ||||
| #include <Stream.h> | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| struct ArduinoStreamReader { | ||||
|   Stream& _stream; | ||||
| @@ -35,7 +34,6 @@ struct ArduinoStreamReader { | ||||
| inline ArduinoStreamReader makeReader(Stream& input) { | ||||
|   return ArduinoStreamReader(input); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TChar> | ||||
| class UnsafeCharPointerReader { | ||||
| @@ -60,5 +59,4 @@ inline SafeCharPointerReader<char> makeReader(const String& input) { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
| #include <ostream> | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class DeserializationError { | ||||
|  public: | ||||
| @@ -80,4 +80,4 @@ inline std::ostream& operator<<(std::ostream& s, DeserializationError::Code c) { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #if ARDUINOJSON_ENABLE_PROGMEM | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class UnsafeFlashStringReader { | ||||
|   const char* _ptr; | ||||
|  | ||||
| @@ -50,7 +49,6 @@ inline SafeFlashStringReader makeReader(const __FlashStringHelper* input, | ||||
|                                         size_t size) { | ||||
|   return SafeFlashStringReader(input, size); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TIterator> | ||||
| class IteratorReader { | ||||
| @@ -30,5 +29,4 @@ inline IteratorReader<typename TInput::const_iterator> makeReader( | ||||
|   return IteratorReader<typename TInput::const_iterator>(input.begin(), | ||||
|                                                          input.end()); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
|  | ||||
| #include <istream> | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class StdStreamReader { | ||||
|   std::istream& _stream; | ||||
| @@ -34,7 +33,6 @@ class StdStreamReader { | ||||
| inline StdStreamReader makeReader(std::istream& input) { | ||||
|   return StdStreamReader(input); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -12,8 +12,7 @@ | ||||
| #include "./IteratorReader.hpp" | ||||
| #include "./StdStreamReader.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <template <typename, typename> class TDeserializer, | ||||
|           typename TMemoryPool, typename TReader, typename TWriter> | ||||
| @@ -29,10 +28,8 @@ TDeserializer<TReader, TWriter> makeDeserializer(TMemoryPool &memoryPool, | ||||
| // TString = const std::string&, const String& | ||||
| template <template <typename, typename> class TDeserializer, typename TDocument, | ||||
|           typename TString> | ||||
| typename Internals::enable_if<!Internals::is_array<TString>::value, | ||||
|                               DeserializationError>::type | ||||
| typename enable_if<!is_array<TString>::value, DeserializationError>::type | ||||
| deserialize(TDocument &doc, const TString &input) { | ||||
|   using namespace Internals; | ||||
|   return makeDeserializer<TDeserializer>( | ||||
|              doc.memoryPool(), makeReader(input), | ||||
|              makeStringStorage(doc.memoryPool(), input), doc.nestingLimit) | ||||
| @@ -45,7 +42,6 @@ deserialize(TDocument &doc, const TString &input) { | ||||
| template <template <typename, typename> class TDeserializer, typename TDocument, | ||||
|           typename TChar> | ||||
| DeserializationError deserialize(TDocument &doc, TChar *input) { | ||||
|   using namespace Internals; | ||||
|   return makeDeserializer<TDeserializer>( | ||||
|              doc.memoryPool(), makeReader(input), | ||||
|              makeStringStorage(doc.memoryPool(), input), doc.nestingLimit) | ||||
| @@ -60,7 +56,6 @@ template <template <typename, typename> class TDeserializer, typename TDocument, | ||||
|           typename TChar> | ||||
| DeserializationError deserialize(TDocument &doc, TChar *input, | ||||
|                                  size_t inputSize) { | ||||
|   using namespace Internals; | ||||
|   return makeDeserializer<TDeserializer>( | ||||
|              doc.memoryPool(), makeReader(input, inputSize), | ||||
|              makeStringStorage(doc.memoryPool(), input), doc.nestingLimit) | ||||
| @@ -73,11 +68,9 @@ DeserializationError deserialize(TDocument &doc, TChar *input, | ||||
| template <template <typename, typename> class TDeserializer, typename TDocument, | ||||
|           typename TStream> | ||||
| DeserializationError deserialize(TDocument &doc, TStream &input) { | ||||
|   using namespace Internals; | ||||
|   return makeDeserializer<TDeserializer>( | ||||
|              doc.memoryPool(), makeReader(input), | ||||
|              makeStringStorage(doc.memoryPool(), input), doc.nestingLimit) | ||||
|       .parse(doc.template to<JsonVariant>()); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
| #include "JsonVariant.hpp" | ||||
| #include "Memory/DynamicMemoryPool.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class DynamicJsonDocument { | ||||
|  public: | ||||
| @@ -25,19 +25,19 @@ class DynamicJsonDocument { | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   typename Internals::JsonVariantAs<T>::type as() const { | ||||
|   typename JsonVariantAs<T>::type as() const { | ||||
|     return getVariant().as<T>(); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   typename Internals::JsonVariantTo<T>::type to() { | ||||
|   typename JsonVariantTo<T>::type to() { | ||||
|     _memoryPool.clear(); | ||||
|     return getVariant().to<T>(); | ||||
|   } | ||||
|  | ||||
|   void clear() { | ||||
|     _memoryPool.clear(); | ||||
|     _rootData.type = Internals::JSON_NULL; | ||||
|     _rootData.type = JSON_NULL; | ||||
|   } | ||||
|  | ||||
|   size_t memoryUsage() const { | ||||
| @@ -49,7 +49,7 @@ class DynamicJsonDocument { | ||||
|     return getVariant().accept(visitor); | ||||
|   } | ||||
|  | ||||
|   Internals::DynamicMemoryPool& memoryPool() { | ||||
|   DynamicMemoryPool& memoryPool() { | ||||
|     return _memoryPool; | ||||
|   } | ||||
|  | ||||
| @@ -58,7 +58,7 @@ class DynamicJsonDocument { | ||||
|     return JsonVariant(&_memoryPool, &_rootData); | ||||
|   } | ||||
|  | ||||
|   mutable Internals::DynamicMemoryPool _memoryPool; | ||||
|   mutable Internals::JsonVariantData _rootData; | ||||
|   mutable DynamicMemoryPool _memoryPool; | ||||
|   mutable JsonVariantData _rootData; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class EscapeSequence { | ||||
|  public: | ||||
| @@ -33,5 +32,4 @@ class EscapeSequence { | ||||
|     return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // Decorator on top of Print to allow indented output. | ||||
| // This class is used by serializeJsonPretty() but can also be used | ||||
| @@ -67,5 +66,4 @@ class IndentedPrint { | ||||
|   static const int MAX_LEVEL = 15;    // because it's only 4 bits | ||||
|   static const int MAX_TAB_SIZE = 7;  // because it's only 3 bits | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -12,8 +12,7 @@ | ||||
| #include "../Polyfills/type_traits.hpp" | ||||
| #include "./EscapeSequence.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TReader, typename TStringStorage> | ||||
| class JsonDeserializer { | ||||
| @@ -339,31 +338,26 @@ class JsonDeserializer { | ||||
|   uint8_t _nestingLimit; | ||||
|   char _current; | ||||
|   bool _loaded; | ||||
| };  // namespace Internals | ||||
| }  // namespace Internals | ||||
| }; | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeJson(TDocument &doc, const TInput &input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<JsonDeserializer>(doc, input); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeJson(TDocument &doc, TInput *input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<JsonDeserializer>(doc, input); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeJson(TDocument &doc, TInput *input, | ||||
|                                      size_t inputSize) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<JsonDeserializer>(doc, input, inputSize); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeJson(TDocument &doc, TInput &input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<JsonDeserializer>(doc, input); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
| #include "../Serialization/serialize.hpp" | ||||
| #include "./JsonWriter.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TWriter> | ||||
| class JsonSerializer { | ||||
| @@ -88,23 +87,18 @@ class JsonSerializer { | ||||
|   JsonWriter<TWriter> _writer; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
|  | ||||
| template <typename TSource, typename TDestination> | ||||
| size_t serializeJson(const TSource &source, TDestination &destination) { | ||||
|   using namespace Internals; | ||||
|   return serialize<JsonSerializer>(source, destination); | ||||
| } | ||||
|  | ||||
| template <typename TSource> | ||||
| size_t serializeJson(const TSource &source, char *buffer, size_t bufferSize) { | ||||
|   using namespace Internals; | ||||
|   return serialize<JsonSerializer>(source, buffer, bufferSize); | ||||
| } | ||||
|  | ||||
| template <typename TSource> | ||||
| size_t measureJson(const TSource &source) { | ||||
|   using namespace Internals; | ||||
|   return measure<JsonSerializer>(source); | ||||
| } | ||||
|  | ||||
| @@ -122,7 +116,6 @@ inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) { | ||||
|   return os; | ||||
| } | ||||
|  | ||||
| namespace Internals { | ||||
| inline std::ostream &operator<<(std::ostream &os, | ||||
|                                 const JsonArraySubscript &source) { | ||||
|   serializeJson(source, os); | ||||
| @@ -135,8 +128,6 @@ inline std::ostream &operator<<(std::ostream &os, | ||||
|   serializeJson(source, os); | ||||
|   return os; | ||||
| } | ||||
| }  // namespace Internals | ||||
|  | ||||
| #endif | ||||
|  | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -11,8 +11,7 @@ | ||||
| #include "../Polyfills/attributes.hpp" | ||||
| #include "./EscapeSequence.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TWriter> | ||||
| class JsonWriter { | ||||
| @@ -154,5 +153,4 @@ class JsonWriter { | ||||
|  private: | ||||
|   JsonWriter &operator=(const JsonWriter &);  // cannot be assigned | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -10,8 +10,7 @@ | ||||
| #include "./JsonSerializer.hpp" | ||||
| #include "./Prettyfier.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TPrint> | ||||
| class PrettyJsonSerializer_Base { | ||||
| @@ -33,25 +32,21 @@ class PrettyJsonSerializer : PrettyJsonSerializer_Base<TPrint>, | ||||
|         JsonSerializer<Prettyfier<TPrint> >( | ||||
|             PrettyJsonSerializer_Base<TPrint>::_prettyfier) {} | ||||
| }; | ||||
| }  // namespace Internals | ||||
|  | ||||
| template <typename TSource, typename TDestination> | ||||
| size_t serializeJsonPretty(TSource &source, TDestination &destination) { | ||||
|   using namespace Internals; | ||||
|   return serialize<PrettyJsonSerializer>(source, destination); | ||||
| } | ||||
|  | ||||
| template <typename TSource> | ||||
| size_t serializeJsonPretty(const TSource &source, char *buffer, | ||||
|                            size_t bufferSize) { | ||||
|   using namespace Internals; | ||||
|   return serialize<PrettyJsonSerializer>(source, buffer, bufferSize); | ||||
| } | ||||
|  | ||||
| template <typename TSource> | ||||
| size_t measureJsonPretty(const TSource &source) { | ||||
|   using namespace Internals; | ||||
|   return measure<PrettyJsonSerializer>(source); | ||||
| } | ||||
|  | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "IndentedPrint.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // Converts a compact JSON string into an indented one. | ||||
| template <typename TWriter> | ||||
| @@ -141,5 +140,4 @@ class Prettyfier { | ||||
|   IndentedPrint<TWriter>& _sink; | ||||
|   bool _inString; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -10,14 +10,12 @@ | ||||
| // Returns the size (in bytes) of an array with n elements. | ||||
| // Can be very handy to determine the size of a StaticMemoryPool. | ||||
| #define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ | ||||
|   ((NUMBER_OF_ELEMENTS) * sizeof(ArduinoJson::Internals::Slot)) | ||||
|   ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::Slot)) | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class JsonObject; | ||||
| namespace Internals { | ||||
| class JsonArraySubscript; | ||||
| } | ||||
|  | ||||
| class JsonArray { | ||||
|   friend class JsonVariant; | ||||
| @@ -26,12 +24,10 @@ class JsonArray { | ||||
|   typedef JsonArrayIterator iterator; | ||||
|  | ||||
|   FORCE_INLINE JsonArray() : _memoryPool(0), _data(0) {} | ||||
|   FORCE_INLINE JsonArray(Internals::MemoryPool* pool, | ||||
|                          Internals::JsonArrayData* arr) | ||||
|   FORCE_INLINE JsonArray(MemoryPool* pool, JsonArrayData* arr) | ||||
|       : _memoryPool(pool), _data(arr) {} | ||||
|  | ||||
|   operator JsonVariant() { | ||||
|     using namespace Internals; | ||||
|     return JsonVariant(_memoryPool, getVariantData(_data)); | ||||
|   } | ||||
|  | ||||
| @@ -59,7 +55,7 @@ class JsonArray { | ||||
|   JsonVariant add() { | ||||
|     if (!_data) return JsonVariant(); | ||||
|  | ||||
|     Internals::Slot* slot = new (_memoryPool) Internals::Slot(); | ||||
|     Slot* slot = new (_memoryPool) Slot(); | ||||
|     if (!slot) return JsonVariant(); | ||||
|  | ||||
|     slot->next = 0; | ||||
| @@ -151,10 +147,9 @@ class JsonArray { | ||||
|   FORCE_INLINE JsonArray createNestedArray(); | ||||
|   FORCE_INLINE JsonObject createNestedObject(); | ||||
|  | ||||
|   FORCE_INLINE Internals::JsonArraySubscript operator[](size_t index); | ||||
|   FORCE_INLINE JsonArraySubscript operator[](size_t index); | ||||
|  | ||||
|   FORCE_INLINE const Internals::JsonArraySubscript operator[]( | ||||
|       size_t index) const; | ||||
|   FORCE_INLINE const JsonArraySubscript operator[](size_t index) const; | ||||
|  | ||||
|   FORCE_INLINE bool operator==(JsonArray rhs) const { | ||||
|     iterator it1 = begin(); | ||||
| @@ -171,8 +166,7 @@ class JsonArray { | ||||
|  | ||||
|   // Gets the value at the specified index. | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<T>::type get( | ||||
|       size_t index) const { | ||||
|   FORCE_INLINE typename JsonVariantAs<T>::type get(size_t index) const { | ||||
|     iterator it = begin() += index; | ||||
|     return it != end() ? it->as<T>() : T(); | ||||
|   } | ||||
| @@ -188,7 +182,7 @@ class JsonArray { | ||||
|   FORCE_INLINE void remove(iterator it) { | ||||
|     if (!_data) return; | ||||
|  | ||||
|     Internals::Slot* slot = it.internal(); | ||||
|     Slot* slot = it.internal(); | ||||
|     if (!slot) return; | ||||
|  | ||||
|     if (slot->prev) | ||||
| @@ -235,7 +229,7 @@ class JsonArray { | ||||
|  | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     if (!_data) return 0; | ||||
|     Internals::Slot* slot = _data->head; | ||||
|     Slot* slot = _data->head; | ||||
|     size_t n = 0; | ||||
|     while (slot) { | ||||
|       slot = slot->next; | ||||
| @@ -269,7 +263,7 @@ class JsonArray { | ||||
|     return add().set(value); | ||||
|   } | ||||
|  | ||||
|   Internals::MemoryPool* _memoryPool; | ||||
|   Internals::JsonArrayData* _data; | ||||
|   MemoryPool* _memoryPool; | ||||
|   JsonArrayData* _data; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
| #include "JsonArray.hpp" | ||||
| #include "JsonObject.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline JsonArray JsonArray::createNestedArray() { | ||||
|   return add().to<JsonArray>(); | ||||
| @@ -16,4 +16,4 @@ inline JsonArray JsonArray::createNestedArray() { | ||||
| inline JsonObject JsonArray::createNestedObject() { | ||||
|   return add().to<JsonObject>(); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,12 +7,11 @@ | ||||
| #include "Data/Slot.hpp" | ||||
| #include "JsonVariant.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class JsonVariantPtr { | ||||
|  public: | ||||
|   JsonVariantPtr(Internals::MemoryPool *memoryPool, | ||||
|                  Internals::JsonVariantData *data) | ||||
|   JsonVariantPtr(MemoryPool *memoryPool, JsonVariantData *data) | ||||
|       : _variant(memoryPool, data) {} | ||||
|  | ||||
|   JsonVariant *operator->() { | ||||
| @@ -30,8 +29,7 @@ class JsonVariantPtr { | ||||
| class JsonArrayIterator { | ||||
|  public: | ||||
|   JsonArrayIterator() : _slot(0) {} | ||||
|   explicit JsonArrayIterator(Internals::MemoryPool *memoryPool, | ||||
|                              Internals::Slot *iterator) | ||||
|   explicit JsonArrayIterator(MemoryPool *memoryPool, Slot *iterator) | ||||
|       : _memoryPool(memoryPool), _slot(iterator) {} | ||||
|  | ||||
|   JsonVariant operator*() const { | ||||
| @@ -62,12 +60,12 @@ class JsonArrayIterator { | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   Internals::Slot *internal() { | ||||
|   Slot *internal() { | ||||
|     return _slot; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Internals::MemoryPool *_memoryPool; | ||||
|   Internals::Slot *_slot; | ||||
|   MemoryPool *_memoryPool; | ||||
|   Slot *_slot; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -12,8 +12,7 @@ | ||||
| #pragma warning(disable : 4522) | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> { | ||||
|  public: | ||||
|   FORCE_INLINE JsonArraySubscript(JsonArray array, size_t index) | ||||
| @@ -100,17 +99,15 @@ inline const JsonArraySubscript JsonVariantSubscripts<TImpl>::operator[]( | ||||
|     size_t index) const { | ||||
|   return impl()->template as<JsonArray>()[index]; | ||||
| } | ||||
| }  // namespace Internals | ||||
|  | ||||
| inline Internals::JsonArraySubscript JsonArray::operator[](size_t index) { | ||||
|   return Internals::JsonArraySubscript(*this, index); | ||||
| inline JsonArraySubscript JsonArray::operator[](size_t index) { | ||||
|   return JsonArraySubscript(*this, index); | ||||
| } | ||||
|  | ||||
| inline const Internals::JsonArraySubscript JsonArray::operator[]( | ||||
|     size_t index) const { | ||||
|   return Internals::JsonArraySubscript(*this, index); | ||||
| inline const JsonArraySubscript JsonArray::operator[](size_t index) const { | ||||
|   return JsonArraySubscript(*this, index); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #ifdef _MSC_VER | ||||
| #pragma warning(pop) | ||||
|   | ||||
| @@ -9,9 +9,9 @@ | ||||
| // Returns the size (in bytes) of an object with n elements. | ||||
| // Can be very handy to determine the size of a StaticMemoryPool. | ||||
| #define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \ | ||||
|   ((NUMBER_OF_ELEMENTS) * sizeof(ArduinoJson::Internals::Slot)) | ||||
|   ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::Slot)) | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class JsonObject { | ||||
|   friend class JsonVariant; | ||||
| @@ -20,12 +20,10 @@ class JsonObject { | ||||
|   typedef JsonObjectIterator iterator; | ||||
|  | ||||
|   FORCE_INLINE JsonObject() : _memoryPool(0), _data(0) {} | ||||
|   FORCE_INLINE JsonObject(Internals::MemoryPool* buf, | ||||
|                           Internals::JsonObjectData* object) | ||||
|   FORCE_INLINE JsonObject(MemoryPool* buf, JsonObjectData* object) | ||||
|       : _memoryPool(buf), _data(object) {} | ||||
|  | ||||
|   operator JsonVariant() { | ||||
|     using namespace Internals; | ||||
|     return JsonVariant(_memoryPool, getVariantData(_data)); | ||||
|   } | ||||
|  | ||||
| @@ -103,7 +101,7 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get( | ||||
|   FORCE_INLINE typename JsonVariantAs<TValue>::type get( | ||||
|       const TString& key) const { | ||||
|     return get_impl<const TString&, TValue>(key); | ||||
|   } | ||||
| @@ -113,8 +111,7 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get( | ||||
|       TString* key) const { | ||||
|   FORCE_INLINE typename JsonVariantAs<TValue>::type get(TString* key) const { | ||||
|     return get_impl<TString*, TValue>(key); | ||||
|   } | ||||
|  | ||||
| @@ -144,17 +141,16 @@ class JsonObject { | ||||
|   // JsonObjectSubscript operator[](TKey) | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|   FORCE_INLINE JsonObjectSubscript<const TString&> operator[]( | ||||
|       const TString& key) { | ||||
|     return Internals::JsonObjectSubscript<const TString&>(*this, key); | ||||
|     return JsonObjectSubscript<const TString&>(*this, key); | ||||
|   } | ||||
|   // | ||||
|   // JsonObjectSubscript operator[](TKey) | ||||
|   // TKey = char*, const char*, char[], const char[N], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE Internals::JsonObjectSubscript<TString*> operator[]( | ||||
|       TString* key) { | ||||
|     return Internals::JsonObjectSubscript<TString*>(*this, key); | ||||
|   FORCE_INLINE JsonObjectSubscript<TString*> operator[](TString* key) { | ||||
|     return JsonObjectSubscript<TString*>(*this, key); | ||||
|   } | ||||
|  | ||||
|   // Gets the value associated with the specified key. | ||||
| @@ -162,17 +158,17 @@ class JsonObject { | ||||
|   // const JsonObjectSubscript operator[](TKey) const; | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE const Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|   FORCE_INLINE const JsonObjectSubscript<const TString&> operator[]( | ||||
|       const TString& key) const { | ||||
|     return Internals::JsonObjectSubscript<const TString&>(*this, key); | ||||
|     return JsonObjectSubscript<const TString&>(*this, key); | ||||
|   } | ||||
|   // | ||||
|   // const JsonObjectSubscript operator[](TKey) const; | ||||
|   // TKey = const char*, const char[N], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE const Internals::JsonObjectSubscript<TString*> operator[]( | ||||
|   FORCE_INLINE const JsonObjectSubscript<TString*> operator[]( | ||||
|       TString* key) const { | ||||
|     return Internals::JsonObjectSubscript<TString*>(*this, key); | ||||
|     return JsonObjectSubscript<TString*>(*this, key); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool operator==(JsonObject rhs) const { | ||||
| @@ -185,7 +181,7 @@ class JsonObject { | ||||
|  | ||||
|   FORCE_INLINE void remove(iterator it) { | ||||
|     if (!_data) return; | ||||
|     Internals::Slot* slot = it.internal(); | ||||
|     Slot* slot = it.internal(); | ||||
|     if (!slot) return; | ||||
|     if (slot->prev) | ||||
|       slot->prev->next = slot->next; | ||||
| @@ -262,7 +258,7 @@ class JsonObject { | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     if (!_data) return 0; | ||||
|     size_t n = 0; | ||||
|     Internals::Slot* slot = _data->head; | ||||
|     Slot* slot = _data->head; | ||||
|     while (slot) { | ||||
|       n++; | ||||
|       slot = slot->next; | ||||
| @@ -296,38 +292,38 @@ class JsonObject { | ||||
|  | ||||
|   // Returns the list node that matches the specified key. | ||||
|   template <typename TStringRef> | ||||
|   Internals::Slot* findSlot(TStringRef key) { | ||||
|   Slot* findSlot(TStringRef key) { | ||||
|     if (!_data) return 0; | ||||
|     Internals::Slot* slot = _data->head; | ||||
|     Slot* slot = _data->head; | ||||
|     while (slot) { | ||||
|       if (Internals::makeString(key).equals(slot->key)) break; | ||||
|       if (makeString(key).equals(slot->key)) break; | ||||
|       slot = slot->next; | ||||
|     } | ||||
|     return slot; | ||||
|   } | ||||
|   template <typename TStringRef> | ||||
|   FORCE_INLINE Internals::Slot* findSlot(TStringRef key) const { | ||||
|   FORCE_INLINE Slot* findSlot(TStringRef key) const { | ||||
|     return const_cast<JsonObject*>(this)->findSlot<TStringRef>(key); | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef, typename TValue> | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get_impl( | ||||
|   FORCE_INLINE typename JsonVariantAs<TValue>::type get_impl( | ||||
|       TStringRef key) const { | ||||
|     Internals::Slot* slot = findSlot<TStringRef>(key); | ||||
|     Slot* slot = findSlot<TStringRef>(key); | ||||
|     return slot ? JsonVariant(_memoryPool, &slot->value).as<TValue>() | ||||
|                 : TValue(); | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef, typename TValue> | ||||
|   FORCE_INLINE bool is_impl(TStringRef key) const { | ||||
|     Internals::Slot* slot = findSlot<TStringRef>(key); | ||||
|     Slot* slot = findSlot<TStringRef>(key); | ||||
|     return slot ? JsonVariant(_memoryPool, &slot->value).is<TValue>() : false; | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef> | ||||
|   FORCE_INLINE void remove_impl(TStringRef key) { | ||||
|     if (!_data) return; | ||||
|     Internals::Slot* slot = findSlot<TStringRef>(key); | ||||
|     Slot* slot = findSlot<TStringRef>(key); | ||||
|     if (!slot) return; | ||||
|     if (slot->prev) | ||||
|       slot->prev->next = slot->next; | ||||
| @@ -344,13 +340,13 @@ class JsonObject { | ||||
|     if (!_data) return JsonVariant(); | ||||
|  | ||||
|     // ignore null key | ||||
|     if (Internals::makeString(key).is_null()) return JsonVariant(); | ||||
|     if (makeString(key).is_null()) return JsonVariant(); | ||||
|  | ||||
|     // search a matching key | ||||
|     Internals::Slot* slot = findSlot<TStringRef>(key); | ||||
|     Slot* slot = findSlot<TStringRef>(key); | ||||
|     if (!slot) { | ||||
|       // add the key | ||||
|       slot = new (_memoryPool) Internals::Slot(); | ||||
|       slot = new (_memoryPool) Slot(); | ||||
|       if (!slot) return JsonVariant(); | ||||
|  | ||||
|       slot->next = 0; | ||||
| @@ -371,20 +367,20 @@ class JsonObject { | ||||
|     return JsonVariant(_memoryPool, &slot->value); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool set_key(Internals::Slot* slot, const char* key) { | ||||
|   FORCE_INLINE bool set_key(Slot* slot, const char* key) { | ||||
|     slot->key = key; | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set_key(Internals::Slot* slot, const T& key) { | ||||
|     const char* dup = Internals::makeString(key).save(_memoryPool); | ||||
|   FORCE_INLINE bool set_key(Slot* slot, const T& key) { | ||||
|     const char* dup = makeString(key).save(_memoryPool); | ||||
|     if (!dup) return false; | ||||
|     slot->key = dup; | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   mutable Internals::MemoryPool* _memoryPool; | ||||
|   mutable Internals::JsonObjectData* _data; | ||||
| };  // namespace ArduinoJson | ||||
| }  // namespace ArduinoJson | ||||
|   mutable MemoryPool* _memoryPool; | ||||
|   mutable JsonObjectData* _data; | ||||
| };  // namespace ARDUINOJSON_NAMESPACE | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
| #include "JsonArray.hpp" | ||||
| #include "JsonObject.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TString> | ||||
| inline JsonArray JsonObject::createNestedArray(const TString& key) { | ||||
| @@ -30,4 +30,4 @@ inline JsonObject JsonObject::createNestedObject_impl(TStringRef key) { | ||||
|   if (!_data) return JsonObject(); | ||||
|   return set(key).template to<JsonObject>(); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,12 +6,11 @@ | ||||
|  | ||||
| #include "JsonPair.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class JsonPairPtr { | ||||
|  public: | ||||
|   JsonPairPtr(Internals::MemoryPool *memoryPool, Internals::Slot *slot) | ||||
|       : _pair(memoryPool, slot) {} | ||||
|   JsonPairPtr(MemoryPool *memoryPool, Slot *slot) : _pair(memoryPool, slot) {} | ||||
|  | ||||
|   const JsonPair *operator->() const { | ||||
|     return &_pair; | ||||
| @@ -29,8 +28,7 @@ class JsonObjectIterator { | ||||
|  public: | ||||
|   JsonObjectIterator() : _slot(0) {} | ||||
|  | ||||
|   explicit JsonObjectIterator(Internals::MemoryPool *memoryPool, | ||||
|                               Internals::Slot *slot) | ||||
|   explicit JsonObjectIterator(MemoryPool *memoryPool, Slot *slot) | ||||
|       : _memoryPool(memoryPool), _slot(slot) {} | ||||
|  | ||||
|   JsonPair operator*() const { | ||||
| @@ -61,12 +59,12 @@ class JsonObjectIterator { | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   Internals::Slot *internal() { | ||||
|   Slot *internal() { | ||||
|     return _slot; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Internals::MemoryPool *_memoryPool; | ||||
|   Internals::Slot *_slot; | ||||
|   MemoryPool *_memoryPool; | ||||
|   Slot *_slot; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -13,8 +13,7 @@ | ||||
| #pragma warning(disable : 4522) | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TStringRef> | ||||
| class JsonObjectSubscript | ||||
| @@ -130,8 +129,7 @@ inline typename enable_if<IsString<TString *>::value, | ||||
|   return impl()->template as<JsonObject>()[key]; | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #ifdef _MSC_VER | ||||
| #pragma warning(pop) | ||||
|   | ||||
| @@ -6,12 +6,12 @@ | ||||
|  | ||||
| #include "JsonVariant.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A key value pair for JsonObjectData. | ||||
| class JsonPair { | ||||
|  public: | ||||
|   JsonPair(Internals::MemoryPool* memoryPool, Internals::Slot* slot) { | ||||
|   JsonPair(MemoryPool* memoryPool, Slot* slot) { | ||||
|     if (slot) { | ||||
|       _key = slot->key; | ||||
|       _value = JsonVariant(memoryPool, &slot->value); | ||||
| @@ -32,4 +32,4 @@ class JsonPair { | ||||
|   const char* _key; | ||||
|   JsonVariant _value; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -17,7 +17,7 @@ | ||||
| #include "Serialization/DynamicStringWriter.hpp" | ||||
| #include "SerializedValue.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // Forward declarations. | ||||
| class JsonArray; | ||||
| @@ -30,11 +30,10 @@ class JsonObject; | ||||
| // - a char, short, int or a long (signed or unsigned) | ||||
| // - a string (const char*) | ||||
| // - a reference to a JsonArray or JsonObject | ||||
| class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
| class JsonVariant : public JsonVariantBase<JsonVariant> { | ||||
|  public: | ||||
|   // Intenal use only | ||||
|   FORCE_INLINE JsonVariant(Internals::MemoryPool *memoryPool, | ||||
|                            Internals::JsonVariantData *data) | ||||
|   FORCE_INLINE JsonVariant(MemoryPool *memoryPool, JsonVariantData *data) | ||||
|       : _memoryPool(memoryPool), _data(data) {} | ||||
|  | ||||
|   // Creates an uninitialized JsonVariant | ||||
| @@ -43,8 +42,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(bool value) | ||||
|   FORCE_INLINE bool set(bool value) { | ||||
|     if (!_data) return false; | ||||
|     _data->type = Internals::JSON_BOOLEAN; | ||||
|     _data->content.asInteger = static_cast<Internals::JsonUInt>(value); | ||||
|     _data->type = JSON_BOOLEAN; | ||||
|     _data->content.asInteger = static_cast<JsonUInt>(value); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
| @@ -52,11 +51,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(float value); | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, typename Internals::enable_if< | ||||
|                    Internals::is_floating_point<T>::value>::type * = 0) { | ||||
|       T value, typename enable_if<is_floating_point<T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     _data->type = Internals::JSON_FLOAT; | ||||
|     _data->content.asFloat = static_cast<Internals::JsonFloat>(value); | ||||
|     _data->type = JSON_FLOAT; | ||||
|     _data->content.asFloat = static_cast<JsonFloat>(value); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
| @@ -66,18 +64,16 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(signed long) | ||||
|   // set(signed char) | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, | ||||
|       typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                     Internals::is_signed<T>::value>::type * = | ||||
|           0) { | ||||
|   FORCE_INLINE bool set(T value, | ||||
|                         typename enable_if<is_integral<T>::value && | ||||
|                                            is_signed<T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     if (value >= 0) { | ||||
|       _data->type = Internals::JSON_POSITIVE_INTEGER; | ||||
|       _data->content.asInteger = static_cast<Internals::JsonUInt>(value); | ||||
|       _data->type = JSON_POSITIVE_INTEGER; | ||||
|       _data->content.asInteger = static_cast<JsonUInt>(value); | ||||
|     } else { | ||||
|       _data->type = Internals::JSON_NEGATIVE_INTEGER; | ||||
|       _data->content.asInteger = ~static_cast<Internals::JsonUInt>(value) + 1; | ||||
|       _data->type = JSON_NEGATIVE_INTEGER; | ||||
|       _data->content.asInteger = ~static_cast<JsonUInt>(value) + 1; | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
| @@ -86,21 +82,19 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(unsigned int) | ||||
|   // set(unsigned long) | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, | ||||
|       typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                     Internals::is_unsigned<T>::value>::type * = | ||||
|           0) { | ||||
|   FORCE_INLINE bool set(T value, | ||||
|                         typename enable_if<is_integral<T>::value && | ||||
|                                            is_unsigned<T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     _data->type = Internals::JSON_POSITIVE_INTEGER; | ||||
|     _data->content.asInteger = static_cast<Internals::JsonUInt>(value); | ||||
|     _data->type = JSON_POSITIVE_INTEGER; | ||||
|     _data->content.asInteger = static_cast<JsonUInt>(value); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   // set(SerializedValue<const char *>) | ||||
|   FORCE_INLINE bool set(Internals::SerializedValue<const char *> value) { | ||||
|   FORCE_INLINE bool set(SerializedValue<const char *> value) { | ||||
|     if (!_data) return false; | ||||
|     _data->type = Internals::JSON_LINKED_RAW; | ||||
|     _data->type = JSON_LINKED_RAW; | ||||
|     _data->content.asRaw.data = value.data(); | ||||
|     _data->content.asRaw.size = value.size(); | ||||
|     return true; | ||||
| @@ -111,19 +105,17 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(SerializedValue<const __FlashStringHelper*>) | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       Internals::SerializedValue<T> value, | ||||
|       typename Internals::enable_if< | ||||
|           !Internals::is_same<const char *, T>::value>::type * = 0) { | ||||
|       SerializedValue<T> value, | ||||
|       typename enable_if<!is_same<const char *, T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = | ||||
|         Internals::makeString(value.data(), value.size()).save(_memoryPool); | ||||
|     const char *dup = makeString(value.data(), value.size()).save(_memoryPool); | ||||
|     if (dup) { | ||||
|       _data->type = Internals::JSON_OWNED_RAW; | ||||
|       _data->type = JSON_OWNED_RAW; | ||||
|       _data->content.asRaw.data = dup; | ||||
|       _data->content.asRaw.size = value.size(); | ||||
|       return true; | ||||
|     } else { | ||||
|       _data->type = Internals::JSON_NULL; | ||||
|       _data->type = JSON_NULL; | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
| @@ -131,36 +123,32 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(const std::string&) | ||||
|   // set(const String&) | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       const T &value, | ||||
|       typename Internals::enable_if<Internals::IsString<T>::value>::type * = | ||||
|           0) { | ||||
|   FORCE_INLINE bool set(const T &value, | ||||
|                         typename enable_if<IsString<T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = Internals::makeString(value).save(_memoryPool); | ||||
|     const char *dup = makeString(value).save(_memoryPool); | ||||
|     if (dup) { | ||||
|       _data->type = Internals::JSON_OWNED_STRING; | ||||
|       _data->type = JSON_OWNED_STRING; | ||||
|       _data->content.asString = dup; | ||||
|       return true; | ||||
|     } else { | ||||
|       _data->type = Internals::JSON_NULL; | ||||
|       _data->type = JSON_NULL; | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // set(char*) | ||||
|   template <typename T> | ||||
|   FORCE_INLINE bool set( | ||||
|       T *value, | ||||
|       typename Internals::enable_if<Internals::IsString<T *>::value>::type * = | ||||
|           0) { | ||||
|   FORCE_INLINE bool set(T *value, | ||||
|                         typename enable_if<IsString<T *>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = Internals::makeString(value).save(_memoryPool); | ||||
|     const char *dup = makeString(value).save(_memoryPool); | ||||
|     if (dup) { | ||||
|       _data->type = Internals::JSON_OWNED_STRING; | ||||
|       _data->type = JSON_OWNED_STRING; | ||||
|       _data->content.asString = dup; | ||||
|       return true; | ||||
|     } else { | ||||
|       _data->type = Internals::JSON_NULL; | ||||
|       _data->type = JSON_NULL; | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
| @@ -168,7 +156,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(const char*); | ||||
|   FORCE_INLINE bool set(const char *value) { | ||||
|     if (!_data) return false; | ||||
|     _data->type = Internals::JSON_LINKED_STRING; | ||||
|     _data->type = JSON_LINKED_STRING; | ||||
|     _data->content.asString = value; | ||||
|     return true; | ||||
|   } | ||||
| @@ -176,10 +164,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   bool set(const JsonVariant &value); | ||||
|  | ||||
|   FORCE_INLINE bool set(JsonArray array); | ||||
|   FORCE_INLINE bool set(const Internals::JsonArraySubscript &); | ||||
|   FORCE_INLINE bool set(const JsonArraySubscript &); | ||||
|   FORCE_INLINE bool set(JsonObject object); | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE bool set(const Internals::JsonObjectSubscript<TString> &); | ||||
|   FORCE_INLINE bool set(const JsonObjectSubscript<TString> &); | ||||
|  | ||||
|   // Get the variant as the specified type. | ||||
|   // | ||||
| @@ -193,20 +181,19 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // unsigned int as<unsigned int>() const; | ||||
|   // unsigned long as<unsigned long>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_integral<T>::value, T>::type | ||||
|   as() const { | ||||
|   FORCE_INLINE const typename enable_if<is_integral<T>::value, T>::type as() | ||||
|       const { | ||||
|     if (!_data) return 0; | ||||
|     switch (_data->type) { | ||||
|       case Internals::JSON_POSITIVE_INTEGER: | ||||
|       case Internals::JSON_BOOLEAN: | ||||
|       case JSON_POSITIVE_INTEGER: | ||||
|       case JSON_BOOLEAN: | ||||
|         return T(_data->content.asInteger); | ||||
|       case Internals::JSON_NEGATIVE_INTEGER: | ||||
|       case JSON_NEGATIVE_INTEGER: | ||||
|         return T(~_data->content.asInteger + 1); | ||||
|       case Internals::JSON_LINKED_STRING: | ||||
|       case Internals::JSON_OWNED_STRING: | ||||
|         return Internals::parseInteger<T>(_data->content.asString); | ||||
|       case Internals::JSON_FLOAT: | ||||
|       case JSON_LINKED_STRING: | ||||
|       case JSON_OWNED_STRING: | ||||
|         return parseInteger<T>(_data->content.asString); | ||||
|       case JSON_FLOAT: | ||||
|         return T(_data->content.asFloat); | ||||
|       default: | ||||
|         return 0; | ||||
| @@ -214,29 +201,27 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   } | ||||
|   // bool as<bool>() const | ||||
|   template <typename T> | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_same<T, bool>::value, T>::type | ||||
|   as() const { | ||||
|   FORCE_INLINE const typename enable_if<is_same<T, bool>::value, T>::type as() | ||||
|       const { | ||||
|     return as<int>() != 0; | ||||
|   } | ||||
|   // | ||||
|   // double as<double>() const; | ||||
|   // float as<float>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_floating_point<T>::value, T>::type | ||||
|   FORCE_INLINE const typename enable_if<is_floating_point<T>::value, T>::type | ||||
|   as() const { | ||||
|     if (!_data) return 0; | ||||
|     switch (_data->type) { | ||||
|       case Internals::JSON_POSITIVE_INTEGER: | ||||
|       case Internals::JSON_BOOLEAN: | ||||
|       case JSON_POSITIVE_INTEGER: | ||||
|       case JSON_BOOLEAN: | ||||
|         return static_cast<T>(_data->content.asInteger); | ||||
|       case Internals::JSON_NEGATIVE_INTEGER: | ||||
|       case JSON_NEGATIVE_INTEGER: | ||||
|         return -static_cast<T>(_data->content.asInteger); | ||||
|       case Internals::JSON_LINKED_STRING: | ||||
|       case Internals::JSON_OWNED_STRING: | ||||
|         return Internals::parseFloat<T>(_data->content.asString); | ||||
|       case Internals::JSON_FLOAT: | ||||
|       case JSON_LINKED_STRING: | ||||
|       case JSON_OWNED_STRING: | ||||
|         return parseFloat<T>(_data->content.asString); | ||||
|       case JSON_FLOAT: | ||||
|         return static_cast<T>(_data->content.asFloat); | ||||
|       default: | ||||
|         return 0; | ||||
| @@ -246,14 +231,13 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // const char* as<const char*>() const; | ||||
|   // const char* as<char*>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<T, const char *>::value || | ||||
|           Internals::is_same<T, char *>::value, | ||||
|       const char *>::type | ||||
|   FORCE_INLINE typename enable_if<is_same<T, const char *>::value || | ||||
|                                       is_same<T, char *>::value, | ||||
|                                   const char *>::type | ||||
|   as() const { | ||||
|     if (!_data) return 0; | ||||
|     if (_data && (_data->type == Internals::JSON_LINKED_STRING || | ||||
|                   _data->type == Internals::JSON_OWNED_STRING)) | ||||
|     if (_data && | ||||
|         (_data->type == JSON_LINKED_STRING || _data->type == JSON_OWNED_STRING)) | ||||
|       return _data->content.asString; | ||||
|     else | ||||
|       return 0; | ||||
| @@ -262,10 +246,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // std::string as<std::string>() const; | ||||
|   // String as<String>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::IsWriteableString<T>::value, | ||||
|                                     T>::type | ||||
|       as() const { | ||||
|   FORCE_INLINE typename enable_if<IsWriteableString<T>::value, T>::type as() | ||||
|       const { | ||||
|     const char *cstr = as<const char *>(); | ||||
|     if (cstr) return T(cstr); | ||||
|     T s; | ||||
| @@ -276,27 +258,22 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // JsonArray as<JsonArray>() const; | ||||
|   // const JsonArray as<const JsonArray>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonArray>::value, | ||||
|   FORCE_INLINE typename enable_if< | ||||
|       is_same<typename remove_const<T>::type, JsonArray>::value, | ||||
|       JsonArray>::type | ||||
|   as() const; | ||||
|   // | ||||
|   // JsonObject as<JsonObject>() const; | ||||
|   // const JsonObject as<const JsonObject>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonObject>::value, | ||||
|       T>::type | ||||
|   FORCE_INLINE typename enable_if< | ||||
|       is_same<typename remove_const<T>::type, JsonObject>::value, T>::type | ||||
|   as() const; | ||||
|   // | ||||
|   // JsonVariant as<JsonVariant> const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value, | ||||
|                                     T>::type | ||||
|       as() const { | ||||
|   FORCE_INLINE typename enable_if<is_same<T, JsonVariant>::value, T>::type as() | ||||
|       const { | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
| @@ -313,69 +290,59 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<unsigned int>() const; | ||||
|   // bool is<unsigned long>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if<Internals::is_integral<T>::value, | ||||
|                                              bool>::type | ||||
|   is() const { | ||||
|     return _data && (_data->type == Internals::JSON_POSITIVE_INTEGER || | ||||
|                      _data->type == Internals::JSON_NEGATIVE_INTEGER); | ||||
|   FORCE_INLINE typename enable_if<is_integral<T>::value, bool>::type is() | ||||
|       const { | ||||
|     return _data && (_data->type == JSON_POSITIVE_INTEGER || | ||||
|                      _data->type == JSON_NEGATIVE_INTEGER); | ||||
|   } | ||||
|   // | ||||
|   // bool is<double>() const; | ||||
|   // bool is<float>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::is_floating_point<T>::value, | ||||
|                                     bool>::type | ||||
|       is() const { | ||||
|     return _data && (_data->type == Internals::JSON_FLOAT || | ||||
|                      _data->type == Internals::JSON_POSITIVE_INTEGER || | ||||
|                      _data->type == Internals::JSON_NEGATIVE_INTEGER); | ||||
|   FORCE_INLINE typename enable_if<is_floating_point<T>::value, bool>::type is() | ||||
|       const { | ||||
|     return _data && | ||||
|            (_data->type == JSON_FLOAT || _data->type == JSON_POSITIVE_INTEGER || | ||||
|             _data->type == JSON_NEGATIVE_INTEGER); | ||||
|   } | ||||
|   // | ||||
|   // bool is<bool>() const | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if<Internals::is_same<T, bool>::value, | ||||
|                                              bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->type == Internals::JSON_BOOLEAN; | ||||
|   FORCE_INLINE typename enable_if<is_same<T, bool>::value, bool>::type is() | ||||
|       const { | ||||
|     return _data && _data->type == JSON_BOOLEAN; | ||||
|   } | ||||
|   // | ||||
|   // bool is<const char*>() const; | ||||
|   // bool is<char*>() const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<T, const char *>::value || | ||||
|           Internals::is_same<T, char *>::value, | ||||
|       bool>::type | ||||
|   FORCE_INLINE typename enable_if< | ||||
|       is_same<T, const char *>::value || is_same<T, char *>::value, bool>::type | ||||
|   is() const { | ||||
|     return _data && (_data->type == Internals::JSON_LINKED_STRING || | ||||
|                      _data->type == Internals::JSON_OWNED_STRING); | ||||
|     return _data && (_data->type == JSON_LINKED_STRING || | ||||
|                      _data->type == JSON_OWNED_STRING); | ||||
|   } | ||||
|   // | ||||
|   // bool is<JsonArray> const; | ||||
|   // bool is<const JsonArray> const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonArray>::value, | ||||
|       bool>::type | ||||
|   FORCE_INLINE typename enable_if< | ||||
|       is_same<typename remove_const<T>::type, JsonArray>::value, bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->type == Internals::JSON_ARRAY; | ||||
|     return _data && _data->type == JSON_ARRAY; | ||||
|   } | ||||
|   // | ||||
|   // bool is<JsonObject> const; | ||||
|   // bool is<const JsonObject> const; | ||||
|   template <typename T> | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonObject>::value, | ||||
|       bool>::type | ||||
|   FORCE_INLINE typename enable_if< | ||||
|       is_same<typename remove_const<T>::type, JsonObject>::value, bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->type == Internals::JSON_OBJECT; | ||||
|     return _data && _data->type == JSON_OBJECT; | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return _data == 0 || _data->type == Internals::JSON_NULL; | ||||
|     return _data == 0 || _data->type == JSON_NULL; | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE bool isInvalid() const { | ||||
| @@ -389,35 +356,29 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // | ||||
|   // JsonArray to<JsonArray>() | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, JsonArray>::value, | ||||
|                                 JsonArray>::type | ||||
|   to(); | ||||
|   typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type to(); | ||||
|   // | ||||
|   // JsonObject to<JsonObject>() | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, JsonObject>::value, | ||||
|                                 JsonObject>::type | ||||
|   to(); | ||||
|   typename enable_if<is_same<T, JsonObject>::value, JsonObject>::type to(); | ||||
|   // | ||||
|   // JsonObject to<JsonVariant>() | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value, | ||||
|                                 JsonVariant>::type | ||||
|   to(); | ||||
|   typename enable_if<is_same<T, JsonVariant>::value, JsonVariant>::type to(); | ||||
|  | ||||
|  private: | ||||
|   Internals::MemoryPool *_memoryPool; | ||||
|   Internals::JsonVariantData *_data; | ||||
|   MemoryPool *_memoryPool; | ||||
|   JsonVariantData *_data; | ||||
| }; | ||||
|  | ||||
| class JsonVariantLocal : public JsonVariant { | ||||
|  public: | ||||
|   explicit JsonVariantLocal(Internals::MemoryPool *memoryPool) | ||||
|   explicit JsonVariantLocal(MemoryPool *memoryPool) | ||||
|       : JsonVariant(memoryPool, &_localData) { | ||||
|     _localData.type = Internals::JSON_NULL; | ||||
|     _localData.type = JSON_NULL; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Internals::JsonVariantData _localData; | ||||
|   JsonVariantData _localData; | ||||
| }; | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
| #include "JsonVariantOr.hpp" | ||||
| #include "JsonVariantSubscripts.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TImpl> | ||||
| class JsonVariantBase : public JsonVariantCasts<TImpl>, | ||||
| @@ -18,5 +17,4 @@ class JsonVariantBase : public JsonVariantCasts<TImpl>, | ||||
|                         public JsonVariantOr<TImpl>, | ||||
|                         public JsonVariantSubscripts<TImpl>, | ||||
|                         public JsonVariantTag {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "Data/JsonVariantAs.hpp" | ||||
| #include "Polyfills/attributes.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TImpl> | ||||
| class JsonVariantCasts { | ||||
| @@ -23,5 +22,4 @@ class JsonVariantCasts { | ||||
|     return static_cast<const TImpl *>(this); | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -10,12 +10,10 @@ | ||||
| #include "Polyfills/type_traits.hpp" | ||||
| #include "Strings/StringTypes.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class JsonArray; | ||||
| class JsonObject; | ||||
|  | ||||
| namespace Internals { | ||||
|  | ||||
| template <typename TImpl> | ||||
| class JsonVariantComparisons { | ||||
|  public: | ||||
| @@ -120,7 +118,6 @@ class JsonVariantComparisons { | ||||
|  | ||||
|   template <typename TVariant2> | ||||
|   bool equals(const JsonVariantComparisons<TVariant2> &right) const { | ||||
|     using namespace Internals; | ||||
|     if (is<bool>() && right.template is<bool>()) | ||||
|       return as<bool>() == right.template as<bool>(); | ||||
|     if (is<JsonInteger>() && right.template is<JsonInteger>()) | ||||
| @@ -137,5 +134,4 @@ class JsonVariantComparisons { | ||||
|     return false; | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -11,13 +11,13 @@ | ||||
|  | ||||
| #include <string.h>  // for strcmp | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline bool JsonVariant::set(JsonArray array) { | ||||
|   return to<JsonArray>().copyFrom(array); | ||||
| } | ||||
|  | ||||
| inline bool JsonVariant::set(const Internals::JsonArraySubscript& value) { | ||||
| inline bool JsonVariant::set(const JsonArraySubscript& value) { | ||||
|   return set(value.as<JsonVariant>()); | ||||
| } | ||||
|  | ||||
| @@ -26,25 +26,24 @@ inline bool JsonVariant::set(JsonObject object) { | ||||
| } | ||||
|  | ||||
| template <typename TString> | ||||
| inline bool JsonVariant::set( | ||||
|     const Internals::JsonObjectSubscript<TString>& value) { | ||||
| inline bool JsonVariant::set(const JsonObjectSubscript<TString>& value) { | ||||
|   return set(value.template as<JsonVariant>()); | ||||
| } | ||||
|  | ||||
| inline bool JsonVariant::set(const JsonVariant& value) { | ||||
|   if (!_data) return false; | ||||
|   if (!value._data) { | ||||
|     _data->type = Internals::JSON_NULL; | ||||
|     _data->type = JSON_NULL; | ||||
|     return true; | ||||
|   } | ||||
|   switch (value._data->type) { | ||||
|     case Internals::JSON_ARRAY: | ||||
|     case JSON_ARRAY: | ||||
|       return set(value.as<JsonArray>()); | ||||
|     case Internals::JSON_OBJECT: | ||||
|     case JSON_OBJECT: | ||||
|       return set(value.as<JsonObject>()); | ||||
|     case Internals::JSON_OWNED_STRING: | ||||
|     case JSON_OWNED_STRING: | ||||
|       return set(const_cast<char*>(value._data->content.asString)); | ||||
|     case Internals::JSON_OWNED_RAW: | ||||
|     case JSON_OWNED_RAW: | ||||
|       return set(serialized(const_cast<char*>(value._data->content.asRaw.data), | ||||
|                             value._data->content.asRaw.size)); | ||||
|     default: | ||||
| @@ -54,63 +53,55 @@ inline bool JsonVariant::set(const JsonVariant& value) { | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| inline typename Internals::enable_if< | ||||
|     Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                        JsonArray>::value, | ||||
|     JsonArray>::type | ||||
| inline typename enable_if< | ||||
|     is_same<typename remove_const<T>::type, JsonArray>::value, JsonArray>::type | ||||
| JsonVariant::as() const { | ||||
|   if (_data && _data->type == Internals::JSON_ARRAY) | ||||
|   if (_data && _data->type == JSON_ARRAY) | ||||
|     return JsonArray(_memoryPool, &_data->content.asArray); | ||||
|   else | ||||
|     return JsonArray(); | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| inline typename Internals::enable_if< | ||||
|     Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                        JsonObject>::value, | ||||
|     T>::type | ||||
| inline typename enable_if< | ||||
|     is_same<typename remove_const<T>::type, JsonObject>::value, T>::type | ||||
| JsonVariant::as() const { | ||||
|   if (_data && _data->type == Internals::JSON_OBJECT) | ||||
|   if (_data && _data->type == JSON_OBJECT) | ||||
|     return JsonObject(_memoryPool, &_data->content.asObject); | ||||
|   else | ||||
|     return JsonObject(); | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| inline typename Internals::enable_if<Internals::is_same<T, JsonArray>::value, | ||||
|                                      JsonArray>::type | ||||
| inline typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type | ||||
| JsonVariant::to() { | ||||
|   if (!_data) return JsonArray(); | ||||
|   _data->type = Internals::JSON_ARRAY; | ||||
|   _data->type = JSON_ARRAY; | ||||
|   _data->content.asArray.head = 0; | ||||
|   _data->content.asArray.tail = 0; | ||||
|   return JsonArray(_memoryPool, &_data->content.asArray); | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| typename Internals::enable_if<Internals::is_same<T, JsonObject>::value, | ||||
|                               JsonObject>::type | ||||
| typename enable_if<is_same<T, JsonObject>::value, JsonObject>::type | ||||
| JsonVariant::to() { | ||||
|   if (!_data) return JsonObject(); | ||||
|   _data->type = Internals::JSON_OBJECT; | ||||
|   _data->type = JSON_OBJECT; | ||||
|   _data->content.asObject.head = 0; | ||||
|   _data->content.asObject.tail = 0; | ||||
|   return JsonObject(_memoryPool, &_data->content.asObject); | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value, | ||||
|                               JsonVariant>::type | ||||
| typename enable_if<is_same<T, JsonVariant>::value, JsonVariant>::type | ||||
| JsonVariant::to() { | ||||
|   if (!_data) return JsonVariant(); | ||||
|   _data->type = Internals::JSON_NULL; | ||||
|   _data->type = JSON_NULL; | ||||
|   return *this; | ||||
| } | ||||
|  | ||||
| template <typename Visitor> | ||||
| inline void JsonVariant::accept(Visitor& visitor) const { | ||||
|   using namespace Internals; | ||||
|   if (!_data) return visitor.visitNull(); | ||||
|  | ||||
|   switch (_data->type) { | ||||
| @@ -147,4 +138,4 @@ inline void JsonVariant::accept(Visitor& visitor) const { | ||||
|       return visitor.visitNull(); | ||||
|   } | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
| #include "Polyfills/attributes.hpp" | ||||
| #include "Polyfills/type_traits.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TImpl> | ||||
| class JsonVariantOr { | ||||
| @@ -47,5 +46,4 @@ class JsonVariantOr { | ||||
|     return static_cast<const TImpl *>(this); | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -9,10 +9,9 @@ | ||||
| #include "Polyfills/type_traits.hpp" | ||||
| #include "Strings/StringTypes.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class JsonArray; | ||||
| class JsonObject; | ||||
| namespace Internals { | ||||
|  | ||||
| // Forward declarations. | ||||
| class JsonArraySubscript; | ||||
| @@ -73,5 +72,4 @@ class JsonVariantSubscripts { | ||||
|     return static_cast<const TImpl *>(this); | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "MemoryPool.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class AllocableInMemoryPool { | ||||
|  public: | ||||
| @@ -17,5 +16,4 @@ class AllocableInMemoryPool { | ||||
|  | ||||
|   void operator delete(void *, MemoryPool *)NOEXCEPT {} | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -18,8 +18,7 @@ | ||||
| #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| class DefaultAllocator { | ||||
|  public: | ||||
|   void* allocate(size_t size) { | ||||
| @@ -156,8 +155,7 @@ class DynamicMemoryPoolBase : public MemoryPool { | ||||
| // You are strongly encouraged to consider using StaticMemoryPool which is much | ||||
| // more suitable for embedded systems. | ||||
| typedef DynamicMemoryPoolBase<DefaultAllocator> DynamicMemoryPool; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #if defined(__clang__) | ||||
| #pragma clang diagnostic pop | ||||
|   | ||||
| @@ -11,8 +11,7 @@ | ||||
| #include "../Configuration.hpp" | ||||
| #include "../Polyfills/attributes.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| // Handle the memory management (done in derived classes) and calls the parser. | ||||
| // This abstract class is implemented by StaticMemoryPool which implements a | ||||
| // fixed memory allocation. | ||||
| @@ -38,5 +37,4 @@ class MemoryPool { | ||||
| #endif | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "../Polyfills/mpl/max.hpp" | ||||
| #include "MemoryPool.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class StaticMemoryPoolBase : public MemoryPool { | ||||
|  public: | ||||
| @@ -117,8 +116,7 @@ class StaticMemoryPool : public StaticMemoryPoolBase { | ||||
|  private: | ||||
|   char _buffer[ACTUAL_CAPACITY]; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #if defined(__clang__) | ||||
| #pragma clang diagnostic pop | ||||
|   | ||||
| @@ -11,8 +11,7 @@ | ||||
| #include "./endianess.hpp" | ||||
| #include "./ieee754.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TReader, typename TStringStorage> | ||||
| class MsgPackDeserializer { | ||||
| @@ -69,7 +68,7 @@ class MsgPackDeserializer { | ||||
|         return readInteger<uint32_t>(variant); | ||||
|  | ||||
|       case 0xcf: | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|         return readInteger<uint64_t>(variant); | ||||
| #else | ||||
|         readInteger<uint32_t>(); | ||||
| @@ -86,7 +85,7 @@ class MsgPackDeserializer { | ||||
|         return readInteger<int32_t>(variant); | ||||
|  | ||||
|       case 0xd3: | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|         return readInteger<int64_t>(variant); | ||||
| #else | ||||
|         if (!skip(4)) return DeserializationError::IncompleteInput; | ||||
| @@ -297,30 +296,25 @@ class MsgPackDeserializer { | ||||
|   TStringStorage _stringStorage; | ||||
|   uint8_t _nestingLimit; | ||||
| }; | ||||
| }  // namespace Internals | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeMsgPack(TDocument &doc, const TInput &input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<MsgPackDeserializer>(doc, input); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeMsgPack(TDocument &doc, TInput *input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<MsgPackDeserializer>(doc, input); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeMsgPack(TDocument &doc, TInput *input, | ||||
|                                         size_t inputSize) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<MsgPackDeserializer>(doc, input, inputSize); | ||||
| } | ||||
|  | ||||
| template <typename TDocument, typename TInput> | ||||
| DeserializationError deserializeMsgPack(TDocument &doc, TInput &input) { | ||||
|   using namespace Internals; | ||||
|   return deserialize<MsgPackDeserializer>(doc, input); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -10,8 +10,7 @@ | ||||
| #include "../Serialization/serialize.hpp" | ||||
| #include "./endianess.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TWriter> | ||||
| class MsgPackSerializer { | ||||
| @@ -107,7 +106,7 @@ class MsgPackSerializer { | ||||
|       writeByte(0xD2); | ||||
|       writeInteger(int32_t(negated)); | ||||
|     } | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|     else { | ||||
|       writeByte(0xD3); | ||||
|       writeInteger(int64_t(negated)); | ||||
| @@ -128,7 +127,7 @@ class MsgPackSerializer { | ||||
|       writeByte(0xCE); | ||||
|       writeInteger(uint32_t(value)); | ||||
|     } | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|     else { | ||||
|       writeByte(0xCF); | ||||
|       writeInteger(uint64_t(value)); | ||||
| @@ -166,25 +165,21 @@ class MsgPackSerializer { | ||||
|   TWriter* _writer; | ||||
|   size_t _bytesWritten; | ||||
| }; | ||||
| }  // namespace Internals | ||||
|  | ||||
| template <typename TSource, typename TDestination> | ||||
| inline size_t serializeMsgPack(const TSource& source, TDestination& output) { | ||||
|   using namespace Internals; | ||||
|   return serialize<MsgPackSerializer>(source, output); | ||||
| } | ||||
|  | ||||
| template <typename TSource, typename TDestination> | ||||
| inline size_t serializeMsgPack(const TSource& source, TDestination* output, | ||||
|                                size_t size) { | ||||
|   using namespace Internals; | ||||
|   return serialize<MsgPackSerializer>(source, output, size); | ||||
| } | ||||
|  | ||||
| template <typename TSource> | ||||
| inline size_t measureMsgPack(const TSource& source) { | ||||
|   using namespace Internals; | ||||
|   return measure<MsgPackSerializer>(source); | ||||
| } | ||||
|  | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "../Polyfills/type_traits.hpp" | ||||
| #include "../Polyfills/utility.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline void fixEndianess(uint8_t* p, integral_constant<size_t, 8>) { | ||||
|   swap(p[0], p[7]); | ||||
| @@ -36,5 +35,4 @@ inline void fixEndianess(T& value) { | ||||
| #endif | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline void doubleToFloat(const uint8_t d[8], uint8_t f[4]) { | ||||
|   f[0] = uint8_t((d[0] & 0xC0) | (d[0] << 3 & 0x3f) | (d[1] >> 5)); | ||||
| @@ -14,5 +13,4 @@ inline void doubleToFloat(const uint8_t d[8], uint8_t f[4]) { | ||||
|   f[3] = uint8_t((d[3] << 3) | (d[4] >> 5)); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
							
								
								
									
										22
									
								
								src/ArduinoJson/Namespace.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/ArduinoJson/Namespace.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| // ArduinoJson - arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2018 | ||||
| // MIT License | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "version.hpp" | ||||
|  | ||||
| #include "Configuration.hpp" | ||||
|  | ||||
| #define ARDUINOJSON_DO_CONCAT(A, B) A##B | ||||
| #define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_DO_CONCAT(A, B) | ||||
| #define ARDUINOJSON_CONCAT4(A, B, C, D) \ | ||||
|   ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), ARDUINOJSON_CONCAT2(C, D)) | ||||
| #define ARDUINOJSON_CONCAT8(A, B, C, D, E, F, G, H)    \ | ||||
|   ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT4(A, B, C, D), \ | ||||
|                       ARDUINOJSON_CONCAT4(E, F, G, H)) | ||||
|  | ||||
| #define ARDUINOJSON_NAMESPACE                                                  \ | ||||
|   ARDUINOJSON_CONCAT8(ArduinoJson, ARDUINOJSON_VERSION_MAJOR,                  \ | ||||
|                       ARDUINOJSON_VERSION_MINOR, ARDUINOJSON_VERSION_REVISION, \ | ||||
|                       _, ARDUINOJSON_USE_LONG_LONG, _, ARDUINOJSON_USE_DOUBLE) | ||||
| @@ -8,8 +8,7 @@ | ||||
| #include "../Polyfills/math.hpp" | ||||
| #include "./FloatTraits.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TFloat> | ||||
| struct FloatParts { | ||||
| @@ -85,5 +84,4 @@ struct FloatParts { | ||||
|     return powersOf10; | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
| #include "../Configuration.hpp" | ||||
| #include "../Polyfills/math.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename T, size_t = sizeof(T)> | ||||
| struct FloatTraits {}; | ||||
| @@ -167,5 +166,4 @@ struct FloatTraits<T, 4 /*32bits*/> { | ||||
|     return forge(0x7f800000); | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include <string.h>  // for strcmp | ||||
| #include "../Polyfills/ctype.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline bool isFloat(const char* s) { | ||||
|   if (!s) return false; | ||||
| @@ -34,5 +33,4 @@ inline bool isFloat(const char* s) { | ||||
|  | ||||
|   return *s == '\0'; | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "../Polyfills/ctype.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline bool isInteger(const char* s) { | ||||
|   if (!s || !*s) return false; | ||||
| @@ -15,5 +14,4 @@ inline bool isInteger(const char* s) { | ||||
|   while (isdigit(*s)) s++; | ||||
|   return *s == '\0'; | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
| #include "../Polyfills/ctype.hpp" | ||||
| #include "../Polyfills/math.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename T> | ||||
| inline T parseFloat(const char* s) { | ||||
| @@ -86,5 +85,4 @@ inline T parseFloat(const char* s) { | ||||
|  | ||||
|   return negative_result ? -result : result; | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
| #include "../Configuration.hpp" | ||||
| #include "../Polyfills/ctype.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| template <typename T> | ||||
| T parseInteger(const char *s) { | ||||
|   if (!s) return 0;  // NULL | ||||
| @@ -37,5 +36,4 @@ T parseInteger(const char *s) { | ||||
|  | ||||
|   return negative_result ? T(~result + 1) : result; | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| inline bool isdigit(char c) { | ||||
|   return '0' <= c && c <= '9'; | ||||
| @@ -14,5 +13,4 @@ inline bool isdigit(char c) { | ||||
| inline bool issign(char c) { | ||||
|   return '-' == c || c == '+'; | ||||
| } | ||||
| } | ||||
| } | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // Some libraries #define isnan() and isinf() so we need to check before | ||||
| // using this name | ||||
| @@ -23,5 +22,4 @@ bool isinf(T x) { | ||||
|   return x != 0.0 && x * 2 == x; | ||||
| } | ||||
| #endif | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include <stdlib.h>  // for size_t | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that returns the highest value | ||||
| template <size_t X, size_t Y, bool MaxIsX = (X > Y)> | ||||
| @@ -22,5 +21,4 @@ template <size_t X, size_t Y> | ||||
| struct Max<X, Y, false> { | ||||
|   static const size_t value = Y; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that return the type T if Condition is true. | ||||
| template <bool Condition, typename T = void> | ||||
| @@ -15,5 +14,4 @@ template <typename T> | ||||
| struct enable_if<true, T> { | ||||
|   typedef T type; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename T, T v> | ||||
| struct integral_constant { | ||||
| @@ -15,5 +14,4 @@ struct integral_constant { | ||||
| typedef integral_constant<bool, true> true_type; | ||||
| typedef integral_constant<bool, false> false_type; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename T> | ||||
| struct is_array : false_type {}; | ||||
| @@ -15,5 +14,4 @@ struct is_array<T[]> : true_type {}; | ||||
|  | ||||
| template <typename T, size_t N> | ||||
| struct is_array<T[N]> : true_type {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that returns true if Derived inherits from TBase is an | ||||
| // integral type. | ||||
| @@ -23,5 +22,4 @@ class is_base_of { | ||||
|     value = sizeof(probe(reinterpret_cast<TDerived *>(0))) == sizeof(Yes) | ||||
|   }; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "integral_constant.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that return the type T without the const modifier | ||||
| template <typename T> | ||||
| @@ -15,5 +14,4 @@ struct is_const : false_type {}; | ||||
|  | ||||
| template <typename T> | ||||
| struct is_const<const T> : true_type {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "integral_constant.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename> | ||||
| struct is_floating_point : false_type {}; | ||||
| @@ -17,5 +16,4 @@ struct is_floating_point<float> : true_type {}; | ||||
|  | ||||
| template <> | ||||
| struct is_floating_point<double> : true_type {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "../../Configuration.hpp" | ||||
| #include "is_same.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that returns true if T is an integral type. | ||||
| template <typename T> | ||||
| @@ -18,19 +17,19 @@ struct is_integral { | ||||
|       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 || | ||||
| #if ARDUINOJSON_HAS_LONG_LONG | ||||
|       is_same<T, signed long long>::value || | ||||
|       is_same<T, unsigned long long>::value || | ||||
| #endif | ||||
| #if ARDUINOJSON_USE_INT64 | ||||
|       is_same<T, unsigned __int64>::value || | ||||
| #if ARDUINOJSON_HAS_INT64 | ||||
|       is_same<T, signed __int64>::value || | ||||
|       is_same<T, unsigned __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 | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "integral_constant.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that returns true if types T and U are the same. | ||||
| template <typename T, typename U> | ||||
| @@ -15,5 +14,4 @@ struct is_same : false_type {}; | ||||
|  | ||||
| template <typename T> | ||||
| struct is_same<T, T> : true_type {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "integral_constant.hpp" | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename> | ||||
| struct is_signed : false_type {}; | ||||
| @@ -32,13 +31,13 @@ struct is_signed<float> : true_type {}; | ||||
| template <> | ||||
| struct is_signed<double> : true_type {}; | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
| #if ARDUINOJSON_HAS_LONG_LONG | ||||
| template <> | ||||
| struct is_signed<signed long long> : true_type {}; | ||||
| #endif | ||||
| #if ARDUINOJSON_USE_INT64 | ||||
|  | ||||
| #if ARDUINOJSON_HAS_INT64 | ||||
| template <> | ||||
| struct is_signed<signed __int64> : true_type {}; | ||||
| #endif | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "integral_constant.hpp" | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename> | ||||
| struct is_unsigned : false_type {}; | ||||
| @@ -26,13 +25,13 @@ 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 | ||||
| #if ARDUINOJSON_HAS_INT64 | ||||
| template <> | ||||
| struct is_unsigned<unsigned __int64> : true_type {}; | ||||
| #endif | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
|  | ||||
| #if ARDUINOJSON_HAS_LONG_LONG | ||||
| template <> | ||||
| struct is_unsigned<unsigned long long> : true_type {}; | ||||
| #endif | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that return the type T without the const modifier | ||||
| template <typename T> | ||||
| @@ -16,5 +15,4 @@ template <typename T> | ||||
| struct remove_const<const T> { | ||||
|   typedef T type; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A meta-function that return the type T without the reference modifier. | ||||
| template <typename T> | ||||
| @@ -16,5 +15,4 @@ template <typename T> | ||||
| struct remove_reference<T&> { | ||||
|   typedef T type; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,13 +4,11 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| template <typename T> | ||||
| inline void swap(T& a, T& b) { | ||||
|   T t(a); | ||||
|   a = b; | ||||
|   b = t; | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class DummyWriter { | ||||
|  public: | ||||
| @@ -17,5 +16,4 @@ class DummyWriter { | ||||
|     return n; | ||||
|   } | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -14,8 +14,7 @@ | ||||
| #include <string> | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename> | ||||
| struct IsWriteableString : false_type {}; | ||||
| @@ -77,5 +76,4 @@ class DynamicStringWriter<std::string> { | ||||
|   std::string *_str; | ||||
| }; | ||||
| #endif | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| // A Print implementation that allows to write in a char[] | ||||
| class StaticStringWriter { | ||||
| @@ -35,5 +34,4 @@ class StaticStringWriter { | ||||
|   char *end; | ||||
|   char *p; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -10,8 +10,7 @@ | ||||
|  | ||||
| #include <ostream> | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class StreamWriter { | ||||
|  public: | ||||
| @@ -34,7 +33,6 @@ class StreamWriter { | ||||
|  | ||||
|   std::ostream& _os; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #endif  // ARDUINOJSON_ENABLE_STD_STREAM | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "./DummyWriter.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <template <typename> class TSerializer, typename TSource> | ||||
| size_t measure(const TSource &source) { | ||||
| @@ -17,5 +16,4 @@ size_t measure(const TSource &source) { | ||||
|   return serializer.bytesWritten(); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -11,8 +11,7 @@ | ||||
| #include "./StreamWriter.hpp" | ||||
| #endif | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <template <typename> class TSerializer, typename TSource, | ||||
|           typename TPrint> | ||||
| @@ -51,5 +50,4 @@ typename enable_if<IsWriteableString<TString>::value, size_t>::type serialize( | ||||
|   return serialize<TSerializer>(source, writer); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,9 +6,8 @@ | ||||
|  | ||||
| #include "Strings/StringTypes.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| namespace Internals { | ||||
| // A special type of data that can be used to insert pregenerated JSON portions. | ||||
| template <typename T> | ||||
| class SerializedValue { | ||||
| @@ -51,20 +50,19 @@ class SerializedValue<TChar*> { | ||||
|   TChar* _data; | ||||
|   size_t _size; | ||||
| }; | ||||
| }  // namespace Internals | ||||
|  | ||||
| template <typename T> | ||||
| inline Internals::SerializedValue<T> serialized(T str) { | ||||
|   return Internals::SerializedValue<T>(str); | ||||
| inline SerializedValue<T> serialized(T str) { | ||||
|   return SerializedValue<T>(str); | ||||
| } | ||||
|  | ||||
| template <typename TChar> | ||||
| inline Internals::SerializedValue<TChar*> serialized(TChar* p) { | ||||
|   return Internals::SerializedValue<TChar*>(p, Internals::makeString(p).size()); | ||||
| inline SerializedValue<TChar*> serialized(TChar* p) { | ||||
|   return SerializedValue<TChar*>(p, makeString(p).size()); | ||||
| } | ||||
|  | ||||
| template <typename TChar> | ||||
| inline Internals::SerializedValue<TChar*> serialized(TChar* p, size_t n) { | ||||
|   return Internals::SerializedValue<TChar*>(p, n); | ||||
| inline SerializedValue<TChar*> serialized(TChar* p, size_t n) { | ||||
|   return SerializedValue<TChar*>(p, n); | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
| #include "JsonVariant.hpp" | ||||
| #include "Memory/StaticMemoryPool.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <size_t CAPACITY> | ||||
| class StaticJsonDocument { | ||||
| @@ -17,7 +17,7 @@ class StaticJsonDocument { | ||||
|  | ||||
|   StaticJsonDocument() : nestingLimit(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} | ||||
|  | ||||
|   Internals::StaticMemoryPoolBase& memoryPool() { | ||||
|   StaticMemoryPoolBase& memoryPool() { | ||||
|     return _memoryPool; | ||||
|   } | ||||
|  | ||||
| @@ -27,19 +27,19 @@ class StaticJsonDocument { | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   typename Internals::JsonVariantAs<T>::type as() const { | ||||
|   typename JsonVariantAs<T>::type as() const { | ||||
|     return getVariant().template as<T>(); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   typename Internals::JsonVariantTo<T>::type to() { | ||||
|   typename JsonVariantTo<T>::type to() { | ||||
|     _memoryPool.clear(); | ||||
|     return getVariant().template to<T>(); | ||||
|   } | ||||
|  | ||||
|   void clear() { | ||||
|     _memoryPool.clear(); | ||||
|     _rootData.type = Internals::JSON_NULL; | ||||
|     _rootData.type = JSON_NULL; | ||||
|   } | ||||
|  | ||||
|   size_t memoryUsage() const { | ||||
| @@ -56,8 +56,8 @@ class StaticJsonDocument { | ||||
|     return JsonVariant(&_memoryPool, &_rootData); | ||||
|   } | ||||
|  | ||||
|   mutable Internals::StaticMemoryPool<CAPACITY> _memoryPool; | ||||
|   mutable Internals::JsonVariantData _rootData; | ||||
|   mutable StaticMemoryPool<CAPACITY> _memoryPool; | ||||
|   mutable JsonVariantData _rootData; | ||||
| }; | ||||
|  | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TMemoryPool> | ||||
| class StringCopier { | ||||
| @@ -21,5 +20,4 @@ class StringCopier { | ||||
|  private: | ||||
|   TMemoryPool* _memoryPool; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TChar> | ||||
| class StringMover { | ||||
| @@ -37,5 +36,4 @@ class StringMover { | ||||
|  private: | ||||
|   TChar* _ptr; | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "./StringCopier.hpp" | ||||
| #include "./StringMover.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename TMemoryPool, typename TInput, typename Enable = void> | ||||
| struct StringStorage { | ||||
| @@ -40,5 +39,4 @@ typename StringStorage<TMemoryPool, TChar*>::type makeStringStorage( | ||||
|     TMemoryPool& jb, TChar* input) { | ||||
|   return StringStorage<TMemoryPool, TChar*>::create(jb, input); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include <WString.h> | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class ArduinoString { | ||||
|  public: | ||||
| @@ -56,5 +55,4 @@ inline ArduinoString makeString(const ::String& str) { | ||||
|   return ArduinoString(str); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class FixedSizeFlashString { | ||||
|  public: | ||||
| @@ -43,5 +42,4 @@ inline FixedSizeFlashString makeString(const __FlashStringHelper* str, | ||||
|                                        size_t sz) { | ||||
|   return FixedSizeFlashString(str, sz); | ||||
| } | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include <string.h>  // strcmp | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class FixedSizeRamString { | ||||
|  public: | ||||
| @@ -46,5 +45,4 @@ inline FixedSizeRamString makeString(const TChar* str, size_t size) { | ||||
|   return FixedSizeRamString(reinterpret_cast<const char*>(str), size); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include <string> | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class StlString { | ||||
|  public: | ||||
| @@ -49,5 +48,4 @@ inline StlString makeString(const std::string& str) { | ||||
|   return StlString(str); | ||||
| } | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "../Polyfills/type_traits.hpp" | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
| template <typename> | ||||
| struct IsString : false_type {}; | ||||
|  | ||||
| @@ -16,8 +15,7 @@ struct IsString<const T> : IsString<T> {}; | ||||
|  | ||||
| template <typename T> | ||||
| struct IsString<T&> : IsString<T> {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|  | ||||
| #include "FixedSizeRamString.hpp" | ||||
| #include "ZeroTerminatedRamString.hpp" | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class ZeroTerminatedFlashString { | ||||
|  public: | ||||
| @@ -44,5 +43,4 @@ inline ZeroTerminatedFlashString makeString(const __FlashStringHelper* str) { | ||||
|  | ||||
| template <> | ||||
| struct IsString<const __FlashStringHelper*> : true_type {}; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ArduinoJson { | ||||
| namespace Internals { | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class ZeroTerminatedRamString { | ||||
|  public: | ||||
| @@ -49,5 +48,4 @@ struct IsString<TChar*> { | ||||
|   static const bool value = sizeof(TChar) == 1; | ||||
| }; | ||||
|  | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
| @@ -85,3 +85,4 @@ add_subdirectory(MsgPackDeserializer) | ||||
| add_subdirectory(MsgPackSerializer) | ||||
| add_subdirectory(Numbers) | ||||
| add_subdirectory(StaticMemoryPool) | ||||
| add_subdirectory(MixedConfiguration) | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
| #include <catch.hpp> | ||||
| #include <sstream> | ||||
|  | ||||
| using namespace ArduinoJson::Internals; | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| static bool isAligned(void* ptr) { | ||||
|   const size_t mask = sizeof(void*) - 1; | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ArduinoJson::Internals; | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| struct NoMemoryAllocator { | ||||
|   void* allocate(size_t) { | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| #include <ArduinoJson/Memory/DynamicMemoryPool.hpp> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ArduinoJson::Internals; | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("DynamicMemoryPool::size()") { | ||||
|   DynamicMemoryPool memoryPool; | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| #include <ArduinoJson/Memory/DynamicMemoryPool.hpp> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ArduinoJson::Internals; | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("DynamicMemoryPool::startString()") { | ||||
|   SECTION("WorksWhenBufferIsBigEnough") { | ||||
|   | ||||
| @@ -18,10 +18,10 @@ TEST_CASE("JsonArray::operator[]") { | ||||
|     REQUIRE(false == array[0].is<bool>()); | ||||
|   } | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|   SECTION("long long") { | ||||
|     array[0] = 9223372036854775807; | ||||
|     REQUIRE(9223372036854775807 == array[0].as<long long>()); | ||||
|     REQUIRE(9223372036854775807 == array[0].as<int64_t>()); | ||||
|     REQUIRE(true == array[0].is<int>()); | ||||
|     REQUIRE(false == array[0].is<bool>()); | ||||
|   } | ||||
|   | ||||
| @@ -7,6 +7,11 @@ | ||||
|  | ||||
| using namespace Catch::Matchers; | ||||
|  | ||||
| namespace my { | ||||
| using ARDUINOJSON_NAMESPACE::isinf; | ||||
| using ARDUINOJSON_NAMESPACE::isnan; | ||||
| } | ||||
|  | ||||
| TEST_CASE("deserializeJson(DynamicJsonDocument&)") { | ||||
|   DynamicJsonDocument doc; | ||||
|  | ||||
| @@ -99,28 +104,28 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") { | ||||
|     DeserializationError err = deserializeJson(doc, "NaN"); | ||||
|     REQUIRE(err == DeserializationError::Ok); | ||||
|     REQUIRE(doc.is<float>() == true); | ||||
|     REQUIRE(Internals::isnan(doc.as<float>())); | ||||
|     REQUIRE(my::isnan(doc.as<float>())); | ||||
|   } | ||||
|  | ||||
|   SECTION("Infinity") { | ||||
|     DeserializationError err = deserializeJson(doc, "Infinity"); | ||||
|     REQUIRE(err == DeserializationError::Ok); | ||||
|     REQUIRE(doc.is<float>() == true); | ||||
|     REQUIRE(Internals::isinf(doc.as<float>())); | ||||
|     REQUIRE(my::isinf(doc.as<float>())); | ||||
|   } | ||||
|  | ||||
|   SECTION("+Infinity") { | ||||
|     DeserializationError err = deserializeJson(doc, "+Infinity"); | ||||
|     REQUIRE(err == DeserializationError::Ok); | ||||
|     REQUIRE(doc.is<float>() == true); | ||||
|     REQUIRE(Internals::isinf(doc.as<float>())); | ||||
|     REQUIRE(my::isinf(doc.as<float>())); | ||||
|   } | ||||
|  | ||||
|   SECTION("-Infinity") { | ||||
|     DeserializationError err = deserializeJson(doc, "-Infinity"); | ||||
|     REQUIRE(err == DeserializationError::Ok); | ||||
|     REQUIRE(doc.is<float>() == true); | ||||
|     REQUIRE(Internals::isinf(doc.as<float>())); | ||||
|     REQUIRE(my::isinf(doc.as<float>())); | ||||
|   } | ||||
|  | ||||
|   SECTION("issue #628") { | ||||
|   | ||||
| @@ -69,7 +69,7 @@ TEST_CASE("serializeJson(JsonVariant)") { | ||||
|     check(false, "false"); | ||||
|   } | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 | ||||
| #if ARDUINOJSON_USE_LONG_LONG | ||||
|   SECTION("NegativeInt64") { | ||||
|     check(-9223372036854775807 - 1, "-9223372036854775808"); | ||||
|   } | ||||
|   | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user