Streams: an open discussion
Ben Hinkle
ben.hinkle at gmail.com
Sun Feb 26 05:44:32 PST 2006
<surferjeff at excite.com> wrote in message
news:dtribg$eui$1 at digitaldaemon.com...
> The interface for InputStream and OutputStream is huge. I often have to
> create
> my own streambufs in C++, which only requires implementing about 5
> methods. If
> I want to write my own class that implements InputStream, then I have to
> implement about 50 methods, and another 50 if I want to implement
> OutputStream
> too!
>
> It would useful if there were smaller interfaces. For example, a read()
> method
> and eof() for input, and that's it. Then have a util class that takes one
> of
> these small interfaces and implements the full 50 methods in the bigger
> interface.
>
> Yes, I could do this in my own code, but I think many people will have to
> re-invent this wheel in D, and each re-invention will be different and not
> interchangeable.
Subclass Stream or FilterStream. You'll probably have to override 3 methods:
readBlock, writeBlock and seek. The interfaces are primarily for users to
restrict their API - not for library writers to shoe-horn their classes
into. Look at any of the small stream classes in std.stream to get an idea
how easy it is to do.
More information about the Digitalmars-d
mailing list