Files
ArduinoJson/JsonGenerator/JsonObjectBase.h

57 lines
1.2 KiB
C
Raw Normal View History

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