31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9.26 Memory Streambuffer ( memory streambuf )<br />

1. Definition<br />

An object mb of the class memory streambuf can be used as source or target stream<br />

for a coder and allows encoding and decoding in memory (i.e. without file accesses).<br />

Every read or write operation is forwarded to a buffer in memory. This buffer is directly<br />

accessible by the user. <strong>The</strong> length of this buffer is called the capacity of mb. <strong>The</strong> size<br />

of mb is the number of characters that can be read from or written to the stream before<br />

an underflow/overflow occurs. (In that case the corresponding stream operation returns<br />

EOF (end-of-file).) Thus the capacity is the maximum size that mb can have without<br />

reallocating its buffer.<br />

#include < <strong>LEDA</strong>/coding/memory streambuf.h ><br />

2. Creation<br />

memory streambuf mb(streamsize buf sz = 0, bool wipe buf = false);<br />

creates an object mb with capacity and size buf sz. <strong>The</strong> parameter<br />

wipe buf determines whether wipe buffer is called when the buffer<br />

is not needed any more.<br />

memory streambuf mb(char ∗ buf , streamsize buf sz, bool own buf = false,<br />

bool wipe buf = false);<br />

creates an object mb with the memory buffer buf and sets the<br />

capacity and the size to buf sz. If own buf /wipe buf is true, then<br />

buf is deleted/wiped by mb when it is not used anymore. Note that<br />

buf is not copied but it is used as the internal buffer of mb.<br />

3. Operations<br />

void mb.reset( ) moves the internal get and put pointers to the beginning<br />

of the buffer and clears the underflow/overflow<br />

flags.<br />

streamsize mb.get capacity( ) returns the current capacity.<br />

streamsize mb.get size( ) returns the current size.<br />

void mb.set size(streamsize n)<br />

changes the size to n and calls reset. (If n exceeds<br />

the capacity then a new buffer with sufficient capacity<br />

is allocated. <strong>The</strong> contents of the old buffer are not<br />

copied.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!