source: rtos_arduino/trunk/arduino_lib/libraries/ArduinoJson/include/ArduinoJson/Internals/IndentedPrint.hpp@ 209

Last change on this file since 209 was 209, checked in by ertl-honda, 8 years ago

BlueMix用のフィアルを追加

File size: 1.2 KB
Line 
1// Copyright Benoit Blanchon 2014-2016
2// MIT License
3//
4// Arduino JSON library
5// https://github.com/bblanchon/ArduinoJson
6// If you like this project, please add a star!
7
8#pragma once
9
10#include "../Arduino/Print.hpp"
11
12namespace ArduinoJson {
13namespace Internals {
14
15// Decorator on top of Print to allow indented output.
16// This class is used by JsonPrintable::prettyPrintTo() but can also be used
17// for your own purpose, like logging.
18class IndentedPrint : public Print {
19 public:
20 explicit IndentedPrint(Print &p) : sink(&p) {
21 level = 0;
22 tabSize = 2;
23 isNewLine = true;
24 }
25
26 virtual size_t write(uint8_t);
27
28 // Adds one level of indentation
29 void indent() {
30 if (level < MAX_LEVEL) level++;
31 }
32
33 // Removes one level of indentation
34 void unindent() {
35 if (level > 0) level--;
36 }
37
38 // Set the number of space printed for each level of indentation
39 void setTabSize(uint8_t n) {
40 if (n < MAX_TAB_SIZE) tabSize = n & MAX_TAB_SIZE;
41 }
42
43 private:
44 Print *sink;
45 uint8_t level : 4;
46 uint8_t tabSize : 3;
47 bool isNewLine : 1;
48
49 size_t writeTabs();
50
51 static const int MAX_LEVEL = 15; // because it's only 4 bits
52 static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
53};
54}
55}
Note: See TracBrowser for help on using the repository browser.