On Sun, 1 Feb 2009 03:30:10 -0500
Chris Frey <cdf...@foursquare.net> wrote:

> Only if we support in-memory operation as well.  I'd be interested in
> seeing some pseudo-code of what you had in mind.
> 
> I don't want to lock users of the library into loading data to and from
> files.  I don't think it is a good idea to force people to use iostreams
> either.  I use them, but they are not everyone's cup of tea.

I think the iostream stuff is nice, but you are right.  It's not fair
to force people to use something they are not accustom to.

> 
> COD files and screenshots could be loaded or saved from anywhere...
> applications may grab these files over a network, downloaded via HTTP,
> or stored in their own archives.  The screenshot mechanism may just be
> used to display a 'semi-live' image of the device in real time and never get
> saved.  All these uses must be allowed by the library.
> 
> If iostreams can do that, I'm cautiously open to that, but I'd like to see
> an example before I make up my mind.

The iostream class library is supposed to be a framework for "streams
of data" so in that sense it's not just about files.  It's true that
the standard library only has implementations for streams from files
(and stringd) but if we stick to using references of std::istream and
std::ostream in the API then that leaves it open to other
implementations of these classes.  This simplifies the code in
JavaLoader.  Take GetScreenShot for example.  Currently the Data class
is used to resize a buffer and append bytes to it:

// Copy data
unsigned char *buffer = image.GetBuffer(image.GetSize() + bytereceived);
memcpy(buffer + image.GetSize(), pd + 4, bytereceived);

// New size
image.ReleaseBuffer(image.GetSize() + bytereceived);


Switching to std::ostream would simplify this to:

output.write (response.GetData() + 4, bytereceived);


Could also add a method to Data class to simplify this further:

// Write data to the output stream
/// \param output output stream to write to
/// \param offset offset into data buffer to begin writing
/// \param length length of data to write, defaults to remaining data
Data::Write(std::ostream &output, size_t offset = 0, size_t length =
-1);


Looking at the Boost libraries there is an example of setting up HTTP
(or basic TCP socket) sessions and they use iostream classes, eg:

http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/http/client/sync_client.cpp

This could be used to stream the cod file from a web server for loading
to the device for example.

For memory only streams, I think the std::ostringstream class would
work.  One could also write a simple implementation of std::streambuf
and use it to create std::ostream.  Again in Boost, it looks like there
is another library that simplifies this and makes it more robust.

http://www.boost.org/doc/libs/1_37_0/libs/iostreams/doc/index.html




-- 
Josh Kropf <j...@slashdev.ca>

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Barry-devel mailing list
Barry-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/barry-devel

Reply via email to