2014-07-08 13:27:29 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-07-17 13:16:14 +02:00
|
|
|
#include "JsonPrintable.h"
|
2014-07-08 13:27:29 +02:00
|
|
|
#include "EscapedString.h"
|
|
|
|
|
|
|
|
namespace ArduinoJson
|
|
|
|
{
|
|
|
|
namespace Generator
|
|
|
|
{
|
2014-07-22 21:02:16 +02:00
|
|
|
class JsonObjectBase : public JsonPrintable
|
2014-07-08 13:27:29 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void add(const char* key, T value)
|
|
|
|
{
|
2014-07-08 13:38:37 +02:00
|
|
|
if (count >= capacity) return;
|
2014-07-08 13:27:29 +02:00
|
|
|
|
2014-07-08 13:38:37 +02:00
|
|
|
items[count].key.set(key);
|
|
|
|
items[count].value.set(value);
|
|
|
|
count++;
|
2014-07-08 13:27:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int DIGITS>
|
|
|
|
void add(const char* key, double value)
|
|
|
|
{
|
2014-07-08 13:38:37 +02:00
|
|
|
if (count >= capacity) return;
|
2014-07-08 13:27:29 +02:00
|
|
|
|
2014-07-08 13:38:37 +02:00
|
|
|
items[count].key.set(key);
|
|
|
|
items[count].value.set<DIGITS>(value);
|
|
|
|
count++;
|
2014-07-08 13:27:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-17 13:16:14 +02:00
|
|
|
using JsonPrintable::printTo;
|
2014-07-08 13:27:29 +02:00
|
|
|
|
|
|
|
virtual size_t printTo(Print& p) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
struct KeyValuePair
|
|
|
|
{
|
|
|
|
Internals::EscapedString key;
|
|
|
|
Internals::JsonValue value;
|
|
|
|
};
|
|
|
|
|
2014-07-22 21:02:16 +02:00
|
|
|
JsonObjectBase(KeyValuePair* items, int capacity)
|
2014-07-08 13:38:37 +02:00
|
|
|
: items(items), capacity(capacity), count(0)
|
2014-07-08 13:27:29 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
KeyValuePair* items;
|
2014-07-14 16:13:58 +02:00
|
|
|
int capacity, count;
|
2014-07-08 13:27:29 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|