An object mb of the class memory_streambuf can be used as source or target stream for a coder and allows encoding and decoding in memory (i.e. without file accesses). Every read or write operation is forwarded to a buffer in memory. This buffer is directly accessible by the user. The length of this buffer is called the capacity of mb. The size of mb is the number of characters that can be read from or written to the stream before an underflow/overflow occurs. (In that case the corresponding stream operation returns EOF (end-of-file).) Thus the capacity is the maximum size that mb can have without reallocating its buffer.
#include < LEDA/coding/memory_streambuf.h >
|memory_streambuf||mb(streamsize buf_sz = 0, bool wipe_buf = false)|
|creates an object mb with capacity and size buf_sz. The parameter wipe_buf determines whether wipe_buffer is called when the buffer is not needed any more.|
|memory_streambuf||mb(char* buf, streamsize buf_sz, bool own_buf = false, bool wipe_buf = false)|
|creates an object mb with the memory buffer buf and sets the capacity and the size to buf_sz. If own_buf/wipe_buf is true, then buf is deleted/wiped by mb when it is not used anymore. Note that buf is not copied but it is used as the internal buffer of mb.|
|void||mb.reset()||moves the internal get and put pointers to the beginning of the buffer and clears the underflow/overflow flags.|
|streamsize||mb.get_capacity()||returns the current capacity.|
|streamsize||mb.get_size()||returns the current size.|
|void||mb.set_size(streamsize n)||changes the size to n and calls reset. (If n exceeds the capacity then a new buffer with sufficient capacity is allocated. The contents of the old buffer are not copied.)|
|void||mb.truncate(streamsize n)||also changes the size to n, but never allocates a new buffer.
Precondition n < = current capacity.
|char*||mb.get_buffer()||returns the memory buffer of mb.|
|void||mb.set_buffer(char* buf, streamsize buf_sz, bool own_buf = false, bool wipe_buf = false)|
|makes buf the new memory buffer and changes capacity and size to buf_sz. (The meaning of own_buf and wipe_buf is the same as in the second contructor.)|
|void||mb.wipe_buffer()||like reset, in addition all bytes in the memory buffer are set to zero.|
|streamsize||mb.in_avail()||returns how many characters can be read from mb before an underflow occurs.|
|streamsize||mb.in_count()||returns how many characters have been read from mb since the last reset.|
|streamsize||mb.out_avail()||returns how many characters can be written to mb before an overflow occurs.|
|streamsize||mb.out_count()||returns how many characters have been written to mb since the last reset.|
|bool||mb.had_underflow()||returns whether an underflow has occurred since the last reset.|
|bool||mb.had_overflow()||returns whether an overflow has occurred since the last reset.|