mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-20 14:02:24 +02:00
Extracted class JsonHashTableBase to reduce the size of the code.
This commit is contained in:
62
JsonGenerator/JsonHashTableBase.h
Normal file
62
JsonGenerator/JsonHashTableBase.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonObjectBase.h"
|
||||
#include "EscapedString.h"
|
||||
|
||||
namespace ArduinoJson
|
||||
{
|
||||
namespace Generator
|
||||
{
|
||||
class JsonHashTableBase : public JsonObjectBase
|
||||
{
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
void add(const char* key, T value)
|
||||
{
|
||||
if (itemCount >= capacity) return;
|
||||
|
||||
items[itemCount].key.set(key);
|
||||
items[itemCount].value.set(value);
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void add(const char* key, double value)
|
||||
{
|
||||
if (itemCount >= capacity) return;
|
||||
|
||||
items[itemCount].key.set(key);
|
||||
items[itemCount].value.set<DIGITS>(value);
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
using JsonObjectBase::printTo;
|
||||
|
||||
virtual size_t printTo(Print& p) const;
|
||||
|
||||
protected:
|
||||
|
||||
struct KeyValuePair
|
||||
{
|
||||
Internals::EscapedString key;
|
||||
Internals::JsonValue value;
|
||||
};
|
||||
|
||||
JsonHashTableBase(KeyValuePair* items, int capacity)
|
||||
: items(items), capacity(capacity), itemCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
KeyValuePair* items;
|
||||
int itemCount;
|
||||
int capacity;
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user