|
|
A Sink First-In First-Out buffer. This buffer can always be written to, it overwrites any data contained if needed. The class is not thread-safe.
unsigned char * buffer | buffer |
[private]
unsigned char * bufferEnd | bufferEnd |
[private]
unsigned int bufferSize | bufferSize |
[private]
unsigned int peak | peak |
[private]
unsigned int chunkSize | chunkSize |
[private]
unsigned int misalignment | misalignment |
[private]
unsigned char * inp | inp |
[private]
unsigned char * outp | outp |
[private]
Ref<Sink> sink | sink |
[private]
void
init ( Sink * sink,
unsigned int size,
unsigned int chunkSize )
throw ( Exception ) | init |
[private]
Initialize the object.
Parameters:
sink | the Sink to attach this BufferedSink to. |
size | the size of the internal buffer to use. |
chunkSize | size of chunks to handle data in. |
Throws: Exception
void
strip ( void )
throw ( Exception ) | strip |
[private]
De-initialize the object.
Throws: Exception
inline unsigned char *
slidePointer (
unsigned char * p,
unsigned int offset )
throw () | slidePointer |
[private]
Slide a pointer in the internal buffer by offset. If the pointer would reach beyond the end of the buffer, it goes wraps around.
Parameters:
p | the pointer to slide. |
offset | the amount to slide with. |
Returns: pointer p + offset, wrapped around if needed.
inline void
updatePeak ( void )
throw () | updatePeak |
[private]
Update the peak buffer usage indicator.
See also: peak
inline bool
align ( void )
throw ( Exception ) | align |
[private]
If the underlying Sink is misaligned on chunkSize, write as many 0s as needed to get it aligned.
See also: misalignment, chunkSize
inline
BufferedSink ( void )
throw ( Exception ) | BufferedSink |
[protected]
Default constructor. Always throws an Exception.
Throws: Exception
inline unsigned int
getSize ( void )
throw () | getSize |
[protected const]
Get the size of the buffer.
Returns: the size of the buffer.
unsigned int
store ( const void * buffer,
unsigned int bufferSize )
throw ( Exception ) | store |
[protected]
Store data in the internal buffer. If there is not enough space, discard all in the buffer and the beginning of the supplied buffer if needed.
Parameters:
buffer | the data to store. |
bufferSize | the amount of data to store in bytes. |
Returns: number of bytes really stored.
inline
BufferedSink ( Sink * sink,
unsigned int size,
unsigned int chunkSize = 1 )
throw ( Exception ) | BufferedSink |
Constructor by an underlying Sink, buffer size and chunk size.
Parameters:
sink | the Sink to attach this BufferSink to. |
size | the size of the buffer to use for buffering. |
chunkSize | hanlde all data in write() as chunks of chunkSize |
Throws: Exception
BufferedSink ( const BufferedSink & buffer )
throw ( Exception ) | BufferedSink |
Copy constructor.
Parameters:
buffer | the object to copy. |
Throws: Exception
inline
~BufferedSink ( void )
throw ( Exception ) | ~BufferedSink |
[virtual]
Destructor.
Throws: Exception
BufferedSink &
operator= ( const BufferedSink & bs )
throw ( Exception ) | operator= |
[virtual]
Assignment operator.
Parameters:
bs | the object to assign to this one. |
Returns: a reference to this object.
Throws: Exception
Reimplemented from Sink.
inline unsigned int
getPeak ( void )
throw () | getPeak |
[const]
Get the peak usage of the internal buffer.
Returns: the peak usage of the internal buffer.
inline bool
open ( void )
throw ( Exception ) | open |
[virtual]
Open the BufferedSink. Opens the underlying Sink.
Returns: true if opening was successful, false otherwise.
Throws: Exception
Reimplemented from Sink.
inline bool
isOpen ( void )
throw () | isOpen |
[const virtual]
Check if a BufferedSink is open.
Returns: true if the BufferedSink is open, false otherwise.
Reimplemented from Sink.
inline bool
canWrite ( unsigned int sec,
unsigned int usec )
throw ( Exception ) | canWrite |
[virtual]
Check if the BufferedSink is ready to accept data. Always returns true immediately.
Parameters:
sec | the maximum seconds to block. |
usec | micro seconds to block after the full seconds. |
Returns: true
Throws: Exception
Reimplemented from Sink.
unsigned int
write ( const void * buf,
unsigned int len )
throw ( Exception ) | write |
[virtual]
Write data to the BufferedSink. Always reads the maximum number of chunkSize chunks buf holds. If the data can not be written to the underlying stream, it is buffered. If the buffer overflows, the oldest data is discarded.
Parameters:
buf | the data to write. |
len | number of bytes to write from buf. |
Returns: the number of bytes written (may be less than len).
Throws: Exception
Reimplemented from Sink.
inline void
flush ( void )
throw ( Exception ) | flush |
[virtual]
Flush all data that was written to the BufferedSink to the underlying Sink.
Throws: Exception
Reimplemented from Sink.
void
close ( void )
throw ( Exception ) | close |
[virtual]
Close the BufferedSink. Closes the underlying Sink.
Throws: Exception
Reimplemented from Sink.