buffered input (examples?)

Michel Fortin michel.fortin at michelf.com
Mon Feb 7 06:40:06 PST 2011


On 2011-02-07 08:24:32 -0500, spir <denis.spir at gmail.com> said:

> Does this have anything to do with currently discussed buffered input 
> ranges? If yes, how does such a design, or any alternative, fit their 
> proposed interface?

You can build all of this on top of a buffered input range. The 
buffered input range is not an alternative for your complex parsing 
algorithm, it's just the component managing the buffer.

Having the underlying range manage the buffer (as opposed to having 
your parser algorithm doing it) means that the buffer implementation 
can vary depending on the type of range. For instance, if you're 
parsing directly data in memory, the buffered range can use directly 
this data in memory as the buffer, requiring no allocation and no copy; 
if you're parsing from a file or a network stream it'll use a more 
standard buffer.

But how exactly the buffer is implemented does not affect your parsing 
algorithm in any way. That's the great thing about it, separation of 
concerns: your algorithm will work independently of the buffer 
implementation used. All your parser algorithm has to do is say 
"shiftFront" and "appendToFront" to control what's available in the 
buffer.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list