2014-10-01 16:13:36 +02:00
|
|
|
#include "JsonContainer.h"
|
|
|
|
|
2014-10-01 16:56:22 +02:00
|
|
|
#include "JsonBuffer.h"
|
2014-10-05 16:25:49 +02:00
|
|
|
#include "Internals/JsonWriter.h"
|
2014-10-01 16:13:36 +02:00
|
|
|
#include "Internals/StringBuilder.h"
|
|
|
|
|
|
|
|
size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const
|
|
|
|
{
|
|
|
|
ArduinoJson::Internals::StringBuilder sb(buffer, bufferSize);
|
|
|
|
return printTo(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::printTo(Print& p) const
|
|
|
|
{
|
2014-10-05 16:25:49 +02:00
|
|
|
JsonWriter writer(p);
|
|
|
|
_node->writeTo(writer);
|
|
|
|
return writer.bytesWritten();
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode* JsonContainer::createNode(JsonNodeType type)
|
|
|
|
{
|
|
|
|
JsonBuffer* buffer = _node->content.asContainer.buffer;
|
2014-10-05 15:02:40 +02:00
|
|
|
return buffer->createNode(type);
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonContainer::checkNodeType(JsonNodeType expectedType)
|
|
|
|
{
|
|
|
|
return _node && _node->type == expectedType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonContainer::operator==(const JsonContainer & other) const
|
|
|
|
{
|
|
|
|
return _node == other._node;
|
|
|
|
}
|
|
|
|
|
2014-10-05 14:48:19 +02:00
|
|
|
void JsonContainer::addChild(JsonNode* newChild)
|
2014-10-01 16:56:22 +02:00
|
|
|
{
|
2014-10-05 14:48:19 +02:00
|
|
|
JsonNode* lastChild = _node->content.asContainer.child;
|
|
|
|
|
|
|
|
if (!lastChild)
|
|
|
|
{
|
|
|
|
_node->content.asContainer.child = newChild = newChild;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (lastChild->next)
|
|
|
|
lastChild = lastChild->next;
|
|
|
|
|
|
|
|
lastChild->next = newChild;
|
2014-10-01 16:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JsonContainer::removeChildAfter(JsonNode* child, JsonNode* previous)
|
|
|
|
{
|
|
|
|
if (previous)
|
|
|
|
previous->next = child->next;
|
|
|
|
else
|
|
|
|
_node->content.asContainer.child = child->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonContainer::size() const
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
|
|
|
{
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|