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