From 2cedbeef132256ceca033f4b5073ab9aba818130 Mon Sep 17 00:00:00 2001 From: amcewen Date: Fri, 1 Apr 2011 21:10:38 +0100 Subject: Added Printable interface class to allow printing of classes such as IPAddress --- cores/arduino/Printable.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 cores/arduino/Printable.h (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h new file mode 100644 index 0000000..fc64858 --- /dev/null +++ b/cores/arduino/Printable.h @@ -0,0 +1,32 @@ +/* + Printable.h - Interface class that allows printing of complex types + Copyright (c) 2011 Adrian McEwen. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Printable_h +#define Printable_h + +class Print; + +class Printable +{ + public: + virtual void printTo(Print& p) const =0; +}; + +#endif + -- cgit v1.2.3-18-g5258 From 49155d0a4604eb50d756527ef9512499d2ea6cf4 Mon Sep 17 00:00:00 2001 From: amcewen Date: Sat, 2 Apr 2011 11:33:27 +0100 Subject: Added a brief explanation of how you'd use Printable --- cores/arduino/Printable.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index fc64858..e5d7732 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -22,6 +22,12 @@ class Print; +/** The Printable class provides a way for new classes to allow themselves to be printed. + By deriving from Printable and implementing the printTo method, it will then be possible + for users to print out instances of this class by passing them into the usual + Print::print and Print::println methods. +*/ + class Printable { public: -- cgit v1.2.3-18-g5258 From edee02eaf19c4d13324959e6db881dc327342561 Mon Sep 17 00:00:00 2001 From: amcewen Date: Sun, 10 Apr 2011 11:34:40 +0100 Subject: Added virtual destructor to Printable, which also requires new and delete operators to be added --- cores/arduino/Printable.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index e5d7732..5ff6077 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -20,6 +20,8 @@ #ifndef Printable_h #define Printable_h +#include + class Print; /** The Printable class provides a way for new classes to allow themselves to be printed. @@ -31,6 +33,7 @@ class Print; class Printable { public: + virtual ~Printable() {}; virtual void printTo(Print& p) const =0; }; -- cgit v1.2.3-18-g5258 From a239d2c541094ef5445159360ae5d2d6a93dbf00 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 4 Jun 2011 09:19:17 -0400 Subject: Added Printable interface class to allow printing of classes such as IPAddress --- cores/arduino/Printable.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cores/arduino/Printable.h (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h new file mode 100644 index 0000000..d332aad --- /dev/null +++ b/cores/arduino/Printable.h @@ -0,0 +1,37 @@ +/* + Printable.h - Interface class that allows printing of complex types + Copyright (c) 2011 Adrian McEwen. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Printable_h +#define Printable_h + +class Print; + +/** The Printable class provides a way for new classes to allow themselves to be printed. + By deriving from Printable and implementing the printTo method, it will then be possible + for users to print out instances of this class by passing them into the usual + Print::print and Print::println methods. +*/ +class Printable +{ + public: + virtual void printTo(Print& p) const = 0; +}; + +#endif + -- cgit v1.2.3-18-g5258 From f282cbaf968f7142ef5abb68a92e970c3d5eea35 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 23 Aug 2011 19:12:03 -0400 Subject: write(), print(), and println() now return number of bytes written. The type is long, and negative values indicate errors. Needs more testing. http://code.google.com/p/arduino/issues/detail?id=551 --- cores/arduino/Printable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index d332aad..6814ee4 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual void printTo(Print& p) const = 0; + virtual long printTo(Print& p) const = 0; }; #endif -- cgit v1.2.3-18-g5258 From 0635790dd111e91e5c488acc599cc404dc707abd Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 14:20:41 -0400 Subject: Changing from long to ssize_t (int) for write(), print(), println() return. --- cores/arduino/Printable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index 6814ee4..9065904 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual long printTo(Print& p) const = 0; + virtual ssize_t printTo(Print& p) const = 0; }; #endif -- cgit v1.2.3-18-g5258 From 5130a1329462aa36d5f18e31851d3d9d5086e411 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 16:08:14 -0400 Subject: 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 --- cores/arduino/Printable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/Printable.h') diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index 9065904..e22e87e 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual ssize_t printTo(Print& p) const = 0; + virtual size_t printTo(Print& p) const = 0; }; #endif -- cgit v1.2.3-18-g5258