Kept only two namespaces ArduinoJson and ArduinoJson::Internals

This commit is contained in:
Benoit Blanchon
2018-01-19 08:32:15 +01:00
parent bae179ed67
commit e390587e91
53 changed files with 241 additions and 225 deletions

View File

@ -22,8 +22,8 @@ struct ValueSaver {
}; };
template <typename Source> template <typename Source>
struct ValueSaver<Source, typename TypeTraits::EnableIf< struct ValueSaver<
StringTraits<Source>::should_duplicate>::type> { Source, typename EnableIf<StringTraits<Source>::should_duplicate>::type> {
template <typename Destination> template <typename Destination>
static bool save(JsonBuffer* buffer, Destination& dest, Source source) { static bool save(JsonBuffer* buffer, Destination& dest, Source source) {
if (!StringTraits<Source>::is_null(source)) { if (!StringTraits<Source>::is_null(source)) {
@ -40,8 +40,8 @@ struct ValueSaver<Source, typename TypeTraits::EnableIf<
// const char*, const signed char*, const unsigned char* // const char*, const signed char*, const unsigned char*
template <typename Char> template <typename Char>
struct ValueSaver<Char*, typename TypeTraits::EnableIf< struct ValueSaver<
!StringTraits<Char*>::should_duplicate>::type> { Char*, typename EnableIf<!StringTraits<Char*>::should_duplicate>::type> {
template <typename Destination> template <typename Destination>
static bool save(JsonBuffer*, Destination& dest, Char* source) { static bool save(JsonBuffer*, Destination& dest, Char* source) {
dest = reinterpret_cast<const char*>(source); dest = reinterpret_cast<const char*>(source);

View File

@ -71,7 +71,7 @@ class JsonParser {
template <typename TJsonBuffer, typename TString, typename Enable = void> template <typename TJsonBuffer, typename TString, typename Enable = void>
struct JsonParserBuilder { struct JsonParserBuilder {
typedef typename Internals::StringTraits<TString>::Reader InputReader; typedef typename StringTraits<TString>::Reader InputReader;
typedef JsonParser<InputReader, TJsonBuffer &> TParser; typedef JsonParser<InputReader, TJsonBuffer &> TParser;
static TParser makeParser(TJsonBuffer *buffer, TString &json, static TParser makeParser(TJsonBuffer *buffer, TString &json,
@ -81,10 +81,9 @@ struct JsonParserBuilder {
}; };
template <typename TJsonBuffer, typename TChar> template <typename TJsonBuffer, typename TChar>
struct JsonParserBuilder< struct JsonParserBuilder<TJsonBuffer, TChar *,
TJsonBuffer, TChar *, typename EnableIf<!IsConst<TChar>::value>::type> {
typename TypeTraits::EnableIf<!TypeTraits::IsConst<TChar>::value>::type> { typedef typename StringTraits<TChar *>::Reader TReader;
typedef typename Internals::StringTraits<TChar *>::Reader TReader;
typedef StringWriter<TChar> TWriter; typedef StringWriter<TChar> TWriter;
typedef JsonParser<TReader, TWriter> TParser; typedef JsonParser<TReader, TWriter> TParser;

View File

@ -141,8 +141,7 @@ inline bool ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseObjectTo(
template <typename TReader, typename TWriter> template <typename TReader, typename TWriter>
inline const char * inline const char *
ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseString() { ArduinoJson::Internals::JsonParser<TReader, TWriter>::parseString() {
typename TypeTraits::RemoveReference<TWriter>::type::String str = typename RemoveReference<TWriter>::type::String str = _writer.startString();
_writer.startString();
skipSpacesAndComments(_reader); skipSpacesAndComments(_reader);
char c = _reader.current(); char c = _reader.current();

View File

@ -19,6 +19,7 @@
#endif #endif
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
class DefaultAllocator { class DefaultAllocator {
public: public:
void* allocate(size_t size) { void* allocate(size_t size) {
@ -151,6 +152,7 @@ class DynamicJsonBufferBase
Block* _head; Block* _head;
size_t _nextBlockCapacity; size_t _nextBlockCapacity;
}; };
}
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop #pragma clang diagnostic pop
@ -163,5 +165,6 @@ class DynamicJsonBufferBase
// Implements a JsonBuffer with dynamic memory allocation. // Implements a JsonBuffer with dynamic memory allocation.
// You are strongly encouraged to consider using StaticJsonBuffer which is much // You are strongly encouraged to consider using StaticJsonBuffer which is much
// more suitable for embedded systems. // more suitable for embedded systems.
typedef DynamicJsonBufferBase<DefaultAllocator> DynamicJsonBuffer; typedef Internals::DynamicJsonBufferBase<Internals::DefaultAllocator>
DynamicJsonBuffer;
} }

View File

@ -26,7 +26,9 @@ namespace ArduinoJson {
// Forward declarations // Forward declarations
class JsonObject; class JsonObject;
class JsonBuffer; class JsonBuffer;
namespace Internals {
class JsonArraySubscript; class JsonArraySubscript;
}
// An array of JsonVariant. // An array of JsonVariant.
// //
@ -47,10 +49,10 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
: Internals::List<JsonVariant>(buffer) {} : Internals::List<JsonVariant>(buffer) {}
// Gets the value at the specified index // Gets the value at the specified index
const JsonArraySubscript operator[](size_t index) const; const Internals::JsonArraySubscript operator[](size_t index) const;
// Gets or sets the value at specified index // Gets or sets the value at specified index
JsonArraySubscript operator[](size_t index); Internals::JsonArraySubscript operator[](size_t index);
// Adds the specified value at the end of the array. // Adds the specified value at the end of the array.
// //
@ -97,8 +99,7 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
// bool set(size_t index, TValue value, uint8_t decimals); // bool set(size_t index, TValue value, uint8_t decimals);
// TValue = float, double // TValue = float, double
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsFloatingPoint<T>::value, typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value, bool>::type
bool>::type
set(size_t index, T value, uint8_t decimals) { set(size_t index, T value, uint8_t decimals) {
return set_impl<const JsonVariant &>(index, JsonVariant(value, decimals)); return set_impl<const JsonVariant &>(index, JsonVariant(value, decimals));
} }

View File

@ -13,6 +13,7 @@
#endif #endif
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> { class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> {
public: public:
FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index) FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index)
@ -47,7 +48,7 @@ class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> {
} }
template <typename T> template <typename T>
FORCE_INLINE typename Internals::JsonVariantAs<T>::type as() const { FORCE_INLINE typename JsonVariantAs<T>::type as() const {
return _array.get<T>(_index); return _array.get<T>(_index);
} }
@ -86,21 +87,6 @@ class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> {
const size_t _index; const size_t _index;
}; };
#if ARDUINOJSON_ENABLE_STD_STREAM
inline std::ostream& operator<<(std::ostream& os,
const JsonArraySubscript& source) {
return source.printTo(os);
}
#endif
inline JsonArraySubscript JsonArray::operator[](size_t index) {
return JsonArraySubscript(*this, index);
}
inline const JsonArraySubscript JsonArray::operator[](size_t index) const {
return JsonArraySubscript(*const_cast<JsonArray*>(this), index);
}
template <typename TImpl> template <typename TImpl>
inline JsonArraySubscript JsonVariantSubscripts<TImpl>::operator[]( inline JsonArraySubscript JsonVariantSubscripts<TImpl>::operator[](
size_t index) { size_t index) {
@ -113,7 +99,23 @@ inline const JsonArraySubscript JsonVariantSubscripts<TImpl>::operator[](
return impl()->template as<JsonArray>()[index]; return impl()->template as<JsonArray>()[index];
} }
} // namespace ArduinoJson #if ARDUINOJSON_ENABLE_STD_STREAM
inline std::ostream& operator<<(std::ostream& os,
const JsonArraySubscript& source) {
return source.printTo(os);
}
#endif
}
inline Internals::JsonArraySubscript JsonArray::operator[](size_t index) {
return Internals::JsonArraySubscript(*this, index);
}
inline const Internals::JsonArraySubscript JsonArray::operator[](
size_t index) const {
return Internals::JsonArraySubscript(*const_cast<JsonArray*>(this), index);
}
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)

View File

@ -42,8 +42,8 @@ class JsonBuffer : Internals::NonCopyable {
// TValue = const std::string&, const String&, // TValue = const std::string&, const String&,
template <typename TString> template <typename TString>
DEPRECATED("char* are duplicated, you don't need strdup() anymore") DEPRECATED("char* are duplicated, you don't need strdup() anymore")
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TString>::value, typename Internals::EnableIf<!Internals::IsArray<TString>::value,
const char *>::type strdup(const TString &src) { const char *>::type strdup(const TString &src) {
return Internals::StringTraits<TString>::duplicate(src, this); return Internals::StringTraits<TString>::duplicate(src, this);
} }
// //

View File

@ -7,6 +7,7 @@
#include "Deserialization/JsonParser.hpp" #include "Deserialization/JsonParser.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TDerived> template <typename TDerived>
class JsonBufferBase : public JsonBuffer { class JsonBufferBase : public JsonBuffer {
public: public:
@ -25,8 +26,8 @@ class JsonBufferBase : public JsonBuffer {
// JsonArray& parseArray(TString); // JsonArray& parseArray(TString);
// TString = const std::string&, const String& // TString = const std::string&, const String&
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TString>::value, typename Internals::EnableIf<!Internals::IsArray<TString>::value,
JsonArray &>::type JsonArray &>::type
parseArray(const TString &json, parseArray(const TString &json,
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
return Internals::makeParser(that(), json, nestingLimit).parseArray(); return Internals::makeParser(that(), json, nestingLimit).parseArray();
@ -62,8 +63,8 @@ class JsonBufferBase : public JsonBuffer {
// JsonObject& parseObject(TString); // JsonObject& parseObject(TString);
// TString = const std::string&, const String& // TString = const std::string&, const String&
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TString>::value, typename Internals::EnableIf<!Internals::IsArray<TString>::value,
JsonObject &>::type JsonObject &>::type
parseObject(const TString &json, parseObject(const TString &json,
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
return Internals::makeParser(that(), json, nestingLimit).parseObject(); return Internals::makeParser(that(), json, nestingLimit).parseObject();
@ -91,8 +92,8 @@ class JsonBufferBase : public JsonBuffer {
// JsonVariant parse(TString); // JsonVariant parse(TString);
// TString = const std::string&, const String& // TString = const std::string&, const String&
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TString>::value, typename Internals::EnableIf<!Internals::IsArray<TString>::value,
JsonVariant>::type JsonVariant>::type
parse(const TString &json, parse(const TString &json,
uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
return Internals::makeParser(that(), json, nestingLimit).parseVariant(); return Internals::makeParser(that(), json, nestingLimit).parseVariant();
@ -123,3 +124,4 @@ class JsonBufferBase : public JsonBuffer {
} }
}; };
} }
}

View File

@ -26,6 +26,10 @@ namespace ArduinoJson {
// Forward declarations // Forward declarations
class JsonArray; class JsonArray;
class JsonBuffer; class JsonBuffer;
namespace Internals {
template <typename>
class JsonObjectSubscript;
}
// A dictionary of JsonVariant indexed by string (char*) // A dictionary of JsonVariant indexed by string (char*)
// //
@ -50,15 +54,16 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
// JsonObjectSubscript operator[](TKey) // JsonObjectSubscript operator[](TKey)
// TKey = const std::string&, const String& // TKey = const std::string&, const String&
template <typename TString> template <typename TString>
JsonObjectSubscript<const TString&> operator[](const TString& key) { Internals::JsonObjectSubscript<const TString&> operator[](
return JsonObjectSubscript<const TString&>(*this, key); const TString& key) {
return Internals::JsonObjectSubscript<const TString&>(*this, key);
} }
// //
// JsonObjectSubscript operator[](TKey) // JsonObjectSubscript operator[](TKey)
// TKey = char*, const char*, char[], const char[N], const FlashStringHelper* // TKey = char*, const char*, char[], const char[N], const FlashStringHelper*
template <typename TString> template <typename TString>
JsonObjectSubscript<TString*> operator[](TString* key) { Internals::JsonObjectSubscript<TString*> operator[](TString* key) {
return JsonObjectSubscript<TString*>(*this, key); return Internals::JsonObjectSubscript<TString*>(*this, key);
} }
// Gets the value associated with the specified key. // Gets the value associated with the specified key.
@ -66,17 +71,19 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
// const JsonObjectSubscript operator[](TKey) const; // const JsonObjectSubscript operator[](TKey) const;
// TKey = const std::string&, const String& // TKey = const std::string&, const String&
template <typename TString> template <typename TString>
const JsonObjectSubscript<const TString&> operator[]( const Internals::JsonObjectSubscript<const TString&> operator[](
const TString& key) const { const TString& key) const {
return JsonObjectSubscript<const TString&>(*const_cast<JsonObject*>(this), return Internals::JsonObjectSubscript<const TString&>(
key); *const_cast<JsonObject*>(this), key);
} }
// //
// const JsonObjectSubscript operator[](TKey) const; // const JsonObjectSubscript operator[](TKey) const;
// TKey = const char*, const char[N], const FlashStringHelper* // TKey = const char*, const char[N], const FlashStringHelper*
template <typename TString> template <typename TString>
const JsonObjectSubscript<TString*> operator[](TString* key) const { const Internals::JsonObjectSubscript<TString*> operator[](
return JsonObjectSubscript<TString*>(*const_cast<JsonObject*>(this), key); TString* key) const {
return Internals::JsonObjectSubscript<TString*>(
*const_cast<JsonObject*>(this), key);
} }
// Sets the specified key with the specified value. // Sets the specified key with the specified value.
@ -120,8 +127,8 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
// TValue = float, double // TValue = float, double
template <typename TValue, typename TString> template <typename TValue, typename TString>
DEPRECATED("Second argument is not supported anymore") DEPRECATED("Second argument is not supported anymore")
typename TypeTraits::EnableIf<TypeTraits::IsFloatingPoint<TValue>::value, typename Internals::EnableIf<Internals::IsFloatingPoint<TValue>::value,
bool>::type bool>::type
set(const TString& key, TValue value, uint8_t) { set(const TString& key, TValue value, uint8_t) {
return set_impl<const TString&, const JsonVariant&>(key, return set_impl<const TString&, const JsonVariant&>(key,
JsonVariant(value)); JsonVariant(value));
@ -132,8 +139,8 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
// TValue = float, double // TValue = float, double
template <typename TValue, typename TString> template <typename TValue, typename TString>
DEPRECATED("Second argument is not supported anymore") DEPRECATED("Second argument is not supported anymore")
typename TypeTraits::EnableIf<TypeTraits::IsFloatingPoint<TValue>::value, typename Internals::EnableIf<Internals::IsFloatingPoint<TValue>::value,
bool>::type bool>::type
set(TString* key, TValue value, uint8_t) { set(TString* key, TValue value, uint8_t) {
return set_impl<TString*, const JsonVariant&>(key, JsonVariant(value)); return set_impl<TString*, const JsonVariant&>(key, JsonVariant(value));
} }

View File

@ -14,6 +14,7 @@
#endif #endif
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TStringRef> template <typename TStringRef>
class JsonObjectSubscript class JsonObjectSubscript
@ -35,10 +36,8 @@ class JsonObjectSubscript
// TValue = bool, char, long, int, short, float, double, // TValue = bool, char, long, int, short, float, double,
// std::string, String, JsonArray, JsonObject // std::string, String, JsonArray, JsonObject
template <typename TValue> template <typename TValue>
FORCE_INLINE FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, this_type&>::type
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TValue>::value, operator=(const TValue& src) {
this_type&>::type
operator=(const TValue& src) {
_object.set(_key, src); _object.set(_key, src);
return *this; return *this;
} }
@ -56,7 +55,7 @@ class JsonObjectSubscript
} }
template <typename TValue> template <typename TValue>
FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type as() const { FORCE_INLINE typename JsonVariantAs<TValue>::type as() const {
return _object.get<TValue>(_key); return _object.get<TValue>(_key);
} }
@ -71,10 +70,8 @@ class JsonObjectSubscript
// TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant, // TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant,
// std::string, String, JsonArray, JsonObject // std::string, String, JsonArray, JsonObject
template <typename TValue> template <typename TValue>
FORCE_INLINE FORCE_INLINE typename EnableIf<!IsArray<TValue>::value, bool>::type set(
typename TypeTraits::EnableIf<!TypeTraits::IsArray<TValue>::value, const TValue& value) {
bool>::type
set(const TValue& value) {
return _object.set(_key, value); return _object.set(_key, value);
} }
// //
@ -105,7 +102,8 @@ inline std::ostream& operator<<(std::ostream& os,
return source.printTo(os); return source.printTo(os);
} }
#endif #endif
} // namespace ArduinoJson }
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)

View File

@ -36,7 +36,7 @@ class JsonObject;
// - a char, short, int or a long (signed or unsigned) // - a char, short, int or a long (signed or unsigned)
// - a string (const char*) // - a string (const char*)
// - a reference to a JsonArray or JsonObject // - a reference to a JsonArray or JsonObject
class JsonVariant : public JsonVariantBase<JsonVariant> { class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
template <typename Print> template <typename Print>
friend class Internals::JsonSerializer; friend class Internals::JsonSerializer;
@ -56,8 +56,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonVariant(double value); // JsonVariant(double value);
// JsonVariant(float value); // JsonVariant(float value);
template <typename T> template <typename T>
JsonVariant(T value, typename TypeTraits::EnableIf< JsonVariant(T value, typename Internals::EnableIf<
TypeTraits::IsFloatingPoint<T>::value>::type * = 0) { Internals::IsFloatingPoint<T>::value>::type * = 0) {
using namespace Internals; using namespace Internals;
_type = JSON_FLOAT; _type = JSON_FLOAT;
_content.asFloat = static_cast<JsonFloat>(value); _content.asFloat = static_cast<JsonFloat>(value);
@ -65,8 +65,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
template <typename T> template <typename T>
DEPRECATED("Second argument is not supported anymore") DEPRECATED("Second argument is not supported anymore")
JsonVariant(T value, uint8_t, JsonVariant(T value, uint8_t,
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsFloatingPoint<T>::value>::type * = 0) { Internals::IsFloatingPoint<T>::value>::type * = 0) {
using namespace Internals; using namespace Internals;
_type = JSON_FLOAT; _type = JSON_FLOAT;
_content.asFloat = static_cast<JsonFloat>(value); _content.asFloat = static_cast<JsonFloat>(value);
@ -79,9 +79,11 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonVariant(signed long) // JsonVariant(signed long)
// JsonVariant(signed char) // JsonVariant(signed char)
template <typename T> template <typename T>
JsonVariant(T value, typename TypeTraits::EnableIf< JsonVariant(
TypeTraits::IsSignedIntegral<T>::value || T value,
TypeTraits::IsSame<T, char>::value>::type * = 0) { typename Internals::EnableIf<Internals::IsSignedIntegral<T>::value ||
Internals::IsSame<T, char>::value>::type * =
0) {
using namespace Internals; using namespace Internals;
if (value >= 0) { if (value >= 0) {
_type = JSON_POSITIVE_INTEGER; _type = JSON_POSITIVE_INTEGER;
@ -96,8 +98,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonVariant(unsigned long) // JsonVariant(unsigned long)
template <typename T> template <typename T>
JsonVariant(T value, JsonVariant(T value,
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsUnsignedIntegral<T>::value>::type * = 0) { Internals::IsUnsignedIntegral<T>::value>::type * = 0) {
using namespace Internals; using namespace Internals;
_type = JSON_POSITIVE_INTEGER; _type = JSON_POSITIVE_INTEGER;
_content.asInteger = static_cast<JsonUInt>(value); _content.asInteger = static_cast<JsonUInt>(value);
@ -110,7 +112,7 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
template <typename TChar> template <typename TChar>
JsonVariant( JsonVariant(
const TChar *value, const TChar *value,
typename TypeTraits::EnableIf<TypeTraits::IsChar<TChar>::value>::type * = typename Internals::EnableIf<Internals::IsChar<TChar>::value>::type * =
0) { 0) {
_type = Internals::JSON_STRING; _type = Internals::JSON_STRING;
_content.asString = reinterpret_cast<const char *>(value); _content.asString = reinterpret_cast<const char *>(value);
@ -144,14 +146,13 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// unsigned int as<unsigned int>() const; // unsigned int as<unsigned int>() const;
// unsigned long as<unsigned long>() const; // unsigned long as<unsigned long>() const;
template <typename T> template <typename T>
const typename TypeTraits::EnableIf<TypeTraits::IsIntegral<T>::value, T>::type const typename Internals::EnableIf<Internals::IsIntegral<T>::value, T>::type
as() const { as() const {
return variantAsInteger<T>(); return variantAsInteger<T>();
} }
// bool as<bool>() const // bool as<bool>() const
template <typename T> template <typename T>
const typename TypeTraits::EnableIf<TypeTraits::IsSame<T, bool>::value, const typename Internals::EnableIf<Internals::IsSame<T, bool>::value, T>::type
T>::type
as() const { as() const {
return variantAsInteger<int>() != 0; return variantAsInteger<int>() != 0;
} }
@ -159,8 +160,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// double as<double>() const; // double as<double>() const;
// float as<float>() const; // float as<float>() const;
template <typename T> template <typename T>
const typename TypeTraits::EnableIf<TypeTraits::IsFloatingPoint<T>::value, const typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value,
T>::type T>::type
as() const { as() const {
return variantAsFloat<T>(); return variantAsFloat<T>();
} }
@ -168,9 +169,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// const char* as<const char*>() const; // const char* as<const char*>() const;
// const char* as<char*>() const; // const char* as<char*>() const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsSame<T, const char *>::value || typename Internals::EnableIf<Internals::IsSame<T, const char *>::value ||
TypeTraits::IsSame<T, char *>::value, Internals::IsSame<T, char *>::value,
const char *>::type const char *>::type
as() const { as() const {
return variantAsString(); return variantAsString();
} }
@ -178,7 +179,7 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// std::string as<std::string>() const; // std::string as<std::string>() const;
// String as<String>() const; // String as<String>() const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<Internals::StringTraits<T>::has_append, T>::type typename Internals::EnableIf<Internals::StringTraits<T>::has_append, T>::type
as() const { as() const {
const char *cstr = variantAsString(); const char *cstr = variantAsString();
if (cstr) return T(cstr); if (cstr) return T(cstr);
@ -190,9 +191,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonArray& as<JsonArray> const; // JsonArray& as<JsonArray> const;
// JsonArray& as<JsonArray&> const; // JsonArray& as<JsonArray&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame<typename TypeTraits::RemoveReference<T>::type, Internals::IsSame<typename Internals::RemoveReference<T>::type,
JsonArray>::value, JsonArray>::value,
JsonArray &>::type JsonArray &>::type
as() const { as() const {
return variantAsArray(); return variantAsArray();
@ -200,9 +201,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// //
// const JsonArray& as<const JsonArray&> const; // const JsonArray& as<const JsonArray&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame<typename TypeTraits::RemoveReference<T>::type, Internals::IsSame<typename Internals::RemoveReference<T>::type,
const JsonArray>::value, const JsonArray>::value,
const JsonArray &>::type const JsonArray &>::type
as() const { as() const {
return variantAsArray(); return variantAsArray();
@ -211,9 +212,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonObject& as<JsonObject> const; // JsonObject& as<JsonObject> const;
// JsonObject& as<JsonObject&> const; // JsonObject& as<JsonObject&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame<typename TypeTraits::RemoveReference<T>::type, Internals::IsSame<typename Internals::RemoveReference<T>::type,
JsonObject>::value, JsonObject>::value,
JsonObject &>::type JsonObject &>::type
as() const { as() const {
return variantAsObject(); return variantAsObject();
@ -222,9 +223,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// JsonObject& as<const JsonObject> const; // JsonObject& as<const JsonObject> const;
// JsonObject& as<const JsonObject&> const; // JsonObject& as<const JsonObject&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame<typename TypeTraits::RemoveReference<T>::type, Internals::IsSame<typename Internals::RemoveReference<T>::type,
const JsonObject>::value, const JsonObject>::value,
const JsonObject &>::type const JsonObject &>::type
as() const { as() const {
return variantAsObject(); return variantAsObject();
@ -232,8 +233,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// //
// JsonVariant as<JsonVariant> const; // JsonVariant as<JsonVariant> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsSame<T, JsonVariant>::value, typename Internals::EnableIf<Internals::IsSame<T, JsonVariant>::value,
T>::type T>::type
as() const { as() const {
return *this; return *this;
} }
@ -251,23 +252,22 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// bool is<unsigned int>() const; // bool is<unsigned int>() const;
// bool is<unsigned long>() const; // bool is<unsigned long>() const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsIntegral<T>::value, bool>::type typename Internals::EnableIf<Internals::IsIntegral<T>::value, bool>::type is()
is() const { const {
return variantIsInteger(); return variantIsInteger();
} }
// //
// bool is<double>() const; // bool is<double>() const;
// bool is<float>() const; // bool is<float>() const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsFloatingPoint<T>::value, typename Internals::EnableIf<Internals::IsFloatingPoint<T>::value, bool>::type
bool>::type
is() const { is() const {
return variantIsFloat(); return variantIsFloat();
} }
// //
// bool is<bool>() const // bool is<bool>() const
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsSame<T, bool>::value, bool>::type typename Internals::EnableIf<Internals::IsSame<T, bool>::value, bool>::type
is() const { is() const {
return variantIsBoolean(); return variantIsBoolean();
} }
@ -275,9 +275,9 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// bool is<const char*>() const; // bool is<const char*>() const;
// bool is<char*>() const; // bool is<char*>() const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf<TypeTraits::IsSame<T, const char *>::value || typename Internals::EnableIf<Internals::IsSame<T, const char *>::value ||
TypeTraits::IsSame<T, char *>::value, Internals::IsSame<T, char *>::value,
bool>::type bool>::type
is() const { is() const {
return variantIsString(); return variantIsString();
} }
@ -286,11 +286,10 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// bool is<JsonArray&> const; // bool is<JsonArray&> const;
// bool is<const JsonArray&> const; // bool is<const JsonArray&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame< Internals::IsSame<typename Internals::RemoveConst<
typename TypeTraits::RemoveConst< typename Internals::RemoveReference<T>::type>::type,
typename TypeTraits::RemoveReference<T>::type>::type, JsonArray>::value,
JsonArray>::value,
bool>::type bool>::type
is() const { is() const {
return variantIsArray(); return variantIsArray();
@ -300,11 +299,10 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
// bool is<JsonObject&> const; // bool is<JsonObject&> const;
// bool is<const JsonObject&> const; // bool is<const JsonObject&> const;
template <typename T> template <typename T>
typename TypeTraits::EnableIf< typename Internals::EnableIf<
TypeTraits::IsSame< Internals::IsSame<typename Internals::RemoveConst<
typename TypeTraits::RemoveConst< typename Internals::RemoveReference<T>::type>::type,
typename TypeTraits::RemoveReference<T>::type>::type, JsonObject>::value,
JsonObject>::value,
bool>::type bool>::type
is() const { is() const {
return variantIsObject(); return variantIsObject();

View File

@ -11,12 +11,14 @@
#include "Serialization/JsonPrintable.hpp" #include "Serialization/JsonPrintable.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TImpl> template <typename TImpl>
class JsonVariantBase : public Internals::JsonPrintable<TImpl>, class JsonVariantBase : public JsonPrintable<TImpl>,
public JsonVariantCasts<TImpl>, public JsonVariantCasts<TImpl>,
public JsonVariantComparisons<TImpl>, public JsonVariantComparisons<TImpl>,
public JsonVariantOr<TImpl>, public JsonVariantOr<TImpl>,
public JsonVariantSubscripts<TImpl>, public JsonVariantSubscripts<TImpl>,
public TypeTraits::JsonVariantTag {}; public JsonVariantTag {};
}
} }

View File

@ -8,6 +8,7 @@
#include "Polyfills/attributes.hpp" #include "Polyfills/attributes.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TImpl> template <typename TImpl>
class JsonVariantCasts { class JsonVariantCasts {
@ -55,3 +56,4 @@ class JsonVariantCasts {
} }
}; };
} }
}

View File

@ -9,6 +9,7 @@
#include "TypeTraits/IsVariant.hpp" #include "TypeTraits/IsVariant.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TImpl> template <typename TImpl>
class JsonVariantComparisons { class JsonVariantComparisons {
@ -20,10 +21,8 @@ class JsonVariantComparisons {
} }
template <typename TComparand> template <typename TComparand>
friend friend typename EnableIf<!IsVariant<TComparand>::value, bool>::type
typename TypeTraits::EnableIf<!TypeTraits::IsVariant<TComparand>::value, operator==(TComparand comparand, const JsonVariantComparisons &variant) {
bool>::type
operator==(TComparand comparand, const JsonVariantComparisons &variant) {
return variant.equals(comparand); return variant.equals(comparand);
} }
@ -34,10 +33,8 @@ class JsonVariantComparisons {
} }
template <typename TComparand> template <typename TComparand>
friend friend typename EnableIf<!IsVariant<TComparand>::value, bool>::type
typename TypeTraits::EnableIf<!TypeTraits::IsVariant<TComparand>::value, operator!=(TComparand comparand, const JsonVariantComparisons &variant) {
bool>::type
operator!=(TComparand comparand, const JsonVariantComparisons &variant) {
return !variant.equals(comparand); return !variant.equals(comparand);
} }
@ -94,7 +91,7 @@ class JsonVariantComparisons {
} }
template <typename T> template <typename T>
const typename Internals::JsonVariantAs<T>::type as() const { const typename JsonVariantAs<T>::type as() const {
return impl()->template as<T>(); return impl()->template as<T>();
} }
@ -104,18 +101,16 @@ class JsonVariantComparisons {
} }
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<Internals::StringTraits<TString>::has_equals, typename EnableIf<StringTraits<TString>::has_equals, bool>::type equals(
bool>::type const TString &comparand) const {
equals(const TString &comparand) const {
const char *value = as<const char *>(); const char *value = as<const char *>();
return Internals::StringTraits<TString>::equals(comparand, value); return StringTraits<TString>::equals(comparand, value);
} }
template <typename TComparand> template <typename TComparand>
typename TypeTraits::EnableIf< typename EnableIf<!IsVariant<TComparand>::value &&
!TypeTraits::IsVariant<TComparand>::value && !StringTraits<TComparand>::has_equals,
!Internals::StringTraits<TComparand>::has_equals, bool>::type
bool>::type
equals(const TComparand &comparand) const { equals(const TComparand &comparand) const {
return as<TComparand>() == comparand; return as<TComparand>() == comparand;
} }
@ -140,3 +135,4 @@ class JsonVariantComparisons {
} }
}; };
} }
}

View File

@ -58,7 +58,7 @@ inline T JsonVariant::variantAsInteger() const {
return T(~_content.asInteger + 1); return T(~_content.asInteger + 1);
case JSON_STRING: case JSON_STRING:
case JSON_UNPARSED: case JSON_UNPARSED:
return Polyfills::parseInteger<T>(_content.asString); return parseInteger<T>(_content.asString);
default: default:
return T(_content.asFloat); return T(_content.asFloat);
} }
@ -86,7 +86,7 @@ inline T JsonVariant::variantAsFloat() const {
return -static_cast<T>(_content.asInteger); return -static_cast<T>(_content.asInteger);
case JSON_STRING: case JSON_STRING:
case JSON_UNPARSED: case JSON_UNPARSED:
return Polyfills::parseFloat<T>(_content.asString); return parseFloat<T>(_content.asString);
default: default:
return static_cast<T>(_content.asFloat); return static_cast<T>(_content.asFloat);
} }
@ -106,7 +106,7 @@ inline bool JsonVariant::variantIsInteger() const {
using namespace Internals; using namespace Internals;
return _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER || return _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER ||
(_type == JSON_UNPARSED && Polyfills::isInteger(_content.asString)); (_type == JSON_UNPARSED && isInteger(_content.asString));
} }
inline bool JsonVariant::variantIsFloat() const { inline bool JsonVariant::variantIsFloat() const {
@ -114,7 +114,7 @@ inline bool JsonVariant::variantIsFloat() const {
return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER || return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER ||
_type == JSON_NEGATIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER ||
(_type == JSON_UNPARSED && Polyfills::isFloat(_content.asString)); (_type == JSON_UNPARSED && isFloat(_content.asString));
} }
#if ARDUINOJSON_ENABLE_STD_STREAM #if ARDUINOJSON_ENABLE_STD_STREAM

View File

@ -8,6 +8,7 @@
#include "Polyfills/attributes.hpp" #include "Polyfills/attributes.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
template <typename TImpl> template <typename TImpl>
class JsonVariantOr { class JsonVariantOr {
@ -34,3 +35,4 @@ class JsonVariantOr {
} }
}; };
} }
}

View File

@ -10,6 +10,7 @@
#include "TypeTraits/EnableIf.hpp" #include "TypeTraits/EnableIf.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
// Forward declarations. // Forward declarations.
class JsonArraySubscript; class JsonArraySubscript;
@ -41,19 +42,18 @@ class JsonVariantSubscripts {
// const JsonObjectSubscript operator[](TKey) const; // const JsonObjectSubscript operator[](TKey) const;
// TKey = const std::string&, const String& // TKey = const std::string&, const String&
template <typename TString> template <typename TString>
FORCE_INLINE typename TypeTraits::EnableIf< FORCE_INLINE
Internals::StringTraits<TString>::has_equals, typename EnableIf<StringTraits<TString>::has_equals,
const JsonObjectSubscript<const TString &> >::type const JsonObjectSubscript<const TString &> >::type
operator[](const TString &key) const { operator[](const TString &key) const {
return impl()->template as<JsonObject>()[key]; return impl()->template as<JsonObject>()[key];
} }
// //
// const JsonObjectSubscript operator[](TKey) const; // const JsonObjectSubscript operator[](TKey) const;
// TKey = const std::string&, const String& // TKey = const std::string&, const String&
template <typename TString> template <typename TString>
FORCE_INLINE typename TypeTraits::EnableIf< FORCE_INLINE typename EnableIf<StringTraits<TString>::has_equals,
Internals::StringTraits<TString>::has_equals, JsonObjectSubscript<const TString &> >::type
JsonObjectSubscript<const TString &> >::type
operator[](const TString &key) { operator[](const TString &key) {
return impl()->template as<JsonObject>()[key]; return impl()->template as<JsonObject>()[key];
} }
@ -61,9 +61,8 @@ class JsonVariantSubscripts {
// JsonObjectSubscript operator[](TKey); // JsonObjectSubscript operator[](TKey);
// TKey = const char*, const char[N], const FlashStringHelper* // TKey = const char*, const char[N], const FlashStringHelper*
template <typename TString> template <typename TString>
FORCE_INLINE typename TypeTraits::EnableIf< FORCE_INLINE typename EnableIf<StringTraits<const TString *>::has_equals,
Internals::StringTraits<const TString *>::has_equals, JsonObjectSubscript<const TString *> >::type
JsonObjectSubscript<const TString *> >::type
operator[](const TString *key) { operator[](const TString *key) {
return impl()->template as<JsonObject>()[key]; return impl()->template as<JsonObject>()[key];
} }
@ -71,10 +70,10 @@ class JsonVariantSubscripts {
// JsonObjectSubscript operator[](TKey); // JsonObjectSubscript operator[](TKey);
// TKey = const char*, const char[N], const FlashStringHelper* // TKey = const char*, const char[N], const FlashStringHelper*
template <typename TString> template <typename TString>
FORCE_INLINE typename TypeTraits::EnableIf< FORCE_INLINE
Internals::StringTraits<TString *>::has_equals, typename EnableIf<StringTraits<TString *>::has_equals,
const JsonObjectSubscript<const TString *> >::type const JsonObjectSubscript<const TString *> >::type
operator[](const TString *key) const { operator[](const TString *key) const {
return impl()->template as<JsonObject>()[key]; return impl()->template as<JsonObject>()[key];
} }
@ -84,3 +83,4 @@ class JsonVariantSubscripts {
} }
}; };
} }
}

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
inline bool isdigit(char c) { inline bool isdigit(char c) {
return '0' <= c && c <= '9'; return '0' <= c && c <= '9';

View File

@ -8,7 +8,7 @@
#include "./ctype.hpp" #include "./ctype.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
inline bool isFloat(const char* s) { inline bool isFloat(const char* s) {
if (!s) return false; if (!s) return false;

View File

@ -7,7 +7,7 @@
#include "./ctype.hpp" #include "./ctype.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
inline bool isInteger(const char* s) { inline bool isInteger(const char* s) {
if (!s) return false; if (!s) return false;

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
template <typename T> template <typename T>
bool isNaN(T x) { bool isNaN(T x) {
return x != x; return x != x;

View File

@ -9,11 +9,11 @@
#include "./math.hpp" #include "./math.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
template <typename T> template <typename T>
inline T parseFloat(const char* s) { inline T parseFloat(const char* s) {
typedef TypeTraits::FloatTraits<T> traits; typedef FloatTraits<T> traits;
typedef typename traits::mantissa_type mantissa_t; typedef typename traits::mantissa_type mantissa_t;
typedef typename traits::exponent_type exponent_t; typedef typename traits::exponent_type exponent_t;

View File

@ -10,7 +10,7 @@
#include "./ctype.hpp" #include "./ctype.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Polyfills { namespace Internals {
template <typename T> template <typename T>
T parseInteger(const char *s) { T parseInteger(const char *s) {
if (!s) return 0; // NULL if (!s) return 0; // NULL

View File

@ -56,7 +56,7 @@ struct FloatParts {
} }
static int16_t normalize(TFloat& value) { static int16_t normalize(TFloat& value) {
typedef TypeTraits::FloatTraits<TFloat> traits; typedef FloatTraits<TFloat> traits;
int16_t powersOf10 = 0; int16_t powersOf10 = 0;
int8_t index = sizeof(TFloat) == 8 ? 8 : 5; int8_t index = sizeof(TFloat) == 8 ? 8 : 5;

View File

@ -29,8 +29,8 @@ template <typename T>
class JsonPrintable { class JsonPrintable {
public: public:
template <typename Print> template <typename Print>
typename TypeTraits::EnableIf<!StringTraits<Print>::has_append, size_t>::type typename EnableIf<!StringTraits<Print>::has_append, size_t>::type printTo(
printTo(Print &print) const { Print &print) const {
JsonWriter<Print> writer(print); JsonWriter<Print> writer(print);
JsonSerializer<JsonWriter<Print> >::serialize(downcast(), writer); JsonSerializer<JsonWriter<Print> >::serialize(downcast(), writer);
return writer.bytesWritten(); return writer.bytesWritten();
@ -55,8 +55,8 @@ class JsonPrintable {
} }
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<StringTraits<TString>::has_append, size_t>::type typename EnableIf<StringTraits<TString>::has_append, size_t>::type printTo(
printTo(TString &str) const { TString &str) const {
DynamicStringBuilder<TString> sb(str); DynamicStringBuilder<TString> sb(str);
return printTo(sb); return printTo(sb);
} }
@ -78,14 +78,14 @@ class JsonPrintable {
} }
template <typename Print> template <typename Print>
typename TypeTraits::EnableIf<!StringTraits<Print>::has_append, size_t>::type typename EnableIf<!StringTraits<Print>::has_append, size_t>::type
prettyPrintTo(Print &print) const { prettyPrintTo(Print &print) const {
IndentedPrint<Print> indentedPrint(print); IndentedPrint<Print> indentedPrint(print);
return prettyPrintTo(indentedPrint); return prettyPrintTo(indentedPrint);
} }
template <typename TString> template <typename TString>
typename TypeTraits::EnableIf<StringTraits<TString>::has_append, size_t>::type typename EnableIf<StringTraits<TString>::has_append, size_t>::type
prettyPrintTo(TString &str) const { prettyPrintTo(TString &str) const {
DynamicStringBuilder<TString> sb(str); DynamicStringBuilder<TString> sb(str);
return prettyPrintTo(sb); return prettyPrintTo(sb);

View File

@ -9,14 +9,15 @@
namespace ArduinoJson { namespace ArduinoJson {
class JsonArray; class JsonArray;
class JsonArraySubscript;
class JsonObject; class JsonObject;
template <typename TKey>
class JsonObjectSubscript;
class JsonVariant; class JsonVariant;
namespace Internals { namespace Internals {
class JsonArraySubscript;
template <typename TKey>
class JsonObjectSubscript;
template <typename Writer> template <typename Writer>
class JsonSerializer { class JsonSerializer {
public: public:

View File

@ -79,14 +79,14 @@ class JsonWriter {
template <typename TFloat> template <typename TFloat>
void writeFloat(TFloat value) { void writeFloat(TFloat value) {
if (Polyfills::isNaN(value)) return writeRaw("NaN"); if (isNaN(value)) return writeRaw("NaN");
if (value < 0.0) { if (value < 0.0) {
writeRaw('-'); writeRaw('-');
value = -value; value = -value;
} }
if (Polyfills::isInfinity(value)) return writeRaw("Infinity"); if (isInfinity(value)) return writeRaw("Infinity");
FloatParts<TFloat> parts(value); FloatParts<TFloat> parts(value);

View File

@ -7,6 +7,7 @@
#include "JsonBufferBase.hpp" #include "JsonBufferBase.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace Internals {
class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> { class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
public: public:
@ -90,6 +91,7 @@ class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
size_t _capacity; size_t _capacity;
size_t _size; size_t _size;
}; };
}
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
@ -105,9 +107,10 @@ class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
// The template paramenter CAPACITY specifies the capacity of the buffer in // The template paramenter CAPACITY specifies the capacity of the buffer in
// bytes. // bytes.
template <size_t CAPACITY> template <size_t CAPACITY>
class StaticJsonBuffer : public StaticJsonBufferBase { class StaticJsonBuffer : public Internals::StaticJsonBufferBase {
public: public:
explicit StaticJsonBuffer() : StaticJsonBufferBase(_buffer, CAPACITY) {} explicit StaticJsonBuffer()
: Internals::StaticJsonBufferBase(_buffer, CAPACITY) {}
private: private:
char _buffer[CAPACITY]; char _buffer[CAPACITY];

View File

@ -49,11 +49,11 @@ struct ArduinoStreamTraits {
}; };
template <typename TStream> template <typename TStream>
struct StringTraits<TStream, struct StringTraits<
// match any type that is derived from Stream: TStream,
typename TypeTraits::EnableIf<TypeTraits::IsBaseOf< // match any type that is derived from Stream:
Stream, typename TypeTraits::RemoveReference< typename EnableIf<
TStream>::type>::value>::type> IsBaseOf<Stream, typename RemoveReference<TStream>::type>::value>::type>
: ArduinoStreamTraits {}; : ArduinoStreamTraits {};
} }
} }

View File

@ -50,14 +50,13 @@ struct CharPointerTraits {
static const bool has_append = false; static const bool has_append = false;
static const bool has_equals = true; static const bool has_equals = true;
static const bool should_duplicate = !TypeTraits::IsConst<TChar>::value; static const bool should_duplicate = !IsConst<TChar>::value;
}; };
// char*, unsigned char*, signed char* // char*, unsigned char*, signed char*
// const char*, const unsigned char*, const signed char* // const char*, const unsigned char*, const signed char*
template <typename TChar> template <typename TChar>
struct StringTraits<TChar*, typename TypeTraits::EnableIf< struct StringTraits<TChar*, typename EnableIf<IsChar<TChar>::value>::type>
TypeTraits::IsChar<TChar>::value>::type>
: CharPointerTraits<TChar> {}; : CharPointerTraits<TChar> {};
} }
} }

View File

@ -48,11 +48,11 @@ struct StdStreamTraits {
}; };
template <typename TStream> template <typename TStream>
struct StringTraits<TStream, struct StringTraits<
// match any type that is derived from std::istream: TStream,
typename TypeTraits::EnableIf<TypeTraits::IsBaseOf< // match any type that is derived from std::istream:
std::istream, typename TypeTraits::RemoveReference< typename EnableIf<IsBaseOf<
TStream>::type>::value>::type> std::istream, typename RemoveReference<TStream>::type>::value>::type>
: StdStreamTraits {}; : StdStreamTraits {};
} }
} }

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that return the type T if Condition is true. // A meta-function that return the type T if Condition is true.
template <bool Condition, typename T = void> template <bool Condition, typename T = void>

View File

@ -10,7 +10,7 @@
#include "../Polyfills/math.hpp" #include "../Polyfills/math.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
template <typename T, size_t = sizeof(T)> template <typename T, size_t = sizeof(T)>
struct FloatTraits {}; struct FloatTraits {};

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that return the type T without the const modifier // A meta-function that return the type T without the const modifier
template <typename T> template <typename T>

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if Derived inherits from TBase is an // A meta-function that returns true if Derived inherits from TBase is an
// integral type. // integral type.

View File

@ -7,7 +7,7 @@
#include "IsSame.hpp" #include "IsSame.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if T is a charater // A meta-function that returns true if T is a charater
template <typename T> template <typename T>

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that return the type T without the const modifier // A meta-function that return the type T without the const modifier
template <typename T> template <typename T>

View File

@ -7,7 +7,7 @@
#include "IsSame.hpp" #include "IsSame.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if T is a floating point type // A meta-function that returns true if T is a floating point type
template <typename T> template <typename T>

View File

@ -9,14 +9,14 @@
#include "IsUnsignedIntegral.hpp" #include "IsUnsignedIntegral.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if T is an integral type. // A meta-function that returns true if T is an integral type.
template <typename T> template <typename T>
struct IsIntegral { struct IsIntegral {
static const bool value = TypeTraits::IsSignedIntegral<T>::value || static const bool value = IsSignedIntegral<T>::value ||
TypeTraits::IsUnsignedIntegral<T>::value || IsUnsignedIntegral<T>::value ||
TypeTraits::IsSame<T, char>::value; IsSame<T, char>::value;
// CAUTION: differs from std::is_integral as it doesn't include bool // CAUTION: differs from std::is_integral as it doesn't include bool
}; };

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if types T and U are the same. // A meta-function that returns true if types T and U are the same.
template <typename T, typename U> template <typename T, typename U>

View File

@ -8,23 +8,21 @@
#include "IsSame.hpp" #include "IsSame.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if T is an integral type. // A meta-function that returns true if T is an integral type.
template <typename T> template <typename T>
struct IsSignedIntegral { struct IsSignedIntegral {
static const bool value = TypeTraits::IsSame<T, signed char>::value || static const bool value =
TypeTraits::IsSame<T, signed short>::value || IsSame<T, signed char>::value || IsSame<T, signed short>::value ||
TypeTraits::IsSame<T, signed int>::value || IsSame<T, signed int>::value || IsSame<T, signed long>::value ||
TypeTraits::IsSame<T, signed long>::value ||
#if ARDUINOJSON_USE_LONG_LONG #if ARDUINOJSON_USE_LONG_LONG
TypeTraits::IsSame<T, signed long long>::value || IsSame<T, signed long long>::value ||
#endif #endif
#if ARDUINOJSON_USE_INT64 #if ARDUINOJSON_USE_INT64
TypeTraits::IsSame<T, signed __int64>::value || IsSame<T, signed __int64>::value ||
#endif #endif
false; false;
}; };
} }
} }

View File

@ -8,23 +8,21 @@
#include "IsSame.hpp" #include "IsSame.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that returns true if T is an integral type. // A meta-function that returns true if T is an integral type.
template <typename T> template <typename T>
struct IsUnsignedIntegral { struct IsUnsignedIntegral {
static const bool value = TypeTraits::IsSame<T, unsigned char>::value || static const bool value =
TypeTraits::IsSame<T, unsigned short>::value || IsSame<T, unsigned char>::value || IsSame<T, unsigned short>::value ||
TypeTraits::IsSame<T, unsigned int>::value || IsSame<T, unsigned int>::value || IsSame<T, unsigned long>::value ||
TypeTraits::IsSame<T, unsigned long>::value ||
#if ARDUINOJSON_USE_LONG_LONG #if ARDUINOJSON_USE_LONG_LONG
TypeTraits::IsSame<T, unsigned long long>::value || IsSame<T, unsigned long long>::value ||
#endif #endif
#if ARDUINOJSON_USE_INT64 #if ARDUINOJSON_USE_INT64
TypeTraits::IsSame<T, unsigned __int64>::value || IsSame<T, unsigned __int64>::value ||
#endif #endif
false; false;
}; };
} }
} }

View File

@ -7,7 +7,7 @@
#include "IsBaseOf.hpp" #include "IsBaseOf.hpp"
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
class JsonVariantTag {}; class JsonVariantTag {};

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that return the type T without the const modifier // A meta-function that return the type T without the const modifier
template <typename T> template <typename T>

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
namespace ArduinoJson { namespace ArduinoJson {
namespace TypeTraits { namespace Internals {
// A meta-function that return the type T without the reference modifier. // A meta-function that return the type T without the reference modifier.
template <typename T> template <typename T>

View File

@ -6,6 +6,8 @@
#include <catch.hpp> #include <catch.hpp>
#include <sstream> #include <sstream>
using namespace ArduinoJson::Internals;
static bool isAligned(void* ptr) { static bool isAligned(void* ptr) {
const size_t mask = sizeof(void*) - 1; const size_t mask = sizeof(void*) - 1;
size_t addr = reinterpret_cast<size_t>(ptr); size_t addr = reinterpret_cast<size_t>(ptr);

View File

@ -5,6 +5,8 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Internals;
struct NoMemoryAllocator { struct NoMemoryAllocator {
void* allocate(size_t) { void* allocate(size_t) {
return NULL; return NULL;

View File

@ -5,7 +5,7 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::TypeTraits; using namespace ArduinoJson::Internals;
TEST_CASE("TypeTraits") { TEST_CASE("TypeTraits") {
SECTION("IsBaseOf") { SECTION("IsBaseOf") {

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Polyfills/isFloat.hpp> #include <ArduinoJson/Polyfills/isFloat.hpp>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Polyfills; using namespace ArduinoJson::Internals;
TEST_CASE("isFloat()") { TEST_CASE("isFloat()") {
SECTION("Input is NULL") { SECTION("Input is NULL") {

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Polyfills/isInteger.hpp> #include <ArduinoJson/Polyfills/isInteger.hpp>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Polyfills; using namespace ArduinoJson::Internals;
TEST_CASE("isInteger()") { TEST_CASE("isInteger()") {
SECTION("Null") { SECTION("Null") {

View File

@ -5,7 +5,7 @@
#include <ArduinoJson/Polyfills/parseFloat.hpp> #include <ArduinoJson/Polyfills/parseFloat.hpp>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Polyfills; using namespace ArduinoJson::Internals;
template <typename T> template <typename T>
void check(const char* input, T expected) { void check(const char* input, T expected) {

View File

@ -6,7 +6,7 @@
#include <ArduinoJson/Polyfills/parseInteger.hpp> #include <ArduinoJson/Polyfills/parseInteger.hpp>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Polyfills; using namespace ArduinoJson::Internals;
template <typename T> template <typename T>
void check(const char* input, T expected) { void check(const char* input, T expected) {

View File

@ -5,6 +5,8 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <catch.hpp> #include <catch.hpp>
using namespace ArduinoJson::Internals;
TEST_CASE("StaticJsonBuffer::startString()") { TEST_CASE("StaticJsonBuffer::startString()") {
SECTION("WorksWhenBufferIsBigEnough") { SECTION("WorksWhenBufferIsBigEnough") {
StaticJsonBuffer<6> jsonBuffer; StaticJsonBuffer<6> jsonBuffer;