forked from bblanchon/ArduinoJson
Added support for nullptr
(closes #998)
This commit is contained in:
@ -11,6 +11,7 @@ HEAD
|
|||||||
* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON
|
* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON
|
||||||
* Removed implicit conversion in comparison operators (issue #998)
|
* Removed implicit conversion in comparison operators (issue #998)
|
||||||
* Added lexicographical comparison for `JsonVariant`
|
* Added lexicographical comparison for `JsonVariant`
|
||||||
|
* Added support for `nullptr` (issue #998)
|
||||||
|
|
||||||
> ### BREAKING CHANGES
|
> ### BREAKING CHANGES
|
||||||
>
|
>
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
#define ARDUINOJSON_HAS_LONG_LONG 1
|
#define ARDUINOJSON_HAS_LONG_LONG 1
|
||||||
|
#define ARDUINOJSON_HAS_NULLPTR 1
|
||||||
#else
|
#else
|
||||||
#define ARDUINOJSON_HAS_LONG_LONG 0
|
#define ARDUINOJSON_HAS_LONG_LONG 0
|
||||||
|
#define ARDUINOJSON_HAS_NULLPTR 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Small or big machine?
|
// Small or big machine?
|
||||||
|
@ -88,6 +88,27 @@ struct Comparer<bool, void> {
|
|||||||
void visitNull() {}
|
void visitNull() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if ARDUINOJSON_HAS_NULLPTR
|
||||||
|
template <>
|
||||||
|
struct Comparer<decltype(nullptr), void> {
|
||||||
|
int result;
|
||||||
|
|
||||||
|
explicit Comparer(decltype(nullptr)) : result(1) {}
|
||||||
|
|
||||||
|
void visitArray(const CollectionData &) {}
|
||||||
|
void visitObject(const CollectionData &) {}
|
||||||
|
void visitFloat(Float) {}
|
||||||
|
void visitString(const char *) {}
|
||||||
|
void visitRawJson(const char *, size_t) {}
|
||||||
|
void visitNegativeInteger(UInt) {}
|
||||||
|
void visitPositiveInteger(UInt) {}
|
||||||
|
void visitBoolean(bool) {}
|
||||||
|
void visitNull() {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename TVariant>
|
template <typename TVariant>
|
||||||
class VariantComparisons {
|
class VariantComparisons {
|
||||||
private:
|
private:
|
||||||
|
@ -6,12 +6,13 @@
|
|||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
add_executable(MixedConfigurationTests
|
add_executable(MixedConfigurationTests
|
||||||
|
cpp11.cpp
|
||||||
decode_unicode_0.cpp
|
decode_unicode_0.cpp
|
||||||
decode_unicode_1.cpp
|
decode_unicode_1.cpp
|
||||||
enable_nan_0.cpp
|
|
||||||
enable_nan_1.cpp
|
|
||||||
enable_infinity_0.cpp
|
enable_infinity_0.cpp
|
||||||
enable_infinity_1.cpp
|
enable_infinity_1.cpp
|
||||||
|
enable_nan_0.cpp
|
||||||
|
enable_nan_1.cpp
|
||||||
use_double_0.cpp
|
use_double_0.cpp
|
||||||
use_double_1.cpp
|
use_double_1.cpp
|
||||||
use_long_long_0.cpp
|
use_long_long_0.cpp
|
||||||
|
31
test/MixedConfiguration/cpp11.cpp
Normal file
31
test/MixedConfiguration/cpp11.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
|
||||||
|
TEST_CASE("nullptr") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonVariant variant = doc.to<JsonVariant>();
|
||||||
|
|
||||||
|
SECTION("JsonVariant == nullptr") {
|
||||||
|
REQUIRE((variant == nullptr));
|
||||||
|
REQUIRE_FALSE((variant != nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("JsonVariant != nullptr") {
|
||||||
|
variant.set(42);
|
||||||
|
|
||||||
|
REQUIRE_FALSE((variant == nullptr));
|
||||||
|
REQUIRE((variant != nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("JsonVariant.set(nullptr)") {
|
||||||
|
variant.set(42);
|
||||||
|
variant.set(nullptr);
|
||||||
|
|
||||||
|
REQUIRE(variant.isNull());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user