Public Member Functions

hamcast::util::write_buffer< block_size, maximum_size > Class Template Reference

A mutable (growing) buffer that could be used as a sink. More...

#include <write_buffer.hpp>

Inheritance diagram for hamcast::util::write_buffer< block_size, maximum_size >:
hamcast::util::sink hamcast::util::closeable hamcast::ref_counted

List of all members.

Public Member Functions

 write_buffer ()
 ~write_buffer ()
void reserve (size_t arg)
size_t capacity () const
size_t remaining () const
size_t size () const
const char * data () const
void write (size_t buf_size, const void *buf)
std::pair< size_t, void * > take ()
void clear ()
virtual void flush ()
virtual void close ()
virtual bool closed () const

Detailed Description

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
class hamcast::util::write_buffer< block_size, maximum_size >

A mutable (growing) buffer that could be used as a sink.

The write_buffer class provides a representation of a mutable output buffer that automatically grows up to maximum_size bytes.

block_size buffered_sink allocates storage always in chunks to minimize resizing of the internal buffer. maximum_size The maximum number of bytes buffered_sink is allowed to allocate.

Warning:
The buffer is not thread safe except.

Constructor & Destructor Documentation

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
hamcast::util::write_buffer< block_size, maximum_size >::write_buffer (  ) 

Create a buffered sink that decorates underlying_sink.

Precondition:
underlying_sink is valid
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
hamcast::util::write_buffer< block_size, maximum_size >::~write_buffer (  ) 

Deletes the decorated sink.


Member Function Documentation

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
size_t hamcast::util::write_buffer< block_size, maximum_size >::capacity (  )  const

Get the size of the allocated storage.

Returns:
The number of bytes this buffer could write wihtout re-allocation of memory storage.
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
void hamcast::util::write_buffer< block_size, maximum_size >::clear (  ) 

Clear the internal buffer.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual void hamcast::util::write_buffer< block_size, maximum_size >::close (  )  [virtual]

Close the data channel.

Implements hamcast::util::closeable.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual bool hamcast::util::write_buffer< block_size, maximum_size >::closed (  )  const [virtual]

Check if the data channel is closed.

Returns:
true if this is closed for read/write operations; otherwise false.

Implements hamcast::util::closeable.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
const char* hamcast::util::write_buffer< block_size, maximum_size >::data (  )  const

Get the written data.

Returns:
The internal C-buffer.
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual void hamcast::util::write_buffer< block_size, maximum_size >::flush (  )  [virtual]

Force the data sink to flush any buffers.

Exceptions:
Any exception that might be thrown by write().

Implements hamcast::util::sink.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
size_t hamcast::util::write_buffer< block_size, maximum_size >::remaining (  )  const

Get the number of remaining (unwritten) bytes in the allocated storage.

Returns:
capacity() - size().
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
void hamcast::util::write_buffer< block_size, maximum_size >::reserve ( size_t  arg  ) 

Increase capacity() to at least arg bytes.

Parameters:
arg The new minimum size of this.
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
size_t hamcast::util::write_buffer< block_size, maximum_size >::size (  )  const

Get the number of currently used bytes.

Returns:
The number of written bytes in the internal C-buffer.
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
std::pair<size_t, void*> hamcast::util::write_buffer< block_size, maximum_size >::take (  ) 

Get the internal buffer and reset the buffer afterwards.

Returns:
std::make_pair(size(), data())
template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
void hamcast::util::write_buffer< block_size, maximum_size >::write ( size_t  buf_size,
const void *  buf 
) [virtual]

Writes buf_size bytes from buf to the internal buffer.

Parameters:
buf_size The size of buf in bytes.
buf A pointer to a C-buffer that contains the data to write.
Precondition:
buf_size > 0 && buf != NULL.

Implements hamcast::util::sink.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator