forked from bblanchon/ArduinoJson
Move JsonPrintable into Internals/
This commit is contained in:
@ -6,37 +6,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Internals/IndentedPrint.hpp"
|
||||
#include "Internals/PrettyJsonWriter.hpp"
|
||||
#include "Internals/StringBuilder.hpp"
|
||||
#include "IndentedPrint.hpp"
|
||||
#include "PrettyJsonWriter.hpp"
|
||||
#include "StringBuilder.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename T>
|
||||
class JsonPrintable {
|
||||
public:
|
||||
size_t printTo(Print &print) const {
|
||||
Internals::JsonWriter writer(&print);
|
||||
JsonWriter writer(&print);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
size_t printTo(char *buffer, size_t bufferSize) const {
|
||||
Internals::StringBuilder sb(buffer, bufferSize);
|
||||
StringBuilder sb(buffer, bufferSize);
|
||||
return printTo(sb);
|
||||
}
|
||||
|
||||
size_t prettyPrintTo(Internals::IndentedPrint &print) const {
|
||||
Internals::PrettyJsonWriter writer(&print);
|
||||
size_t prettyPrintTo(IndentedPrint &print) const {
|
||||
PrettyJsonWriter writer(&print);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
|
||||
size_t prettyPrintTo(char *buffer, size_t bufferSize) const {
|
||||
Internals::StringBuilder sb(buffer, bufferSize);
|
||||
StringBuilder sb(buffer, bufferSize);
|
||||
return prettyPrintTo(sb);
|
||||
}
|
||||
size_t prettyPrintTo(Print &print) const {
|
||||
Internals::IndentedPrint indentedPrint = Internals::IndentedPrint(print);
|
||||
IndentedPrint indentedPrint = IndentedPrint(print);
|
||||
return prettyPrintTo(indentedPrint);
|
||||
}
|
||||
|
||||
@ -44,3 +45,4 @@ class JsonPrintable {
|
||||
const T &downcast() const { return *static_cast<const T *>(this); }
|
||||
};
|
||||
}
|
||||
}
|
@ -6,10 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Internals/JsonPrintable.hpp"
|
||||
#include "Internals/ReferenceType.hpp"
|
||||
#include "JsonArrayConstIterator.hpp"
|
||||
#include "JsonArrayIterator.hpp"
|
||||
#include "JsonPrintable.hpp"
|
||||
|
||||
#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
|
||||
(sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(Internals::JsonArrayNode))
|
||||
@ -19,7 +19,7 @@ namespace ArduinoJson {
|
||||
class JsonObject;
|
||||
class JsonBuffer;
|
||||
|
||||
class JsonArray : public JsonPrintable<JsonArray>,
|
||||
class JsonArray : public Internals::JsonPrintable<JsonArray>,
|
||||
public Internals::ReferenceType {
|
||||
friend class JsonBuffer;
|
||||
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Internals/JsonPrintable.hpp"
|
||||
#include "Internals/ReferenceType.hpp"
|
||||
#include "JsonObjectConstIterator.hpp"
|
||||
#include "JsonObjectIterator.hpp"
|
||||
#include "JsonPrintable.hpp"
|
||||
|
||||
#define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \
|
||||
(sizeof(JsonObject) + \
|
||||
@ -20,7 +20,7 @@ namespace ArduinoJson {
|
||||
class JsonArray;
|
||||
class JsonBuffer;
|
||||
|
||||
class JsonObject : public JsonPrintable<JsonObject>,
|
||||
class JsonObject : public Internals::JsonPrintable<JsonObject>,
|
||||
public Internals::ReferenceType {
|
||||
friend class JsonBuffer;
|
||||
|
||||
|
@ -9,16 +9,16 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h> // for uint8_t
|
||||
|
||||
#include "Internals/JsonPrintable.hpp"
|
||||
#include "Internals/JsonVariantContent.hpp"
|
||||
#include "Internals/JsonVariantType.hpp"
|
||||
#include "JsonPrintable.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
class JsonArray;
|
||||
class JsonObject;
|
||||
|
||||
class JsonVariant : public JsonPrintable<JsonVariant> {
|
||||
class JsonVariant : public Internals::JsonPrintable<JsonVariant> {
|
||||
public:
|
||||
JsonVariant() : _type(Internals::JSON_UNDEFINED) {}
|
||||
|
||||
@ -63,11 +63,21 @@ class JsonVariant : public JsonPrintable<JsonVariant> {
|
||||
operator signed char() const { return static_cast<signed char>(as<long>()); }
|
||||
operator signed int() const { return static_cast<signed int>(as<long>()); }
|
||||
operator signed long() const;
|
||||
operator signed short() const { return static_cast<signed short>(as<long>()); }
|
||||
operator unsigned char() const { return static_cast<unsigned char>(as<long>()); }
|
||||
operator unsigned int() const { return static_cast<unsigned int>(as<long>()); }
|
||||
operator unsigned long() const { return static_cast<unsigned long>(as<long>()); }
|
||||
operator unsigned short() const { return static_cast<unsigned short>(as<long>()); }
|
||||
operator signed short() const {
|
||||
return static_cast<signed short>(as<long>());
|
||||
}
|
||||
operator unsigned char() const {
|
||||
return static_cast<unsigned char>(as<long>());
|
||||
}
|
||||
operator unsigned int() const {
|
||||
return static_cast<unsigned int>(as<long>());
|
||||
}
|
||||
operator unsigned long() const {
|
||||
return static_cast<unsigned long>(as<long>());
|
||||
}
|
||||
operator unsigned short() const {
|
||||
return static_cast<unsigned short>(as<long>());
|
||||
}
|
||||
operator const char *() const;
|
||||
operator JsonArray &() const;
|
||||
operator JsonObject &() const;
|
||||
|
Reference in New Issue
Block a user