Removing virtual methods...

This commit is contained in:
Benoit Blanchon
2014-11-03 12:32:47 +01:00
parent 507f809da0
commit f26f4263ea
7 changed files with 52 additions and 44 deletions

View File

@ -10,7 +10,8 @@
#include "ArduinoJson/JsonBuffer.hpp"
#include "ArduinoJson/JsonObject.hpp"
#include "ArduinoJson/Internals/JsonWriter.hpp"
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
@ -68,7 +69,8 @@ JsonObject &JsonArray::createNestedObject() {
return object;
}
void JsonArray::writeTo(JsonWriter &writer) const {
template <typename T>
void JsonArray::writeTo(T &writer) const {
JsonArrayNode *child = _firstNode;
if (child) {
@ -88,3 +90,6 @@ void JsonArray::writeTo(JsonWriter &writer) const {
writer.writeEmptyArray();
}
}
template void JsonArray::writeTo<CompactJsonWriter>(CompactJsonWriter &) const;
template void JsonArray::writeTo<PrettyJsonWriter>(PrettyJsonWriter &) const;

View File

@ -12,7 +12,8 @@
#include "ArduinoJson/JsonBuffer.hpp"
#include "ArduinoJson/JsonArray.hpp"
#include "ArduinoJson/JsonValue.hpp"
#include "ArduinoJson/Internals/JsonWriter.hpp"
#include "ArduinoJson/Internals/CompactJsonWriter.hpp"
#include "ArduinoJson/Internals/PrettyJsonWriter.hpp"
#include "ArduinoJson/Internals/StringBuilder.hpp"
using namespace ArduinoJson;
@ -91,7 +92,8 @@ void JsonObject::removeNode(JsonObjectNode *nodeToRemove) {
}
}
void JsonObject::writeTo(JsonWriter &writer) const {
template <typename T>
void JsonObject::writeTo(T &writer) const {
JsonObjectNode *node = _firstNode;
if (node) {
@ -113,3 +115,6 @@ void JsonObject::writeTo(JsonWriter &writer) const {
writer.writeEmptyObject();
}
}
template void JsonObject::writeTo(CompactJsonWriter &writer) const;
template void JsonObject::writeTo(PrettyJsonWriter &writer) const;

View File

@ -13,30 +13,3 @@
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
size_t JsonPrintable::printTo(char *buffer, size_t bufferSize) const {
StringBuilder sb(buffer, bufferSize);
return printTo(sb);
}
size_t JsonPrintable::printTo(Print &p) const {
CompactJsonWriter writer(&p);
writeTo(writer);
return writer.bytesWritten();
}
size_t JsonPrintable::prettyPrintTo(char *buffer, size_t bufferSize) const {
StringBuilder sb(buffer, bufferSize);
return prettyPrintTo(sb);
}
size_t JsonPrintable::prettyPrintTo(IndentedPrint &p) const {
PrettyJsonWriter writer(&p);
writeTo(writer);
return writer.bytesWritten();
}
size_t JsonPrintable::prettyPrintTo(Print &print) const {
IndentedPrint indentedPrint = IndentedPrint(print);
return prettyPrintTo(indentedPrint);
}