Public Member Functions

base::ByteStream Class Reference

Stream of bytes from one thread to another. More...

#include <libppbase/base/ByteStream.h>

List of all members.

Public Member Functions

 ByteStream (size_t size=0)
 Creates a byte stream of the given size.
 ~ByteStream ()
 Destroys a byte stream.
void allocate (size_t size)
 Allocates the stream buffer.
void clear ()
 Clears the stream buffer.
bool empty ()
 Checks if the stream buffer is empty.
bool eos ()
 Checks if the end of the stream has been reached.
size_t getWaitsRead () const
 Gets the number of times a thread waited for the buffer to contain data to read.
size_t getWaitsWrite () const
 Gets the number of times a thread waited for the buffer to become empty to write.
size_t read (void *buffer, size_t len, bool exact=true)
 Reads some bytes from the stream This function blocks the current thread until it can return the desired number of bytes.
size_t read (base::String &buffer, size_t len, bool exact=true)
void reset ()
 Resets the byte stream.
void seteos (bool immediate)
 Sets the end-of-stream marker.
size_t write (const void *buffer, size_t len, bool exact=true)
 Writes some bytes to the stream.
size_t write (const base::String &buffer, bool exact=true)

Detailed Description

Stream of bytes from one thread to another.

Author:
Christoph Schwarz
Version:
$Id: ByteStream.h 21 2010-09-05 04:18:17Z cschwarz1 $

Constructor & Destructor Documentation

base::ByteStream::ByteStream ( size_t  size = 0  ) 

Creates a byte stream of the given size.

Parameters:
size stream buffer size in bytes

Member Function Documentation

void base::ByteStream::allocate ( size_t  size  ) 

Allocates the stream buffer.

Parameters:
size stream buffer size in bytes
bool base::ByteStream::empty (  ) 

Checks if the stream buffer is empty.

Returns:
true if it is empty, false if it contains at least 1 byte
bool base::ByteStream::eos (  ) 

Checks if the end of the stream has been reached.

Returns:
true if the end has been reached, false if the stream is still alive
size_t base::ByteStream::getWaitsRead (  )  const

Gets the number of times a thread waited for the buffer to contain data to read.

Returns:
number of times
size_t base::ByteStream::getWaitsWrite (  )  const

Gets the number of times a thread waited for the buffer to become empty to write.

Returns:
number of times
size_t base::ByteStream::read ( base::String buffer,
size_t  len,
bool  exact = true 
)
See also:
read(char *, size_t, bool)
size_t base::ByteStream::read ( void *  buffer,
size_t  len,
bool  exact = true 
)

Reads some bytes from the stream This function blocks the current thread until it can return the desired number of bytes.

Parameters:
buffer buffer to write the bytes to
len (maximum) number of bytes to read
exact flag: try to read exactly this number of bytes, this may fail on end-of-stream
Returns:
number of bytes read, or 0 if the end of the stream has been reached
void base::ByteStream::seteos ( bool  immediate  ) 

Sets the end-of-stream marker.

Parameters:
immediate true: set the marker even if the stream contains unread data (error mode) false: set the marker as soon as the last unread data has been read (normal mode)
size_t base::ByteStream::write ( const void *  buffer,
size_t  len,
bool  exact = true 
)

Writes some bytes to the stream.

Parameters:
buffer buffer to read the bytes from
len (maximum) number of bytes to write
exact flag: try to write exactly this number of bytes
Returns:
number of bytes written, or 0 if the end of the stream has been reached
size_t base::ByteStream::write ( const base::String buffer,
bool  exact = true 
)
See also:
write(const char *, size_t, bool)

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