From f127ef6019ddbd3e07c27e92aa6e8681e3d3774c Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 26 Aug 2014 10:13:49 +0200 Subject: [PATCH] Refactoring... --- JsonGenerator/JsonArrayBase.h | 1 + JsonGenerator/JsonGenerator.vcxproj | 1 + JsonGenerator/JsonGenerator.vcxproj.filters | 3 +++ JsonGenerator/JsonObjectBase.h | 1 + JsonGenerator/JsonPrintable.cpp | 29 +++++++++++++++++++++ JsonGenerator/JsonPrintable.h | 28 +++++--------------- 6 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 JsonGenerator/JsonPrintable.cpp diff --git a/JsonGenerator/JsonArrayBase.h b/JsonGenerator/JsonArrayBase.h index a36c0525..359fd137 100644 --- a/JsonGenerator/JsonArrayBase.h +++ b/JsonGenerator/JsonArrayBase.h @@ -6,6 +6,7 @@ #pragma once #include "JsonPrintable.h" +#include "JsonValue.h" namespace ArduinoJson { diff --git a/JsonGenerator/JsonGenerator.vcxproj b/JsonGenerator/JsonGenerator.vcxproj index bbbb623b..b24261ba 100644 --- a/JsonGenerator/JsonGenerator.vcxproj +++ b/JsonGenerator/JsonGenerator.vcxproj @@ -30,6 +30,7 @@ + diff --git a/JsonGenerator/JsonGenerator.vcxproj.filters b/JsonGenerator/JsonGenerator.vcxproj.filters index 9046b7e3..70143357 100644 --- a/JsonGenerator/JsonGenerator.vcxproj.filters +++ b/JsonGenerator/JsonGenerator.vcxproj.filters @@ -77,5 +77,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/JsonGenerator/JsonObjectBase.h b/JsonGenerator/JsonObjectBase.h index ccfed649..5e27d34f 100644 --- a/JsonGenerator/JsonObjectBase.h +++ b/JsonGenerator/JsonObjectBase.h @@ -6,6 +6,7 @@ #pragma once #include "JsonPrintable.h" +#include "JsonValue.h" #include "EscapedString.h" namespace ArduinoJson diff --git a/JsonGenerator/JsonPrintable.cpp b/JsonGenerator/JsonPrintable.cpp new file mode 100644 index 00000000..beb21454 --- /dev/null +++ b/JsonGenerator/JsonPrintable.cpp @@ -0,0 +1,29 @@ +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include "JsonPrintable.h" +#include "JsonPrettyPrint.h" +#include "StringBuilder.h" + +using namespace ArduinoJson::Generator; +using namespace ArduinoJson::Internals; + +size_t JsonPrintable::printTo(char* buffer, size_t bufferSize) +{ + StringBuilder sb(buffer, bufferSize); + return printTo(sb); +} + +size_t JsonPrintable::prettyPrintTo(IndentedPrint& p) const +{ + JsonPrettyPrint prettyPrint(p); + return printTo(prettyPrint); +} + +size_t JsonPrintable::prettyPrintTo(Print& p) const +{ + IndentedPrint indentedPrint(p); + return printTo(indentedPrint); +} \ No newline at end of file diff --git a/JsonGenerator/JsonPrintable.h b/JsonGenerator/JsonPrintable.h index cac48599..008bad60 100644 --- a/JsonGenerator/JsonPrintable.h +++ b/JsonGenerator/JsonPrintable.h @@ -5,10 +5,9 @@ #pragma once -#include "JsonValue.h" #include "Print.h" #include "Printable.h" -#include "JsonPrettyPrint.h" +#include "IndentedPrint.h" namespace ArduinoJson { @@ -18,27 +17,12 @@ namespace ArduinoJson { public: - size_t printTo(char* buffer, size_t bufferSize) - { - using namespace Internals; - - StringBuilder sb(buffer, bufferSize); - return printTo(sb); - } - - size_t prettyPrintTo(IndentedPrint& p) const - { - JsonPrettyPrint decorator(p); - return printTo(decorator); - } - - size_t prettyPrintTo(Print& p) const - { - IndentedPrint decorator(p); - return printTo(decorator); - } - virtual size_t printTo(Print& p) const = 0; + + size_t printTo(char* buffer, size_t bufferSize); + + size_t prettyPrintTo(IndentedPrint& p) const; + size_t prettyPrintTo(Print& p) const; }; } } \ No newline at end of file