Skip to content

Stream - virtual copy constructor added #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Stream - virtual copy constructor added #119

wants to merge 2 commits into from

Conversation

timschneider
Copy link

I've added a virtual copy constructor to Stream.h / .cpp, to give the user the ability to pass derived classes as reference.

Tim

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
@lestofante
Copy link

I like this, hope to see it in mainstream soon

2012/10/9 timschneider notifications@github.com

I added a virtual copy constructor to Stream.h / .cpp, to give the user
the ability to pass derived classes as reference.

Tim

You can merge this Pull Request by running:

git pull https://github.com/timschneider/Arduino patch-1

Or view, comment on, or merge it at:

#119
Commit Summary

  • Copy Constructor Stream& operator=(Stream& src) added.
  • Virtual Copy Constructor Stream& operator=(Stream& src) added.

File Changes

  • M hardware/arduino/cores/arduino/Stream.cpp (9)
  • M hardware/arduino/cores/arduino/Stream.h (1)

Patch Links

@mbanzi
Copy link
Member

mbanzi commented Nov 1, 2012

hello timschneider can you show me and example of how this would change things for end users? what does it allow you to do?

@timschneider
Copy link
Author

I used it in the following way.

the firmata arduino library uses a serial stream for communication with the host application on the pc. I've built an arduino http server with websocket support and moved the host application onto the arduino mega board. To be conform to the Firmata library, I'm using a custom memory stream which is created for every websocket client at runtime. For that reason i've to change the stream at runtime, but when you try this with just a reference it wont work otherwise you have to use pointers or like i did, with a virtual copy constructor.

The enduser has the benefit to change stream references at runtime over different class types.

Let me say i've a class called TerminalServer with a property of the type Stream& MyStream. But u change the Stream at Runtime from EthernetStream to SerialStream or BluetoothStream, all have Stream as parent, now u have the ability to do this.

Tim

@ffissore ffissore added the New label Feb 27, 2014
@cmaglie cmaglie added Component: Core Related to the code for the standard Arduino API feature request A request to make an enhancement (not a bug fix) labels Apr 8, 2015
@soundanalogous
Copy link

This issue should be closed. This was fixed via a different means in Firmata v2.3.6.

@cmaglie
Copy link
Member

cmaglie commented May 28, 2015

@soundanalogous
thanks for the heads up!

@cmaglie cmaglie closed this May 28, 2015
@ffissore ffissore added this to the Release 1.6.5 milestone May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API feature request A request to make an enhancement (not a bug fix)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants