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 13:53:30 +02:00
|
|
|
void add(const char* value)
|
2014-06-24 13:34:55 +02:00
|
|
|
{
|
2014-06-27 13:43:26 +02:00
|
|
|
add(JsonValue(value));
|
2014-06-24 13:53:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void add(double value)
|
|
|
|
{
|
2014-06-27 13:43:26 +02:00
|
|
|
add(JsonValue(value));
|
2014-06-24 13:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-06-24 21:15:07 +02:00
|
|
|
void add(bool value)
|
|
|
|
{
|
2014-06-27 13:43:26 +02:00
|
|
|
add(JsonValue(value));
|
2014-06-24 21:15:07 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 13:28:56 +02:00
|
|
|
void add(JsonObjectBase& value)
|
|
|
|
{
|
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-06-25 13:23:08 +02:00
|
|
|
virtual void writeTo(StringBuilder& sb)
|
2014-06-25 13:02:39 +02:00
|
|
|
{
|
|
|
|
sb.append("[");
|
2014-06-24 13:34:55 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < itemCount; i++)
|
|
|
|
{
|
2014-06-25 13:23:08 +02:00
|
|
|
if (i>0) sb.append(",");
|
2014-06-27 13:42:26 +02:00
|
|
|
items[i].writeTo(sb);
|
2014-06-24 13:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 13:02:39 +02:00
|
|
|
sb.append("]");
|
2014-06-24 13:34:55 +02:00
|
|
|
}
|
2014-06-24 13:19:23 +02:00
|
|
|
};
|
|
|
|
|