Public Member Functions

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

A decorator class that adds a read buffer to an otherwise unbuffered source. More...

#include <buffered_source.hpp>

Inheritance diagram for hamcast::util::buffered_source< block_size, maximum_size >:
hamcast::util::source hamcast::util::closeable hamcast::ref_counted

List of all members.

Public Member Functions

virtual bool wait_for_data (long sec, long usec)
 buffered_source (const boost::intrusive_ptr< source > &underlying_source)
virtual size_t read_some (size_t buf_size, void *buf)
virtual void read (size_t buf_size, void *buf)
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::buffered_source< block_size, maximum_size >

A decorator class that adds a read buffer to an otherwise unbuffered source.

Parameters:
block_size buffered_source allocates storage always in chunks to minimize resizing of the internal buffer.
maximum_size The maximum number of bytes buffered_source should allocate.

Constructor & Destructor Documentation

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
hamcast::util::buffered_source< block_size, maximum_size >::buffered_source ( const boost::intrusive_ptr< source > &  underlying_source  ) 

Create a buffered source that decorates underlying_source.

Parameters:
underlying_source The original source.
Precondition:
underlying_source is valid

Member Function Documentation

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual void hamcast::util::buffered_source< 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::buffered_source< 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>
virtual void hamcast::util::buffered_source< block_size, maximum_size >::read ( size_t  buf_size,
void *  buf 
) [virtual]

Read buf_size bytes from the data source. This function blocks until enough bytes are available and throws and exception if the source becomes unreadable before buf_size bytes are read.

Parameters:
buf_size The size of buf.
buf The target buffer.
Precondition:
lock_read() was called
Exceptions:
std::ios_base::failure on errors during read (e.g. if the source is closed)

Implements hamcast::util::source.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual size_t hamcast::util::buffered_source< block_size, maximum_size >::read_some ( size_t  buf_size,
void *  buf 
) [virtual]

Read up to buf_size bytes from the data source and store the bytes in buf. A closed source always returns 0.

Parameters:
buf_size The size of buf.
buf The target buffer.
Returns:
The number of readed bytes (might be < buf_size).
Precondition:
lock_read() was called
Exceptions:
std::ios_base::failure on errors during read.

Implements hamcast::util::source.

template<size_t block_size = default_block_size, size_t maximum_size = default_max_write_buffer_size>
virtual bool hamcast::util::buffered_source< block_size, maximum_size >::wait_for_data ( long  seconds,
long  microseconds 
) [virtual]

Wait until this source becomes "ready" or until a timeout occurs.

Parameters:
seconds The seconds part of the maximum block time.
microseconds The microseconds part of the maximum block time.
Returns:
true if there is data to read; otherwise false
Precondition:
lock_read() was called
Exceptions:
std::ios_base::failure if the source becomes closed

Implements hamcast::util::source.


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