Files
ArduinoJson/JsonGenerator/JsonObjectBase.h

62 lines
1.4 KiB
C
Raw Permalink Normal View History

/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#pragma once
#include "JsonPrintable.h"
2014-08-26 10:13:49 +02:00
#include "JsonValue.h"
#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
{
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
template<typename T>
2014-08-03 13:09:07 +02:00
void add(JsonKey key, T value)
{
2014-07-31 20:11:55 +02:00
operator[](key) = value;
}
template<int DIGITS>
2014-08-03 13:09:07 +02:00
void add(JsonKey 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-03 13:09:07 +02:00
JsonKey key;
2014-08-01 15:22:30 +02:00
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;
2014-08-02 16:25:18 +02:00
2014-08-03 13:09:07 +02:00
KeyValuePair* getMatchingPair(JsonKey key) const;
};
}
}