digitalmars.D - feature request, refactor std.stream.Stream
- BCS (17/17) Dec 27 2006 The InputStream and OutputStream interfaces are all but unusable because...
- Sean Kelly (4/14) Dec 28 2006 You mean like this?
- BCS (3/21) Dec 28 2006 More or less that type of thing. I'm thinking the same philosophy could
- Sean Kelly (3/22) Dec 28 2006 Yup. I just used that as an example because I had it lying around.
- Ben Hinkle (6/22) Jan 03 2007 I tried that once briefly and ran into scoping issues since mixins can't...
The InputStream and OutputStream interfaces are all but unusable because they have such a huge number of methods to implements, however most of them are implemented by the Stream class in a vary abstract way (all build on 4 or 5 low level methods). This is all well and good until you want to implement Input/OutputStream with some other class (Thread in my case) Why not put all of those function in a pair of mixins? Then anyone who needs to make a stream like object could just implement the half dozen low level things and mix in a big chunk of code. class ThreadStream : InputStream OutputStream Thread { mixin InputMixin!(); mixin OutputMixin!(); size_t readBlock(void* buffer, size_t size){...} size_t writeBlock(void* buffer, size_t size){...} ulong seek(long offset, SeekPos whence){...} }
Dec 27 2006
BCS wrote:The InputStream and OutputStream interfaces are all but unusable because they have such a huge number of methods to implements, however most of them are implemented by the Stream class in a vary abstract way (all build on 4 or 5 low level methods). This is all well and good until you want to implement Input/OutputStream with some other class (Thread in my case) Why not put all of those function in a pair of mixins? Then anyone who needs to make a stream like object could just implement the half dozen low level things and mix in a big chunk of code.You mean like this? http://www.invisibleduck.org/~sean/code/stream.d Sean
Dec 28 2006
Sean Kelly wrote:BCS wrote:More or less that type of thing. I'm thinking the same philosophy could be applied to std.stream without braking any existing code.The InputStream and OutputStream interfaces are all but unusable because they have such a huge number of methods to implements, however most of them are implemented by the Stream class in a vary abstract way (all build on 4 or 5 low level methods). This is all well and good until you want to implement Input/OutputStream with some other class (Thread in my case) Why not put all of those function in a pair of mixins? Then anyone who needs to make a stream like object could just implement the half dozen low level things and mix in a big chunk of code.You mean like this? http://www.invisibleduck.org/~sean/code/stream.d Sean
Dec 28 2006
BCS wrote:Sean Kelly wrote:Yup. I just used that as an example because I had it lying around. SeanBCS wrote:More or less that type of thing. I'm thinking the same philosophy could be applied to std.stream without braking any existing code.The InputStream and OutputStream interfaces are all but unusable because they have such a huge number of methods to implements, however most of them are implemented by the Stream class in a vary abstract way (all build on 4 or 5 low level methods). This is all well and good until you want to implement Input/OutputStream with some other class (Thread in my case) Why not put all of those function in a pair of mixins? Then anyone who needs to make a stream like object could just implement the half dozen low level things and mix in a big chunk of code.You mean like this? http://www.invisibleduck.org/~sean/code/stream.d
Dec 28 2006
"BCS" <BCS pathilink.com> wrote in message news:emv92t$2c5$2 digitaldaemon.com...The InputStream and OutputStream interfaces are all but unusable because they have such a huge number of methods to implements, however most of them are implemented by the Stream class in a vary abstract way (all build on 4 or 5 low level methods). This is all well and good until you want to implement Input/OutputStream with some other class (Thread in my case) Why not put all of those function in a pair of mixins? Then anyone who needs to make a stream like object could just implement the half dozen low level things and mix in a big chunk of code. class ThreadStream : InputStream OutputStream Thread { mixin InputMixin!(); mixin OutputMixin!(); size_t readBlock(void* buffer, size_t size){...} size_t writeBlock(void* buffer, size_t size){...} ulong seek(long offset, SeekPos whence){...} }I tried that once briefly and ran into scoping issues since mixins can't see private functions elsewhere and vice versa. I didn't try very hard, though. It would be great to see a serious attempt at it. -Ben
Jan 03 2007