2014-10-05 14:40:03 +02:00
|
|
|
#include "JsonArray.h"
|
|
|
|
|
2014-10-07 15:27:24 +02:00
|
|
|
#include "JsonObject.h"
|
2014-10-05 14:55:14 +02:00
|
|
|
#include "JsonValue.h"
|
|
|
|
|
|
|
|
JsonValue JsonArray::operator[](int index) const
|
|
|
|
{
|
|
|
|
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
|
|
|
{
|
|
|
|
if (!index) return JsonValue(*it);
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JsonValue();
|
2014-10-05 15:02:40 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 15:04:17 +02:00
|
|
|
void JsonArray::add(bool value)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
2014-10-05 15:04:17 +02:00
|
|
|
if (!node) return;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
node->setAsBoolean(value);
|
2014-10-05 15:04:17 +02:00
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
2014-10-05 15:02:40 +02:00
|
|
|
void JsonArray::add(char const* value)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
2014-10-05 15:02:40 +02:00
|
|
|
if (!node) return;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
node->setAsString(value);
|
2014-10-05 15:02:40 +02:00
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(double value, int decimals)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
2014-10-05 15:02:40 +02:00
|
|
|
if (!node) return;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
node->setAsDouble(value, decimals);
|
2014-10-05 15:02:40 +02:00
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(long value)
|
|
|
|
{
|
2014-10-09 14:17:09 +02:00
|
|
|
JsonNode* node = createNode();
|
2014-10-05 15:02:40 +02:00
|
|
|
if (!node) return;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
node->setAsLong(value);
|
2014-10-05 15:02:40 +02:00
|
|
|
addChild(node);
|
2014-10-05 15:13:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 18:20:40 +02:00
|
|
|
// TODO: we should have the same issue as in JsonValue
|
2014-10-09 12:14:10 +02:00
|
|
|
void JsonArray::add(JsonContainer nestedContainer)
|
2014-10-05 15:13:00 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
2014-10-05 15:13:00 +02:00
|
|
|
if (!node) return;
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
*node = *nestedContainer._node;
|
2014-10-05 15:13:00 +02:00
|
|
|
addChild(node);
|
2014-10-07 11:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonArray JsonArray::createNestedArray()
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node->setAsArray(_node->getContainerBuffer());
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
2014-10-07 11:22:10 +02:00
|
|
|
return JsonArray(node);
|
2014-10-07 15:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonObject JsonArray::createNestedObject()
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonNode* node = createNode();
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node->setAsObject(_node->getContainerBuffer());
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:27:24 +02:00
|
|
|
return JsonObject(node);
|
2014-10-05 14:55:14 +02:00
|
|
|
}
|