JsonParserGeneratorRK
spark_wiring_print.h
Go to the documentation of this file.
1 
27 #ifndef __SPARK_WIRING_PRINTx_
28 #define __SPARK_WIRING_PRINT_
29 
30 #include <stddef.h>
31 #include <string.h>
32 #include <stdint.h> // for uint8_t
33 
34 #include "spark_wiring_string.h"
35 #include "spark_wiring_printable.h"
36 
37 const unsigned char DEC = 10;
38 const unsigned char HEX = 16;
39 const unsigned char OCT = 8;
40 const unsigned char BIN = 2;
41 
42 class String;
43 class __FlashStringHelper;
44 
50 class Print
51 {
52  private:
53  int write_error;
54  size_t printNumber(unsigned long, uint8_t);
55  size_t printFloat(double, uint8_t);
56  protected:
57 #ifndef DOXYGEN_DO_NOT_DOCUMENT
58  void setWriteError(int err = 1) { write_error = err; }
59  size_t printf_impl(bool newline, const char* format, ...);
60 #endif
61 
62  public:
63 #ifndef DOXYGEN_DO_NOT_DOCUMENT
64  Print() : write_error(0) {}
65 
66  virtual ~Print() {}
67 #endif
68 
71  int getWriteError() { return write_error; }
72 
76  void clearWriteError() { setWriteError(0); }
77 
83  virtual size_t write(uint8_t c) = 0;
84 
90  size_t write(const char *str) {
91  if (str == NULL) return 0;
92  return write((const uint8_t *)str, strlen(str));
93  }
94 
101  virtual size_t write(const uint8_t *buffer, size_t size);
102 
106  size_t print(const char[]);
107 
111  size_t print(char);
112 
120  size_t print(unsigned char value, int base = DEC);
121 
129  size_t print(int value, int base = DEC);
130 
138  size_t print(unsigned int value, int base = DEC);
139 
147  size_t print(long value, int base = DEC);
148 
156  size_t print(unsigned long value, int base = DEC);
157 
164  size_t print(double value, int dec = 2);
165 
169  size_t print(const Printable&);
170 
171 #ifndef DOXYGEN_DO_NOT_DOCUMENT
172  size_t print(const __FlashStringHelper*);
173 #endif
174 
178  size_t println(const char[]);
179 
183  size_t println(char value);
184 
192  size_t println(unsigned char value, int base = DEC);
200  size_t println(int value, int base = DEC);
201 
209  size_t println(unsigned int value, int base = DEC);
217  size_t println(long value, int base = DEC);
225  size_t println(unsigned long value, int base = DEC);
226 
233  size_t println(double value, int dec = 2);
237  size_t println(const Printable&);
238 
242  size_t println(void);
243 
244 #ifndef DOXYGEN_DO_NOT_DOCUMENT
245  size_t println(const __FlashStringHelper*);
246 #endif
247 
255  template <typename... Args>
256  inline size_t printf(const char* format, Args... args)
257  {
258  return this->printf_impl(false, format, args...);
259  }
260 
268  template <typename... Args>
269  inline size_t printlnf(const char* format, Args... args)
270  {
271  return this->printf_impl(true, format, args...);
272  }
273 
274 };
275 
276 #endif
size_t write(const char *str)
Write a null-terminated c-string the stream or file.
Definition: spark_wiring_print.h:90
const unsigned char HEX
Hexadecimal number format (0-9, a-f)
Definition: spark_wiring_print.h:38
The Printable class provides a way for new classes to allow themselves to be printed.
Definition: spark_wiring_printable.h:41
size_t println(void)
Print a CRLF end-of-line terminator to the stream or file.
size_t printf(const char *format, Args... args)
Print using printf-style formatting to the stream or file.
Definition: spark_wiring_print.h:256
Class for printing to a stream or file.
Definition: spark_wiring_print.h:50
Header for spark_wiring_printable.cpp module.
int getWriteError()
Return the last error code. 0 means no error.
Definition: spark_wiring_print.h:71
size_t print(const char[])
Print a null-terminated array of char variables (a c-string) to the stream or file.
const unsigned char BIN
Binary number format (0-1)
Definition: spark_wiring_print.h:40
Wiring String: A class to hold and manipulate a dynamically allocated string.
Definition: spark_wiring_string.h:54
void clearWriteError()
Clear the last error code to 0.
Definition: spark_wiring_print.h:76
virtual size_t write(uint8_t c)=0
Write a single byte to the stream or file.
const unsigned char OCT
Octal number format (0-7)
Definition: spark_wiring_print.h:39
const unsigned char DEC
Decimal number format (0-9)
Definition: spark_wiring_print.h:37
size_t printlnf(const char *format, Args... args)
Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file...
Definition: spark_wiring_print.h:269