hamcast  Version 0.7
Public Member Functions | List of all members
hamcast::util::buffered_source< block_size, maximum_size > Class Template Reference

#include <buffered_source.hpp>

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

Public Member Functions

virtual bool wait_for_data (long sec, long usec)
 
 buffered_source (const 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
 

Additional Inherited Members

- Static Public Member Functions inherited from hamcast::ref_counted
static void add_ref (ref_counted *rc)
 
static void release (ref_counted *rc)
 
- Protected Member Functions inherited from hamcast::ref_counted
 ref_counted ()
 
void ref ()
 
bool deref ()
 

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_sizebuffered_source allocates storage always in chunks to minimize resizing of the internal buffer.
maximum_sizeThe 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 intrusive_ptr< source > &  underlying_source)

Create a buffered source that decorates underlying_source.

Parameters
underlying_sourceThe 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_sizeThe size of buf.
bufThe target buffer.
Precondition
lock_read() was called
Exceptions
std::ios_base::failureon 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_sizeThe size of buf.
bufThe target buffer.
Returns
The number of readed bytes (might be < buf_size).
Precondition
lock_read() was called
Exceptions
std::ios_base::failureon 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
secondsThe seconds part of the maximum block time.
microsecondsThe 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::failureif the source becomes closed

Implements hamcast::util::source.


The documentation for this class was generated from the following file: