Extracted class JsonArrayBase to reduce code size

This commit is contained in:
Benoît Blanchon
2014-07-08 13:38:37 +02:00
parent bbc18b5ca4
commit 5bb6cd0fa9
9 changed files with 103 additions and 57 deletions

View File

@ -0,0 +1,49 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#pragma once
#include "JsonObjectBase.h"
namespace ArduinoJson
{
namespace Generator
{
class JsonArrayBase : public JsonObjectBase
{
public:
JsonArrayBase(Internals::JsonValue* items, int capacity)
: items(items), capacity(capacity), count(0)
{
}
template<typename T>
void add(T value)
{
if (count >= capacity) return;
items[count++].set(value);
}
template<int DIGITS>
void add(double value)
{
if (count >= capacity) return;
Internals::JsonValue& v = items[count++];
v.set<DIGITS>(value);
}
virtual size_t printTo(Print& p) const;
using JsonObjectBase::printTo;
private:
Internals::JsonValue* items;
int count, capacity;
};
}
}