streambufs!
586
0
Advertisement
Well the new thing added to the code library today are streambuf helper classes. They're a pair of classes that derive from streambuf that implement buffering code. The OStreamBuf class adds a pure virtual method, do_write() and the IStreamBuf class adds a do_read(). Basically these get called when the buffers need to get flushed or filled. These helper classes make creating custom streambufs extremely easy. I've used them for redirecting the standard handles for a child process into a iostream, wrapping sockets and tying a stream to an edit control.
And once you have a streambuf you can tie the input into the rest of the standard library pretty easily, especially with stream/streambuf iterators. Or even just using the insertion opreator to dump entire streambufs into a stream. This is just one of the many examples I've found where using the standard library interfaces as a common ground makes for very productive coding.
The current versions of the OStreamBuf and IStreamBuf classes are templated. I might go and create a non-templated version for the common > case. That should cut down on compile times. And after that I'll probably work on my sixth or seventh binary stream class revision.
And once you have a streambuf you can tie the input into the rest of the standard library pretty easily, especially with stream/streambuf iterators. Or even just using the insertion opreator to dump entire streambufs into a stream. This is just one of the many examples I've found where using the standard library interfaces as a common ground makes for very productive coding.
The current versions of the OStreamBuf and IStreamBuf classes are templated. I might go and create a non-templated version for the common > case. That should cut down on compile times. And after that I'll probably work on my sixth or seventh binary stream class revision.
Advertisement
Advertisement
Advertisement
Discussion