diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2011-08-26 16:08:14 -0400 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2011-08-26 16:08:14 -0400 |
commit | 5130a1329462aa36d5f18e31851d3d9d5086e411 (patch) | |
tree | 373c33573e5e998d7febe50bc94526e63a61de57 /cores/arduino/Print.h | |
parent | 0635790dd111e91e5c488acc599cc404dc707abd (diff) |
Moving write errors out of return value into separate API methods.
write(), print(), println() now return size_t (and don't use negative values to signal errors).
Print adds writeError() for checking for write errors, clearWriteError() to reset the flag to false, and a protected setWriteError() for signalling errors.
http://code.google.com/p/arduino/issues/detail?id=598
Diffstat (limited to 'cores/arduino/Print.h')
-rwxr-xr-x | cores/arduino/Print.h | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index 3f303f3..fce302e 100755 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -23,8 +23,6 @@ #include <inttypes.h> #include <stdio.h> // for size_t -typedef int ssize_t; - #include "WString.h" #include "Printable.h" @@ -36,37 +34,45 @@ typedef int ssize_t; class Print { private: - ssize_t printNumber(unsigned long, uint8_t); - ssize_t printFloat(double, uint8_t); + int write_error; + size_t printNumber(unsigned long, uint8_t); + size_t printFloat(double, uint8_t); + protected: + void setWriteError(int err = 1) { write_error = err; } public: - virtual ssize_t write(uint8_t) = 0; - virtual ssize_t write(const char *str); - virtual ssize_t write(const uint8_t *buffer, size_t size); + Print() : write_error(0) {} + + int writeError() { return write_error; } + void clearWriteError() { setWriteError(0); } + + virtual size_t write(uint8_t) = 0; + virtual size_t write(const char *str); + virtual size_t write(const uint8_t *buffer, size_t size); - ssize_t print(const __FlashStringHelper *); - ssize_t print(const String &); - ssize_t print(const char[]); - ssize_t print(char); - ssize_t print(unsigned char, int = DEC); - ssize_t print(int, int = DEC); - ssize_t print(unsigned int, int = DEC); - ssize_t print(long, int = DEC); - ssize_t print(unsigned long, int = DEC); - ssize_t print(double, int = 2); - ssize_t print(const Printable&); + size_t print(const __FlashStringHelper *); + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(double, int = 2); + size_t print(const Printable&); - ssize_t println(const __FlashStringHelper *); - ssize_t println(const String &s); - ssize_t println(const char[]); - ssize_t println(char); - ssize_t println(unsigned char, int = DEC); - ssize_t println(int, int = DEC); - ssize_t println(unsigned int, int = DEC); - ssize_t println(long, int = DEC); - ssize_t println(unsigned long, int = DEC); - ssize_t println(double, int = 2); - ssize_t println(const Printable&); - ssize_t println(void); + size_t println(const __FlashStringHelper *); + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(double, int = 2); + size_t println(const Printable&); + size_t println(void); }; #endif |