Boost logo

Boost Users :

From: Jonathan Turkanis (turkanis_at_[hidden])
Date: 2008-01-15 12:51:54


Pooyan McSporran wrote:
> I'm trying to use a combination of the iostreams library and the
> serialization library in order to be able to serialise objects and
> send them over a socket.

Sounds reasonable.

> I've written a class called "SocketDevice" which implements a
> bidirectional iostreams instance, and I'm trying to use this with
> serialization, in particular the binary_oarchive and binary_iarchive
> archive models.
>
> The problem is that when I do this, the code ends up calling a copy
> constructor (which doesn't exist) on my SocketDevice class. However I
> don't want to implement a copy constructor for this class as it
> doesn't make sense (as it manages a socket and a buffer for that
> socket, etc).

Currently, except for standard streams and stream buffers, which are
given special treatment, Boost.Iostreams fitlers and devices must be
copy constructible. (See, e.g., the documentation for the template
parameter T here:
http://www.boost.org/libs/iostreams/doc/index.html?path=3.3)

The standard way to make a device copy constructible is to use
shared_ptr; you can see examples by looking at the implementation of
file, file_descriptor, and mapped_file.

I'm considering adding a storage policy parameter to the stream and
stream buffer templates to allow them to store a reference or an owned
pointer to a filter or device; this would allow you to do something like
this:

  SocketDevice dev(sock);
  stream_buffer<SocketDevice, ..., by_ref> buf(dev);

or

  stream_buffer<SocketDevice, ..., by_ptr> buf(new SocketDevice(sock));

Also, I would like to make the following work:

  SocketDevice dev(sock);
  filtering_streambuf<bidirectional> str;
  str.push(boost::ref(sock));

I think I considered these options when I designed the library but was
not able to make them work on the full range of supported compilers at
the time.

Best Regards,

-- 
Jonathan Turkanis
CodeRage
http://www.coderage.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net