digitalmars.D - Re: Stream Proposal
- Kagamin <spam here.lot> Mar 14 2011
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Mar 14 2011
- Kagamin <spam here.lot> Mar 15 2011
Andrei Alexandrescu Wrote:A simple input buffered stream of T would be a range of T[] that has two extra primitives: T[] lookAhead(size_t n); void leaveBehind(size_t n);
T front(); T[] front(size_t n); // bulk front void popFront(size_t n=1); // bulk popFrontI'm not sure there's a need for formalizing a buffered output interface (we could simply make buffering transparent, in which case there's only need for primitives that get and set the size of the buffer). In case we do want to formalize an output buffer, it would need primitives such as: T[] getBuffer(size_t n); void commitBuffer(size_t n);
void put(T); // as usual void put(T[]); // bulk put; can pass a slice of the buffer from getBuffer ?
Mar 14 2011
On 3/14/11 10:32 AM, Kagamin wrote:Andrei Alexandrescu Wrote:A simple input buffered stream of T would be a range of T[] that has two extra primitives: T[] lookAhead(size_t n); void leaveBehind(size_t n);
T front(); T[] front(size_t n); // bulk front void popFront(size_t n=1); // bulk popFront
I think such an interface would be confusing. In particular, if T is int, the overload of front looks awfully close to a property writer.I'm not sure there's a need for formalizing a buffered output interface (we could simply make buffering transparent, in which case there's only need for primitives that get and set the size of the buffer). In case we do want to formalize an output buffer, it would need primitives such as: T[] getBuffer(size_t n); void commitBuffer(size_t n);
void put(T); // as usual void put(T[]); // bulk put; can pass a slice of the buffer from getBuffer
This is already implemented but doesn't allow someone to play with the buffer and then commit it. Arguably there might be no such need. Andrei
Mar 14 2011
Andrei Alexandrescu Wrote:T[] getBuffer(size_t n); void commitBuffer(size_t n);
void put(T); // as usual void put(T[]); // bulk put; can pass a slice of the buffer from getBuffer
This is already implemented but doesn't allow someone to play with the buffer and then commit it. Arguably there might be no such need.
Imagine you played with the buffer and only buffer[2..6] and buffer[9..13] should go to the storage. Say, you're converting from xml to plain text. You just skip markup and optionally unescape entities.
Mar 15 2011