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-08-26 10:13:49 +02:00
|
|
|
#include "JsonValue.h"
|
2014-07-08 13:27:29 +02:00
|
|
|
#include "EscapedString.h"
|
|
|
|
|
|
|
|
namespace ArduinoJson
|
|
|
|
{
|
|
|
|
namespace Generator
|
|
|
|
{
|
2014-08-03 13:09:07 +02:00
|
|
|
typedef const char* JsonKey;
|
|
|
|
|
2014-07-22 21:02:16 +02:00
|
|
|
class JsonObjectBase : public JsonPrintable
|
2014-07-08 13:27:29 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-08-03 13:09:07 +02:00
|
|
|
JsonValue& operator[](JsonKey);
|
|
|
|
bool containsKey(JsonKey) const;
|
2014-08-03 13:16:35 +02:00
|
|
|
void remove(JsonKey key);
|
2014-08-02 16:11:02 +02:00
|
|
|
|
2014-07-08 13:27:29 +02:00
|
|
|
template<typename T>
|
2014-08-03 13:09:07 +02:00
|
|
|
void add(JsonKey key, T value)
|
2014-07-08 13:27:29 +02:00
|
|
|
{
|
2014-07-31 20:11:55 +02:00
|
|
|
operator[](key) = value;
|
2014-07-08 13:27:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int DIGITS>
|
2014-08-03 13:09:07 +02:00
|
|
|
void add(JsonKey key, double value)
|
2014-07-08 13:27:29 +02:00
|
|
|
{
|
2014-07-31 20:11:55 +02:00
|
|
|
operator[](key).set<DIGITS>(value);
|
2014-07-31 19:57:52 +02:00
|
|
|
}
|
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
|
|
|
|
{
|
2014-08-03 13:09:07 +02:00
|
|
|
JsonKey key;
|
2014-08-01 15:22:30 +02:00
|
|
|
JsonValue value;
|
2014-07-08 13:27:29 +02:00
|
|
|
};
|
|
|
|
|
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-08-02 15:55:46 +02:00
|
|
|
static JsonValue nullValue;
|
2014-08-02 16:25:18 +02:00
|
|
|
|
2014-08-03 13:09:07 +02:00
|
|
|
KeyValuePair* getMatchingPair(JsonKey key) const;
|
2014-07-08 13:27:29 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|