forked from bblanchon/ArduinoJson
Removing virtual methods...
This commit is contained in:
@ -19,7 +19,8 @@ namespace ArduinoJson {
|
||||
class JsonObject;
|
||||
class JsonBuffer;
|
||||
|
||||
class JsonArray : public JsonPrintable, public Internals::ReferenceType {
|
||||
class JsonArray : public JsonPrintable<JsonArray>,
|
||||
public Internals::ReferenceType {
|
||||
friend class JsonBuffer;
|
||||
|
||||
public:
|
||||
@ -55,7 +56,8 @@ class JsonArray : public JsonPrintable, public Internals::ReferenceType {
|
||||
|
||||
static JsonArray &invalid() { return _invalid; }
|
||||
|
||||
virtual void writeTo(Internals::JsonWriter &writer) const;
|
||||
template <typename T>
|
||||
void writeTo(T &writer) const;
|
||||
|
||||
private:
|
||||
// constructor is private: instance must be created via a JsonBuffer
|
||||
|
@ -20,7 +20,8 @@ namespace ArduinoJson {
|
||||
class JsonArray;
|
||||
class JsonBuffer;
|
||||
|
||||
class JsonObject : public JsonPrintable, public Internals::ReferenceType {
|
||||
class JsonObject : public JsonPrintable<JsonObject>,
|
||||
public Internals::ReferenceType {
|
||||
friend class JsonBuffer;
|
||||
|
||||
public:
|
||||
@ -55,7 +56,8 @@ class JsonObject : public JsonPrintable, public Internals::ReferenceType {
|
||||
|
||||
static JsonObject &invalid() { return _invalid; }
|
||||
|
||||
virtual void writeTo(Internals::JsonWriter &writer) const;
|
||||
template <typename T>
|
||||
void writeTo(T &writer) const;
|
||||
|
||||
private:
|
||||
// constructor is private, instance must be created via JsonBuffer
|
||||
|
@ -7,24 +7,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino/Printable.hpp"
|
||||
#include "Internals/StringBuilder.hpp"
|
||||
#include "Internals/IndentedPrint.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
namespace Internals {
|
||||
class IndentedPrint;
|
||||
class JsonWriter;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class JsonPrintable : public Printable {
|
||||
public:
|
||||
size_t printTo(char *buffer, size_t bufferSize) const;
|
||||
virtual size_t printTo(Print &print) const;
|
||||
size_t printTo(Print &print) const {
|
||||
CompactJsonWriter writer(&p);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
size_t printTo(char *buffer, size_t bufferSize) const {
|
||||
Internals::StringBuilder sb(buffer, bufferSize);
|
||||
return printTo(sb);
|
||||
}
|
||||
|
||||
size_t prettyPrintTo(char *buffer, size_t bufferSize) const;
|
||||
size_t prettyPrintTo(Internals::IndentedPrint &print) const;
|
||||
size_t prettyPrintTo(Print &print) const;
|
||||
size_t prettyPrintTo(Internals::IndentedPrint &print) const {
|
||||
PrettyJsonWriter writer(&p);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void writeTo(Internals::JsonWriter &) const = 0;
|
||||
size_t prettyPrintTo(char *buffer, size_t bufferSize) const {
|
||||
Internals::StringBuilder sb(buffer, bufferSize);
|
||||
return prettyPrintTo(sb);
|
||||
}
|
||||
size_t prettyPrintTo(Print &print) const {
|
||||
Internals::IndentedPrint indentedPrint = Internals::IndentedPrint(print);
|
||||
return prettyPrintTo(indentedPrint);
|
||||
}
|
||||
|
||||
private:
|
||||
const T &downcast() { return *static_cast<const T *>(this); }
|
||||
};
|
||||
}
|
||||
|
@ -68,7 +68,8 @@ class JsonValue {
|
||||
|
||||
bool success() { return _type != Internals::JSON_INVALID; }
|
||||
|
||||
void writeTo(Internals::JsonWriter &writer) const;
|
||||
template <typename T>
|
||||
void writeTo(T &writer) const;
|
||||
|
||||
private:
|
||||
JsonValue(Internals::JsonValueType type) : _type(type) {}
|
||||
|
Reference in New Issue
Block a user