Thread overview
FilterStream and std.stream cleanup
Aug 05, 2005
Ben Hinkle
Aug 06, 2005
Regan Heath
Aug 06, 2005
Ben Hinkle
August 05, 2005
I'd like to do some cleanup in std.stream. In particular two things:

1) remove all deprecated features. This means stdin, stdout, stderr will go away and ReadError, WriteError and SeekError will go away (the Exceptions will stay).

2) add FilterStream base class for BufferedStream, EndianStream and SliceStream. A FilterStream forwards read/write/seek requests to the source stream. Everything should be backwards compatible and a new "source" property for the backing stream and "nestClose" properties will be available for the FilterStream and subclasses.

A couple side notes, too:
1) fix a bug in SliceStream.available - it assumed the entire source stream
was available
2) if anyone wants to fix up MmFile give me a holler and I'll fix up
MmFileStream, too.

-Ben


August 06, 2005
On Fri, 5 Aug 2005 19:54:30 -0400, Ben Hinkle <ben.hinkle@gmail.com> wrote:
> I'd like to do some cleanup in std.stream. In particular two things:
>
> 1) remove all deprecated features. This means stdin, stdout, stderr will go away and ReadError, WriteError and SeekError will go away (the Exceptions
> will stay).

Good. It will remove the collision when you import std.stream and std.c.stdio and then use 'stdin'.
However, I want a stdin that is a stream or some easy way to construct one, is there? how do I do it?

> 2) add FilterStream base class for BufferedStream, EndianStream and
> SliceStream. A FilterStream forwards read/write/seek requests to the source stream. Everything should be backwards compatible and a new "source"
> property for the backing stream and "nestClose" properties will be available for the FilterStream and subclasses.

Is this so we can derive streams that filter/transcode from this new FilterStream?
If so, great idea.

Regan
August 06, 2005
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opsu2eskwc23k2f5@nrage.netwin.co.nz...
> On Fri, 5 Aug 2005 19:54:30 -0400, Ben Hinkle <ben.hinkle@gmail.com> wrote:
>> I'd like to do some cleanup in std.stream. In particular two things:
>>
>> 1) remove all deprecated features. This means stdin, stdout, stderr will
>> go away and ReadError, WriteError and SeekError will go away (the
>> Exceptions
>> will stay).
>
> Good. It will remove the collision when you import std.stream and
> std.c.stdio and then use 'stdin'.
> However, I want a stdin that is a stream or some easy way to construct
> one, is there? how do I do it?

std.cstream has din/out/err which are the Stream wrappers around C's stdin/out/err. Also cstream publically imports std.stream so if you are currently importing std.stream you can safely switch to cstream without much hassle.

>> 2) add FilterStream base class for BufferedStream, EndianStream and
>> SliceStream. A FilterStream forwards read/write/seek requests to the
>> source stream. Everything should be backwards compatible and a new
>> "source"
>> property for the backing stream and "nestClose" properties will be
>> available for the FilterStream and subclasses.
>
> Is this so we can derive streams that filter/transcode from this new
> FilterStream?
> If so, great idea.

That's the idea - though the FilterStream is very small and mostly it's just for collecting a couple declarations into one place and standardizing the "source" and "nestClose" abilities. Currently SliceStream has "nestClose" but the others don't and BufferedStream lets you reset a source but the others don't. Collecting them up makes it easier to get a consistent API so it doesn't hurt. Here's the doc for FilterStream:

class FilterStream : Stream
  A FilterStream is a base class for wrapping a backing stream
  with extra functionality.
this(Stream source)
  Create a filter for the given backing stream source
Stream source
  Read/write property to access the source stream backing this
  stream. Changing the source closes the current stream and
  attempts to reopen with the new stream. If the new stream is
  null the filter stream remains closed.
bit nestClose
  Read/write property to indicate the source should be closed
  when this stream closes. Defaults to true.
void resetSource()
  Resets the wrapper stream to a new source stream state.
size_t readBlock(void* buffer, size_t size)
size_t writeBlock(void* buffer, size_t size)
ulong seek(long offset, SeekPos whence)
void close()
size_t available()
  Overrides of the Stream methods to forward to the source stream.