IsolatedEthernet
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"
36
37const unsigned char DEC = 10;
38const unsigned char HEX = 16;
39const unsigned char OCT = 8;
40const unsigned char BIN = 2;
41
42class String;
43class __FlashStringHelper;
44
50class 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
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
Class for printing to a stream or file.
Definition: spark_wiring_print.h:51
size_t println(unsigned char value, int base=DEC)
Print an unsigned char (byte value. 8 bits) in the specified base plus a CRLF end-of-line terminator ...
size_t printf(const char *format, Args... args)
Print using printf-style formatting to the stream or file.
Definition: spark_wiring_print.h:256
size_t print(long value, int base=DEC)
Print a long (32 bit integer) the specified base to the stream or file.
size_t println(void)
Print a CRLF end-of-line terminator to the stream or file.
size_t println(double value, int dec=2)
Print a double floating point value plus a CRLF end-of-line terminator to the stream or file.
size_t print(char)
Print a single character to the stream or file.
size_t println(const Printable &)
Print an object derived from Printable plus a CRLF end-of-line terminator to the stream or file.
size_t println(unsigned int value, int base=DEC)
Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator...
size_t write(const char *str)
Write a null-terminated c-string the stream or file.
Definition: spark_wiring_print.h:90
size_t println(char value)
Print a single character plus a CRLF end-of-line terminator to the stream or file.
size_t println(int value, int base=DEC)
Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or ...
size_t println(long value, int base=DEC)
Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the str...
virtual size_t write(const uint8_t *buffer, size_t size)
Write a bytes specified by a buffer and length to the stream or file.
int getWriteError()
Return the last error code. 0 means no error.
Definition: spark_wiring_print.h:71
size_t print(const Printable &)
Print an object derived from Printable to the stream or file.
size_t print(int value, int base=DEC)
Print an int (32 bit integer) the specified base to the stream or file.
virtual size_t write(uint8_t c)=0
Write a single byte to the stream or file.
size_t print(unsigned long value, int base=DEC)
Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file.
size_t print(const char[])
Print a null-terminated array of char variables (a c-string) to the stream or file.
size_t println(const char[])
Print a null-terminated array of char variables (a c-string) plus a CRLF end-of-line terminator to th...
size_t print(double value, int dec=2)
Print a double floating point value to the stream or file.
size_t print(unsigned char value, int base=DEC)
Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file.
void clearWriteError()
Clear the last error code to 0.
Definition: spark_wiring_print.h:76
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
size_t println(unsigned long value, int base=DEC)
Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator...
size_t print(unsigned int value, int base=DEC)
Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file.
The Printable class provides a way for new classes to allow themselves to be printed.
Definition: spark_wiring_printable.h:42
const unsigned char DEC
Decimal (base 10)
Definition: spark_wiring_print.h:37
const unsigned char HEX
Hexadecial (base 16)
Definition: spark_wiring_print.h:38
const unsigned char BIN
Binary (base 2)
Definition: spark_wiring_print.h:40
const unsigned char OCT
Octal (base 8)
Definition: spark_wiring_print.h:39
Header for spark_wiring_printable.cpp module.