Replace ARDUINOJSON_NAMESPACE with an inline namespace (#1820)

This commit is contained in:
Benoit Blanchon
2023-02-14 10:04:48 +01:00
parent 34dd46110b
commit 1b66a217bf
171 changed files with 855 additions and 684 deletions

View File

@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 8,
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 8,
"sizeof(VariantSlot)");
void setup() {}

View File

@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16,
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
"sizeof(VariantSlot)");
void setup() {}

View File

@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 32,
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 32,
"sizeof(VariantSlot)");
int main() {}

View File

@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16,
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
"sizeof(VariantSlot)");
int main() {}

View File

@ -53,7 +53,8 @@ process()
}
simplify_namespaces() {
perl -p0i -e 's|\} // namespace ARDUINOJSON_NAMESPACE\r?\nnamespace ARDUINOJSON_NAMESPACE \{\r?\n||igs' "$1"
perl -p0i -e 's|ARDUINOJSON_END_PUBLIC_NAMESPACE\r?\nARDUINOJSON_BEGIN_PUBLIC_NAMESPACE\r?\n||igs' "$1"
perl -p0i -e 's|ARDUINOJSON_END_PRIVATE_NAMESPACE\r?\nARDUINOJSON_BEGIN_PRIVATE_NAMESPACE\r?\n||igs' "$1"
rm -f "$1.bak"
}

View File

@ -86,7 +86,7 @@ TEST_CASE("string_view") {
}
}
using ARDUINOJSON_NAMESPACE::adaptString;
using ArduinoJson::detail::adaptString;
TEST_CASE("StringViewAdapter") {
std::string_view str("bravoXXX", 5);

View File

@ -11,8 +11,8 @@
#include <catch.hpp>
namespace my {
using ARDUINOJSON_NAMESPACE::isinf;
using ARDUINOJSON_NAMESPACE::isnan;
using ArduinoJson::detail::isinf;
using ArduinoJson::detail::isnan;
} // namespace my
TEST_CASE("deserialize an integer") {

View File

@ -8,8 +8,6 @@
#include <sstream>
#include <utility>
using ARDUINOJSON_NAMESPACE::addPadding;
class SpyingAllocator {
public:
SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {}

View File

@ -5,7 +5,7 @@
#include <ArduinoJson.h>
#include <catch.hpp>
using ARDUINOJSON_NAMESPACE::addPadding;
using ArduinoJson::detail::addPadding;
static void REQUIRE_JSON(JsonDocument& doc, const std::string& expected) {
std::string json;

View File

@ -5,7 +5,7 @@
#include <ArduinoJson.h>
#include <catch.hpp>
typedef ARDUINOJSON_NAMESPACE::ElementProxy<JsonDocument&> ElementProxy;
typedef ArduinoJson::detail::ElementProxy<JsonDocument&> ElementProxy;
TEST_CASE("ElementProxy::add()") {
DynamicJsonDocument doc(4096);

View File

@ -5,7 +5,7 @@
#include <ArduinoJson.h>
#include <catch.hpp>
typedef ARDUINOJSON_NAMESPACE::MemberProxy<JsonDocument&, const char*>
typedef ArduinoJson::detail::MemberProxy<JsonDocument&, const char*>
MemberProxy;
TEST_CASE("MemberProxy::add()") {

View File

@ -8,8 +8,6 @@
#include <stdlib.h> // malloc, free
#include <string>
using ARDUINOJSON_NAMESPACE::addPadding;
class ArmoredAllocator {
public:
ArmoredAllocator() : _ptr(0), _size(0) {}

View File

@ -7,7 +7,7 @@
#include <catch.hpp>
namespace my {
using ARDUINOJSON_NAMESPACE::isinf;
using ArduinoJson::detail::isinf;
} // namespace my
enum MY_ENUM { ONE = 1, TWO = 2 };

View File

@ -88,7 +88,7 @@ class Complex {
double _real, _imag;
};
namespace ARDUINOJSON_NAMESPACE {
namespace ArduinoJson {
template <>
struct Converter<Complex> {
static void toJson(const Complex& src, JsonVariant dst) {
@ -104,7 +104,7 @@ struct Converter<Complex> {
return src["real"].is<double>() && src["imag"].is<double>();
}
};
} // namespace ARDUINOJSON_NAMESPACE
} // namespace ArduinoJson
TEST_CASE("Custom converter with specialization") {
DynamicJsonDocument doc(4096);
@ -142,7 +142,7 @@ TEST_CASE("Custom converter with specialization") {
}
TEST_CASE("ConverterNeedsWriteableRef") {
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
CHECK(ConverterNeedsWriteableRef<int>::value == false);
CHECK(ConverterNeedsWriteableRef<float>::value == false);
CHECK(ConverterNeedsWriteableRef<JsonVariant>::value == true);

View File

@ -10,7 +10,7 @@
#include <string>
#include <vector>
namespace ARDUINOJSON_NAMESPACE {
namespace ArduinoJson {
template <typename T>
struct Converter<std::vector<T> > {
static void toJson(const std::vector<T>& src, JsonVariant dst) {
@ -63,7 +63,7 @@ struct Converter<std::array<T, N> > {
return result && size == N;
}
};
} // namespace ARDUINOJSON_NAMESPACE
} // namespace ArduinoJson
TEST_CASE("vector<int>") {
SECTION("toJson") {

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/StringStorage/StringCopier.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("StringCopier") {
char buffer[4096];

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("MemoryPool::allocVariant()") {
char buffer[4096];

View File

@ -6,7 +6,7 @@
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
static const size_t poolCapacity = 512;

View File

@ -6,7 +6,7 @@
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
static const char* saveString(MemoryPool& pool, const char* s) {
return pool.saveString(adaptString(const_cast<char*>(s)));

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("MemoryPool::capacity()") {
char buffer[4096];

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Numbers/FloatParts.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("FloatParts<double>") {
SECTION("1.7976931348623157E+308") {

View File

@ -8,7 +8,7 @@
#include <sstream>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("Reader<std::istringstream>") {
SECTION("read()") {

View File

@ -14,7 +14,7 @@
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("ZeroTerminatedRamString") {
SECTION("null") {

View File

@ -8,7 +8,7 @@
#include <catch.hpp>
#include "custom_string.hpp"
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
template <typename StringWriter>
static size_t print(StringWriter& writer, const char* s) {

View File

@ -7,7 +7,7 @@
#include <sstream>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
class EmptyClass {};
enum EmptyEnum {};

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Json/Utf16.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
static void testUtf16Codepoint(uint16_t codeunit, uint32_t expectedCodepoint) {
Utf16::Codepoint cp;

View File

@ -7,7 +7,7 @@
#include <string>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
static void testCodepoint(uint32_t codepoint, std::string expected) {
char buffer[4096];

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Numbers/arithmeticCompare.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("arithmeticCompare()") {
SECTION("int vs uint8_t") {

View File

@ -8,7 +8,8 @@
// Issue #1198: strcmp() implementation that returns a value larger than 8-bit
namespace ARDUINOJSON_NAMESPACE {
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
int strcmp(const char* a, const char* b) {
int result = ::strcmp(a, b);
if (result > 0)
@ -26,4 +27,5 @@ int strncmp(const char* a, const char* b, size_t n) {
return -214748364;
return 0;
}
} // namespace ARDUINOJSON_NAMESPACE
ARDUINOJSON_END_PRIVATE_NAMESPACE

View File

@ -1,11 +1,11 @@
#define ARDUINOJSON_NAMESPACE ArduinoJson_NoAlignment
#define ARDUINOJSON_VERSION_NAMESPACE NoAlignment
#define ARDUINOJSON_ENABLE_ALIGNMENT 0
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 0") {
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
const size_t N = sizeof(void*);

View File

@ -4,7 +4,7 @@
#include <catch.hpp>
TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 1") {
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
const size_t N = sizeof(void*);

View File

@ -5,7 +5,7 @@
#include <limits>
namespace my {
using ARDUINOJSON_NAMESPACE::isinf;
using ArduinoJson::detail::isinf;
} // namespace my
TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") {

View File

@ -5,7 +5,7 @@
#include <limits>
namespace my {
using ARDUINOJSON_NAMESPACE::isnan;
using ArduinoJson::detail::isnan;
} // namespace my
TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") {

View File

@ -53,7 +53,7 @@ TEST_CASE("Flash strings") {
}
TEST_CASE("parseNumber()") { // tables are in Flash
using ARDUINOJSON_NAMESPACE::parseNumber;
using ArduinoJson::detail::parseNumber;
CHECK(parseNumber<float>("1") == 1.f);
CHECK(parseNumber<float>("1.23") == 1.23f);
@ -95,7 +95,7 @@ TEST_CASE("memcpy_P") {
}
TEST_CASE("BoundedReader<const __FlashStringHelper*>") {
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
SECTION("read") {
BoundedReader<const __FlashStringHelper*> reader(F("\x01\xFF"), 2);
@ -135,7 +135,7 @@ TEST_CASE("BoundedReader<const __FlashStringHelper*>") {
}
TEST_CASE("Reader<const __FlashStringHelper*>") {
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
SECTION("read()") {
Reader<const __FlashStringHelper*> reader(F("\x01\xFF\x00\x12"));

View File

@ -5,7 +5,7 @@
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
template <typename T>
static void check(const char* input, T expected) {

View File

@ -7,7 +7,7 @@
#include <sstream>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("deserializeMsgPack() filter") {
StaticJsonDocument<4096> doc;

View File

@ -6,7 +6,7 @@
#include <ArduinoJson.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
TEST_CASE("canConvertNumber<TOut, TIn>()") {
SECTION("int8_t -> int8_t") {

View File

@ -9,7 +9,7 @@
#include <ArduinoJson.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
void checkDouble(const char* input, double expected) {
CAPTURE(input);

View File

@ -9,7 +9,7 @@
#include <ArduinoJson.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
void checkFloat(const char* input, float expected) {
CAPTURE(input);

View File

@ -6,7 +6,7 @@
#include <ArduinoJson.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
template <typename T>
void checkInteger(const char* input, T expected) {

View File

@ -5,7 +5,8 @@
#include <ArduinoJson.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson;
using namespace ArduinoJson::detail;
TEST_CASE("Test unsigned integer overflow") {
VariantData first, second;

View File

@ -11,7 +11,7 @@
#include <ArduinoJson/Json/TextFormatter.hpp>
#include <ArduinoJson/Serialization/Writer.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
template <typename TFloat>
void check(TFloat input, const std::string& expected) {

View File

@ -9,7 +9,7 @@
#include <ArduinoJson/Json/TextFormatter.hpp>
#include <ArduinoJson/Serialization/Writer.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
template <typename T>
void checkWriteInteger(T value, std::string expected) {

View File

@ -7,7 +7,7 @@
#include <ArduinoJson/Json/TextFormatter.hpp>
#include <ArduinoJson/Serialization/Writers/StaticStringWriter.hpp>
using namespace ARDUINOJSON_NAMESPACE;
using namespace ArduinoJson::detail;
void check(const char* input, std::string expected) {
char output[64] = {0};