Files
ArduinoJson/JsonGenerator/IndentedPrint.h

54 lines
1.3 KiB
C
Raw Normal View History

/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#pragma once
#include "Print.h"
namespace ArduinoJson
{
namespace Generator
{
2014-09-01 21:36:09 +02:00
// Decorator on top of Print to allow indented output.
// This class is used by JsonPrintable::prettyPrintTo() but can also be used
// for your own purpose, like logging.
class IndentedPrint : public Print
{
public:
IndentedPrint(Print& p)
: sink(p)
{
level = 0;
2014-08-26 11:59:41 +02:00
tabSize = 2;
isNewLine = true;
}
virtual size_t write(uint8_t);
2014-08-26 09:53:32 +02:00
2014-09-01 21:36:09 +02:00
// Adds one level of indentation
void indent();
2014-09-01 21:36:09 +02:00
// Removes one level of indentation
void unindent();
2014-09-01 21:36:09 +02:00
// Set the number of space printed for each level of indentation
2014-08-26 11:58:33 +02:00
void setTabSize(uint8_t n);
private:
Print& sink;
2014-08-26 11:58:33 +02:00
uint8_t level : 4;
uint8_t tabSize : 3;
bool isNewLine : 1;
2014-08-26 11:58:33 +02:00
size_t writeTabs();
2014-08-26 11:58:33 +02:00
2014-08-26 12:03:50 +02:00
static const int MAX_LEVEL = 15; // because it's only 4 bits
static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
};
}
}