diff --git a/include/ArduinoJson/Internals/List.hpp b/include/ArduinoJson/Internals/List.hpp index 3e52e5a8..36631b86 100644 --- a/include/ArduinoJson/Internals/List.hpp +++ b/include/ArduinoJson/Internals/List.hpp @@ -33,6 +33,8 @@ class List { const_iterator end() const { return const_iterator(NULL); } protected: + node_type *createNode(); + JsonBuffer *_buffer; node_type *_firstNode; }; diff --git a/include/ArduinoJson/JsonArray.hpp b/include/ArduinoJson/JsonArray.hpp index 9358a138..3b24389c 100644 --- a/include/ArduinoJson/JsonArray.hpp +++ b/include/ArduinoJson/JsonArray.hpp @@ -50,7 +50,6 @@ class JsonArray : public Internals::JsonPrintable, // constructor is private: instance must be created via a JsonBuffer JsonArray(JsonBuffer *buffer) : List(buffer) {} - node_type *createNode(); inline void addNode(node_type *node); static JsonArray _invalid; diff --git a/include/ArduinoJson/JsonObject.hpp b/include/ArduinoJson/JsonObject.hpp index 1e6ed8d3..4d94cd56 100644 --- a/include/ArduinoJson/JsonObject.hpp +++ b/include/ArduinoJson/JsonObject.hpp @@ -55,7 +55,6 @@ class JsonObject : public Internals::JsonPrintable, JsonObject(JsonBuffer *buffer) : List(buffer) {} JsonVariant &add(key_type key) { return (*this)[key]; } - node_type *createNode(); void addNode(node_type *nodeToAdd); void removeNode(node_type *nodeToRemove); diff --git a/src/Internals/List.cpp b/src/Internals/List.cpp index e0581876..07a06284 100644 --- a/src/Internals/List.cpp +++ b/src/Internals/List.cpp @@ -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::size() const { return nodeCount; } +template +Node *List::createNode() { + if (!_buffer) return NULL; + void *ptr = _buffer->alloc(sizeof(node_type)); + return ptr ? new (ptr) node_type() : NULL; +} + template class List; template class List; \ No newline at end of file diff --git a/src/JsonArray.cpp b/src/JsonArray.cpp index 97d46591..33970b2e 100644 --- a/src/JsonArray.cpp +++ b/src/JsonArray.cpp @@ -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; diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index 1ac06717..de8667f3 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -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;