Files
ArduinoJson/srcs/StaticJsonBuffer.h

41 lines
610 B
C
Raw Normal View History

2014-09-27 09:56:53 +02:00
#pragma once
#include "JsonBuffer.h"
#include "JsonObject.h"
2014-09-27 09:56:53 +02:00
template<int CAPACITY>
class StaticJsonBuffer : public JsonBuffer
2014-09-27 09:56:53 +02:00
{
friend JsonObject;
2014-09-27 09:56:53 +02:00
public:
2014-09-27 09:58:34 +02:00
explicit StaticJsonBuffer()
: _size(0)
{
}
2014-09-27 09:56:53 +02:00
virtual ~StaticJsonBuffer() {}
int capacity()
{
return CAPACITY;
}
int size()
{
return _size;
}
protected:
virtual JsonNode* allocateNode()
{
if (_size >= CAPACITY) return 0;
return &_buffer[_size++];
}
2014-09-27 09:56:53 +02:00
private:
JsonNode _buffer[CAPACITY];
2014-09-27 09:56:53 +02:00
int _size;
};