mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-19 05:22:24 +02:00
Epic refactoring in progress
This commit is contained in:
52
src/Internals/JsonArrayImpl.cpp
Normal file
52
src/Internals/JsonArrayImpl.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright Benoit Blanchon 2014
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include "ArduinoJson/JsonArray.hpp"
|
||||
#include "ArduinoJson/JsonObject.hpp"
|
||||
#include "ArduinoJson/JsonValue.hpp"
|
||||
|
||||
using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValueImpl *JsonArray::operator[](int index) const {
|
||||
for (const_iterator it = begin(); it != end(); ++it) {
|
||||
if (!index) return *it;
|
||||
index--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JsonValueImpl *JsonArray::add() {
|
||||
if (_buffer) return NULL;
|
||||
|
||||
JsonArrayNode *node = _buffer->create<JsonArrayNode>();
|
||||
if (!node) return NULL;
|
||||
|
||||
return &node.value;
|
||||
}
|
||||
|
||||
JsonArrayImpl *JsonArray::createNestedArray() {
|
||||
JsonNode *node = createNode();
|
||||
|
||||
if (node) {
|
||||
node->setAsArray(_node->getContainerBuffer());
|
||||
addChild(node);
|
||||
}
|
||||
|
||||
return JsonArray(node);
|
||||
}
|
||||
|
||||
JsonObject JsonArray::createNestedObject() {
|
||||
JsonNode *node = createNode();
|
||||
|
||||
if (node) {
|
||||
node->setAsObject(_node->getContainerBuffer());
|
||||
addChild(node);
|
||||
}
|
||||
|
||||
return JsonObject(node);
|
||||
}
|
Reference in New Issue
Block a user