2014-06-24 13:19:23 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-06-25 13:23:08 +02:00
|
|
|
#include "JsonObjectBase.h"
|
2014-06-25 13:02:39 +02:00
|
|
|
#include "StringBuilder.h"
|
2014-06-24 13:53:30 +02:00
|
|
|
|
2014-06-24 13:34:55 +02:00
|
|
|
template<int N>
|
2014-06-25 13:23:08 +02:00
|
|
|
class JsonArray : public JsonObjectBase
|
2014-06-24 13:19:23 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-06-24 13:34:55 +02:00
|
|
|
JsonArray()
|
|
|
|
{
|
|
|
|
itemCount = 0;
|
|
|
|
}
|
2014-06-24 21:15:07 +02:00
|
|
|
|
2014-06-27 13:45:50 +02:00
|
|
|
template<typename T>
|
|
|
|
void add(T value)
|
2014-06-25 13:28:56 +02:00
|
|
|
{
|
2014-06-27 13:43:26 +02:00
|
|
|
add(JsonValue(value));
|
2014-06-27 13:42:26 +02:00
|
|
|
}
|
|
|
|
|
2014-06-27 13:43:26 +02:00
|
|
|
void add(JsonValue value)
|
2014-06-27 13:42:26 +02:00
|
|
|
{
|
|
|
|
if (itemCount >= N) return;
|
|
|
|
|
|
|
|
items[itemCount] = value;
|
|
|
|
itemCount++;
|
2014-06-25 13:28:56 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 13:39:05 +02:00
|
|
|
using JsonObjectBase::writeTo;
|
2014-06-24 13:34:55 +02:00
|
|
|
|
2014-06-25 13:02:39 +02:00
|
|
|
private:
|
2014-06-27 13:18:38 +02:00
|
|
|
JsonValue items[N];
|
2014-06-25 13:02:39 +02:00
|
|
|
int itemCount;
|
|
|
|
|
2014-07-01 13:44:36 +02:00
|
|
|
virtual size_t writeTo(Print& p) const
|
2014-06-25 13:02:39 +02:00
|
|
|
{
|
2014-07-01 13:15:50 +02:00
|
|
|
size_t n = 0;
|
|
|
|
|
2014-07-01 13:36:22 +02:00
|
|
|
n += p.write("[");
|
2014-06-24 13:34:55 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < itemCount; i++)
|
|
|
|
{
|
2014-07-01 13:15:50 +02:00
|
|
|
if (i > 0)
|
|
|
|
{
|
2014-07-01 13:36:22 +02:00
|
|
|
n += p.write(",");
|
2014-07-01 13:15:50 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 13:36:22 +02:00
|
|
|
n += items[i].writeTo(p);
|
2014-06-24 13:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 13:36:22 +02:00
|
|
|
n += p.write("]");
|
2014-07-01 13:15:50 +02:00
|
|
|
|
|
|
|
return n;
|
2014-06-24 13:34:55 +02:00
|
|
|
}
|
2014-06-24 13:19:23 +02:00
|
|
|
};
|
|
|
|
|