Extracting a common base class for JsonArray and JsonObject...

This commit is contained in:
Benoit Blanchon
2014-11-05 11:43:59 +01:00
parent 7d73e63c78
commit 0fb4fa8f86
6 changed files with 10 additions and 15 deletions

View File

@ -6,6 +6,7 @@
#include "../../include/ArduinoJson/Internals/List.hpp"
#include "../../include/ArduinoJson/Internals/PlacementNew.hpp"
#include "../../include/ArduinoJson/JsonPair.hpp"
#include "../../include/ArduinoJson/JsonVariant.hpp"
@ -19,5 +20,12 @@ int List<T>::size() const {
return nodeCount;
}
template <typename T>
Node<T> *List<T>::createNode() {
if (!_buffer) return NULL;
void *ptr = _buffer->alloc(sizeof(node_type));
return ptr ? new (ptr) node_type() : NULL;
}
template class List<JsonPair>;
template class List<JsonVariant>;

View File

@ -6,7 +6,6 @@
#include "../include/ArduinoJson/JsonArray.hpp"
#include "../include/ArduinoJson/Internals/PlacementNew.hpp"
#include "../include/ArduinoJson/Internals/PrettyJsonWriter.hpp"
#include "../include/ArduinoJson/JsonBuffer.hpp"
#include "../include/ArduinoJson/JsonObject.hpp"
@ -31,12 +30,6 @@ JsonVariant &JsonArray::add() {
return node->content;
}
JsonArray::node_type *JsonArray::createNode() {
if (!_buffer) return NULL;
void *ptr = _buffer->alloc(sizeof(node_type));
return ptr ? new (ptr) node_type() : NULL;
}
void JsonArray::addNode(node_type *newNode) {
if (_firstNode) {
node_type *lastNode = _firstNode;

View File

@ -69,12 +69,6 @@ JsonObject::node_type *JsonObject::getOrCreateNodeAt(const char *key) {
return newNode;
}
JsonObject::node_type *JsonObject::createNode() {
if (!_buffer) return NULL;
void *ptr = _buffer->alloc(sizeof(node_type));
return ptr ? new (ptr) node_type() : NULL;
}
void JsonObject::addNode(node_type *nodeToAdd) {
if (!_firstNode) {
_firstNode = nodeToAdd;