|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-03 08:04:07
Jonathan Turkanis wrote:
[...]
> II. The Solution (the easy part) ---------------------------
>
> I believe it will suffice to:
>
> - provide the functions put() and write() (both filter member
> functions and the free functions with the same names) with a way to
> indicate that fewer than the requested number of characters have been
> written to the underlying data sink even though no error has occurred.
>
> - Provide the functions get() and read() (both filter member
> functions and the free functions with the same names) with a way to
> indicate that fewer than the requested number of characters have been
> read from the underlying data source, even though no error has
> occurred and EOF has not been reached.
[...]
I haven't looked at the library in detail (but I have developed something
similar).
In my opinion, get and put are non-essential functions, syntactic sugar for
read and write. put(c) is just write(&c, 1); get() is read(&tmp, 1); return
tmp. I wouldn't worry much about the "proper" interface of put and get, and
I wouldn't require filters to implement them. A get() returning -1 for EOF
and -2 for "no input available" should be good enough for
character-at-a-time filters, which are mostly of the form "return xform(
get() );".
In fact, a character-by-character filter is never the proper way to do
things; the canonical form of the above should be
int r = read(buffer, size);
if( r > 0 )
std::transform(buffer, buffer+r, buffer, xform);
return r;
so I'm not sure whether get/put should ever be used at all.
But as I said, I haven't looked at the library in detail, so I may be
missing something.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk