Files
ArduinoJson/JsonGenerator/JsonObjectBase.h

55 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:
template<typename T>
void add(const char* key, T value)
{
2014-07-31 19:48:51 +02:00
getValue(key) = value;
}
template<int DIGITS>
void add(const char* key, double value)
{
getValue(key).set<DIGITS>(value);
2014-07-31 18:50:01 +02:00
}
using JsonPrintable::printTo;
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)
: items(items), capacity(capacity), count(0)
{
}
Internals::JsonValue& getValue(const char* key);
2014-07-31 18:50:01 +02:00
private:
KeyValuePair* items;
2014-07-14 16:13:58 +02:00
int capacity, count;
};
}
}