From 3cedf0afbfc502c641d91959738d0b4efc5391c2 Mon Sep 17 00:00:00 2001 From: timschneider Date: Tue, 9 Oct 2012 09:16:31 +0300 Subject: [PATCH 1/2] Copy Constructor Stream& operator=(Stream& src) added. The copy constructor gives the user the ability to pass an derived class as a reference. Used and needed in Firmata with custom stream. tim --- hardware/arduino/cores/arduino/Stream.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp index aafb7fcf97d..5f3a0cd0379 100644 --- a/hardware/arduino/cores/arduino/Stream.cpp +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -50,6 +50,15 @@ int Stream::timedPeek() return -1; // -1 indicates timeout } +// virtual copy constructor to allow child classes to use Stream as reference +Stream& Stream::operator=(Stream const& src) +{ + // copy the timeout time + _timeout = src._timeout; + // return a reference to this object + return *this; +} + // returns peek of the next digit in the stream or -1 if timeout // discards non-numeric characters int Stream::peekNextDigit() From b6d3f9163f0f79446335f5a5871bb3d4677ba67a Mon Sep 17 00:00:00 2001 From: timschneider Date: Tue, 9 Oct 2012 09:20:53 +0300 Subject: [PATCH 2/2] Virtual Copy Constructor Stream& operator=(Stream& src) added. --- hardware/arduino/cores/arduino/Stream.h | 1 + 1 file changed, 1 insertion(+) diff --git a/hardware/arduino/cores/arduino/Stream.h b/hardware/arduino/cores/arduino/Stream.h index 58bbf752f33..40f44cc8636 100644 --- a/hardware/arduino/cores/arduino/Stream.h +++ b/hardware/arduino/cores/arduino/Stream.h @@ -49,6 +49,7 @@ class Stream : public Print virtual int read() = 0; virtual int peek() = 0; virtual void flush() = 0; + virtual Stream& operator=(Stream const& src); Stream() {_timeout=1000;}