Epic refactoring in progress...

This commit is contained in:
Benoit Blanchon
2014-10-28 16:29:55 +01:00
parent 852256c1af
commit 61218f12fd
13 changed files with 63 additions and 32 deletions

View File

@ -13,6 +13,11 @@
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
JsonArrayImpl *JsonArrayImpl::createFrom(JsonBuffer *buffer) {
void *ptr = buffer->alloc(sizeof(JsonArrayImpl));
return ptr ? new (ptr) JsonArrayImpl(buffer) : NULL;
}
int JsonArrayImpl::size() const {
int nodeCount = 0;
for (JsonArrayNode *node = _firstNode; node; node = node->next) nodeCount++;
@ -29,7 +34,7 @@ JsonValueImpl *JsonArrayImpl::operator[](int index) const {
JsonValueImpl *JsonArrayImpl::add() {
if (_buffer) return NULL;
JsonArrayNode *node = new (_buffer) JsonArrayNode();
JsonArrayNode *node = JsonArrayNode::createFrom(_buffer);
if (!node) return NULL;
return &node->value;
@ -39,7 +44,7 @@ JsonArrayImpl *JsonArrayImpl::createNestedArray() {
JsonValueImpl *value = add();
if (!value) return NULL;
JsonArrayImpl *array = new (_buffer) JsonArrayImpl(_buffer);
JsonArrayImpl *array = JsonArrayImpl::createFrom(_buffer);
value->set(array);
return array;
@ -49,7 +54,7 @@ JsonObjectImpl *JsonArrayImpl::createNestedObject() {
JsonValueImpl *value = add();
if (!value) return NULL;
JsonObjectImpl *array = new (_buffer) JsonObjectImpl(_buffer);
JsonObjectImpl *array = JsonObjectImpl::createFrom(_buffer);
value->set(array);
return array;

View File

@ -17,6 +17,11 @@
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
JsonObjectImpl *JsonObjectImpl::createFrom(JsonBuffer *buffer) {
void *ptr = buffer->alloc(sizeof(JsonObjectImpl));
return ptr ? new (ptr) JsonObjectImpl(buffer) : NULL;
}
int JsonObjectImpl::size() const {
int nodeCount = 0;
for (JsonObjectNode *node = _firstNode; node; node = node->next) nodeCount++;
@ -34,7 +39,7 @@ JsonArrayImpl *JsonObjectImpl::createNestedArray(char const *key) {
JsonObjectNode *node = getOrCreateNodeAt(key);
if (!node) return NULL;
JsonArrayImpl *array = new (_buffer) JsonArrayImpl(_buffer);
JsonArrayImpl *array = JsonArrayImpl::createFrom(_buffer);
node->value.set(array);
return array;
@ -44,7 +49,7 @@ JsonObjectImpl *JsonObjectImpl::createNestedObject(const char *key) {
JsonObjectNode *node = getOrCreateNodeAt(key);
if (!node) return NULL;
JsonObjectImpl *object = new (_buffer) JsonObjectImpl(_buffer);
JsonObjectImpl *object = JsonObjectImpl::createFrom(_buffer);
node->value.set(object);
return object;
@ -61,7 +66,7 @@ JsonObjectNode *JsonObjectImpl::getOrCreateNodeAt(const char *key) {
JsonObjectNode *existingNode = getNodeAt(key);
if (existingNode) return existingNode;
JsonObjectNode *newNode = new (_buffer) JsonObjectNode(key);
JsonObjectNode *newNode = JsonObjectNode::createFrom(_buffer, key);
if (newNode) addNode(newNode);

View File

@ -9,9 +9,15 @@
#include "ArduinoJson/Internals/JsonObjectImpl.hpp"
#include "ArduinoJson/Internals/JsonWriter.hpp"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
void JsonValueImpl::writeTo(JsonWriter &writer) const {
JsonValueImpl* JsonValueImpl::createFrom(JsonBuffer* buffer) {
void* ptr = buffer->alloc(sizeof(JsonValueImpl));
return ptr ? new (ptr) JsonValueImpl() : NULL;
}
void JsonValueImpl::writeTo(JsonWriter& writer) const {
switch (_type) {
case JSON_ARRAY:
_content.asArray->writeTo(writer);