mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 12:32:17 +02:00
Moved implementation is a new folder
This commit is contained in:
61
JsonGenerator/JsonArray.h
Normal file
61
JsonGenerator/JsonArray.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonObjectBase.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
template<int N>
|
||||
class JsonArray : public JsonObjectBase
|
||||
{
|
||||
public:
|
||||
JsonArray()
|
||||
{
|
||||
itemCount = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add(T value)
|
||||
{
|
||||
add(JsonValue(value));
|
||||
}
|
||||
|
||||
void add(JsonValue value)
|
||||
{
|
||||
if (itemCount >= N) return;
|
||||
|
||||
items[itemCount] = value;
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
using JsonObjectBase::writeTo;
|
||||
|
||||
private:
|
||||
JsonValue items[N];
|
||||
int itemCount;
|
||||
|
||||
virtual size_t writeTo(Print& p) const
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
n += p.write("[");
|
||||
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
n += p.write(",");
|
||||
}
|
||||
|
||||
n += items[i].writeTo(p);
|
||||
}
|
||||
|
||||
n += p.write("]");
|
||||
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user