diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d7bbd87..b1293c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ----------- diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 949e6c30..11e8127b 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -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 diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index af4ea0b5..914dd1de 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -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__) || \ diff --git a/src/ArduinoJson/Data/IsVariant.hpp b/src/ArduinoJson/Data/IsVariant.hpp index 2c543417..ae3659b2 100644 --- a/src/ArduinoJson/Data/IsVariant.hpp +++ b/src/ArduinoJson/Data/IsVariant.hpp @@ -6,12 +6,10 @@ #include "../Polyfills/type_traits.hpp" -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { class JsonVariantTag {}; template struct IsVariant : is_base_of {}; -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Data/JsonFloat.hpp b/src/ArduinoJson/Data/JsonFloat.hpp index 0ed42140..2f6e9570 100644 --- a/src/ArduinoJson/Data/JsonFloat.hpp +++ b/src/ArduinoJson/Data/JsonFloat.hpp @@ -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 diff --git a/src/ArduinoJson/Data/JsonInteger.hpp b/src/ArduinoJson/Data/JsonInteger.hpp index c8ddd00b..650d5854 100644 --- a/src/ArduinoJson/Data/JsonInteger.hpp +++ b/src/ArduinoJson/Data/JsonInteger.hpp @@ -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 diff --git a/src/ArduinoJson/Data/JsonVariantAs.hpp b/src/ArduinoJson/Data/JsonVariantAs.hpp index a3a08479..34b4a6b2 100644 --- a/src/ArduinoJson/Data/JsonVariantAs.hpp +++ b/src/ArduinoJson/Data/JsonVariantAs.hpp @@ -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() @@ -19,5 +18,4 @@ struct JsonVariantAs { typedef const char* type; }; -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Data/JsonVariantContent.hpp b/src/ArduinoJson/Data/JsonVariantContent.hpp index e7d6e415..63597c76 100644 --- a/src/ArduinoJson/Data/JsonVariantContent.hpp +++ b/src/ArduinoJson/Data/JsonVariantContent.hpp @@ -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 diff --git a/src/ArduinoJson/Data/JsonVariantData.hpp b/src/ArduinoJson/Data/JsonVariantData.hpp index 7a148f62..af9dcabb 100644 --- a/src/ArduinoJson/Data/JsonVariantData.hpp +++ b/src/ArduinoJson/Data/JsonVariantData.hpp @@ -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(reinterpret_cast(obj) - offset); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Data/JsonVariantTo.hpp b/src/ArduinoJson/Data/JsonVariantTo.hpp index cc73dfb6..5b5d4f0a 100644 --- a/src/ArduinoJson/Data/JsonVariantTo.hpp +++ b/src/ArduinoJson/Data/JsonVariantTo.hpp @@ -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() template @@ -29,5 +27,4 @@ struct JsonVariantTo { typedef JsonVariant type; }; -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Data/JsonVariantType.hpp b/src/ArduinoJson/Data/JsonVariantType.hpp index 8cf6df50..b83efce0 100644 --- a/src/ArduinoJson/Data/JsonVariantType.hpp +++ b/src/ArduinoJson/Data/JsonVariantType.hpp @@ -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 diff --git a/src/ArduinoJson/Data/Slot.hpp b/src/ArduinoJson/Data/Slot.hpp index 72ce7da9..db603b95 100644 --- a/src/ArduinoJson/Data/Slot.hpp +++ b/src/ArduinoJson/Data/Slot.hpp @@ -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 diff --git a/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp b/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp index 53260657..9f12ddbe 100644 --- a/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp +++ b/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp @@ -8,8 +8,7 @@ #include -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 diff --git a/src/ArduinoJson/Deserialization/CharPointerReader.hpp b/src/ArduinoJson/Deserialization/CharPointerReader.hpp index 8414f84a..56a09dfb 100644 --- a/src/ArduinoJson/Deserialization/CharPointerReader.hpp +++ b/src/ArduinoJson/Deserialization/CharPointerReader.hpp @@ -4,8 +4,7 @@ #pragma once -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template class UnsafeCharPointerReader { @@ -60,5 +59,4 @@ inline SafeCharPointerReader makeReader(const String& input) { } #endif -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Deserialization/DeserializationError.hpp b/src/ArduinoJson/Deserialization/DeserializationError.hpp index 724f2ab9..92a868b6 100644 --- a/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -8,7 +8,7 @@ #include #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 diff --git a/src/ArduinoJson/Deserialization/FlashStringReader.hpp b/src/ArduinoJson/Deserialization/FlashStringReader.hpp index 2eabf798..e9fd57e6 100644 --- a/src/ArduinoJson/Deserialization/FlashStringReader.hpp +++ b/src/ArduinoJson/Deserialization/FlashStringReader.hpp @@ -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 diff --git a/src/ArduinoJson/Deserialization/IteratorReader.hpp b/src/ArduinoJson/Deserialization/IteratorReader.hpp index 7e01c214..ce33c3a8 100644 --- a/src/ArduinoJson/Deserialization/IteratorReader.hpp +++ b/src/ArduinoJson/Deserialization/IteratorReader.hpp @@ -4,8 +4,7 @@ #pragma once -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template class IteratorReader { @@ -30,5 +29,4 @@ inline IteratorReader makeReader( return IteratorReader(input.begin(), input.end()); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Deserialization/StdStreamReader.hpp b/src/ArduinoJson/Deserialization/StdStreamReader.hpp index 8ad841a7..2db44194 100644 --- a/src/ArduinoJson/Deserialization/StdStreamReader.hpp +++ b/src/ArduinoJson/Deserialization/StdStreamReader.hpp @@ -8,8 +8,7 @@ #include -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 diff --git a/src/ArduinoJson/Deserialization/deserialize.hpp b/src/ArduinoJson/Deserialization/deserialize.hpp index a32bbdd3..fedea7f4 100644 --- a/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/src/ArduinoJson/Deserialization/deserialize.hpp @@ -12,8 +12,7 @@ #include "./IteratorReader.hpp" #include "./StdStreamReader.hpp" -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template