Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::BasicFIFOBuffer< T > Class Template Reference

#include <FIFOBuffer.h>

+ Collaboration diagram for Poco::BasicFIFOBuffer< T >:

Public Types

typedef T Type
 

Public Member Functions

 BasicFIFOBuffer (std::size_t size, bool notify=false)
 
 BasicFIFOBuffer (T *pBuffer, std::size_t size, bool notify=false)
 
 BasicFIFOBuffer (const T *pBuffer, std::size_t size, bool notify=false)
 
 ~BasicFIFOBuffer ()
 Destroys the FIFOBuffer.
 
void resize (std::size_t newSize, bool preserveContent=true)
 
std::size_t peek (T *pBuffer, std::size_t length) const
 
std::size_t peek (Poco::Buffer< T > &buffer, std::size_t length=0) const
 
std::size_t read (T *pBuffer, std::size_t length)
 
std::size_t read (Poco::Buffer< T > &buffer, std::size_t length=0)
 
std::size_t write (const T *pBuffer, std::size_t length)
 
std::size_t write (const Buffer< T > &buffer, std::size_t length=0)
 
std::size_t size () const
 Returns the size of the buffer.
 
std::size_t used () const
 Returns the size of the used portion of the buffer.
 
std::size_t available () const
 Returns the size of the available portion of the buffer.
 
void drain (std::size_t length=0)
 
void copy (const T *ptr, std::size_t length)
 
void advance (std::size_t length)
 
T * begin ()
 Returns the pointer to the beginning of the buffer.
 
T * next ()
 Returns the pointer to the next available position in the buffer.
 
T & operator[] (std::size_t index)
 
const T & operator[] (std::size_t index) const
 
const Buffer< T > & buffer () const
 Returns const reference to the underlying buffer.
 
void setError (bool error=true)
 
bool isValid () const
 
void setEOF (bool eof=true)
 
bool hasEOF () const
 Returns true if EOF flag has been set.
 
bool isEOF () const
 Returns true if EOF flag has been set and buffer is empty.
 
bool isEmpty () const
 Returns true is buffer is empty, false otherwise.
 
bool isFull () const
 Returns true is buffer is full, false otherwise.
 
bool isReadable () const
 
bool isWritable () const
 
void setNotify (bool notify=true)
 Enables/disables notifications.
 
bool getNotify () const
 Returns true if notifications are enabled, false otherwise.
 
Mutexmutex ()
 Returns reference to mutex.
 

Public Attributes

Poco::BasicEvent< bool > writable
 
Poco::BasicEvent< bool > readable
 

Private Member Functions

void notify (std::size_t usedBefore)
 
 BasicFIFOBuffer ()
 
 BasicFIFOBuffer (const BasicFIFOBuffer &)
 
BasicFIFOBufferoperator= (const BasicFIFOBuffer &)
 

Private Attributes

Buffer< T > _buffer
 
std::size_t _begin
 
std::size_t _used
 
bool _notify
 
Mutex _mutex
 
bool _eof
 
bool _error
 

Detailed Description

template<class T>
class Poco::BasicFIFOBuffer< T >

A simple buffer class with support for re-entrant, FIFO-style read/write operations, as well as (optional) empty/non-empty/full (i.e. writable/readable) transition notifications. Buffer can be flagged with end-of-file and error flags, which renders it un-readable/writable.

Critical portions of code are protected by a recursive mutex. However, to achieve thread-safety in cases where multiple member function calls are involved and have to be atomic, the mutex must be locked externally.

Buffer size, as well as amount of unread data and available space introspections are supported as well.

This class is useful anywhere where a FIFO functionality is needed.

Definition at line 33 of file FIFOBuffer.h.

Member Typedef Documentation

◆ Type

template<class T >
typedef T Poco::BasicFIFOBuffer< T >::Type

Definition at line 52 of file FIFOBuffer.h.

Constructor & Destructor Documentation

◆ BasicFIFOBuffer() [1/5]

template<class T >
Poco::BasicFIFOBuffer< T >::BasicFIFOBuffer ( std::size_t size,
bool notify = false )
inline

Event indicating "readability" of the buffer, triggered as follows:

  • when buffer transitions from non-empty to empty, Readable event observers are notified, with false
    value as the argument
  • when FIFOBuffer transitions from empty to non-empty, Readable event observers are notified, with true value as the argument

Definition at line 78 of file FIFOBuffer.h.

◆ BasicFIFOBuffer() [2/5]

template<class T >
Poco::BasicFIFOBuffer< T >::BasicFIFOBuffer ( T * pBuffer,
std::size_t size,
bool notify = false )
inline

Definition at line 89 of file FIFOBuffer.h.

◆ BasicFIFOBuffer() [3/5]

template<class T >
Poco::BasicFIFOBuffer< T >::BasicFIFOBuffer ( const T * pBuffer,
std::size_t size,
bool notify = false )
inline

Definition at line 100 of file FIFOBuffer.h.

◆ ~BasicFIFOBuffer()

template<class T >
Poco::BasicFIFOBuffer< T >::~BasicFIFOBuffer ( )
inline

Destroys the FIFOBuffer.

Definition at line 111 of file FIFOBuffer.h.

◆ BasicFIFOBuffer() [4/5]

template<class T >
Poco::BasicFIFOBuffer< T >::BasicFIFOBuffer ( )
private

◆ BasicFIFOBuffer() [5/5]

template<class T >
Poco::BasicFIFOBuffer< T >::BasicFIFOBuffer ( const BasicFIFOBuffer< T > & )
private

Member Function Documentation

◆ advance()

template<class T >
void Poco::BasicFIFOBuffer< T >::advance ( std::size_t length)
inline

Advances buffer by length elements. Should be called AFTER the data was copied into the buffer.

Definition at line 332 of file FIFOBuffer.h.

◆ available()

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::available ( ) const
inline

Returns the size of the available portion of the buffer.

Definition at line 282 of file FIFOBuffer.h.

◆ begin()

template<class T >
T * Poco::BasicFIFOBuffer< T >::begin ( )
inline

Returns the pointer to the beginning of the buffer.

Definition at line 356 of file FIFOBuffer.h.

◆ buffer()

template<class T >
const Buffer< T > & Poco::BasicFIFOBuffer< T >::buffer ( ) const
inline

Returns const reference to the underlying buffer.

Definition at line 402 of file FIFOBuffer.h.

◆ copy()

template<class T >
void Poco::BasicFIFOBuffer< T >::copy ( const T * ptr,
std::size_t length )
inline

Copies the supplied data to the buffer and adjusts the used buffer size.

Definition at line 311 of file FIFOBuffer.h.

◆ drain()

template<class T >
void Poco::BasicFIFOBuffer< T >::drain ( std::size_t length = 0)
inline

Drains length number of elements from the buffer. If length is zero or greater than buffer current content length, buffer is emptied.

Definition at line 288 of file FIFOBuffer.h.

◆ getNotify()

template<class T >
bool Poco::BasicFIFOBuffer< T >::getNotify ( ) const
inline

Returns true if notifications are enabled, false otherwise.

Definition at line 506 of file FIFOBuffer.h.

◆ hasEOF()

template<class T >
bool Poco::BasicFIFOBuffer< T >::hasEOF ( ) const
inline

Returns true if EOF flag has been set.

Definition at line 462 of file FIFOBuffer.h.

◆ isEmpty()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isEmpty ( ) const
inline

Returns true is buffer is empty, false otherwise.

Definition at line 474 of file FIFOBuffer.h.

◆ isEOF()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isEOF ( ) const
inline

Returns true if EOF flag has been set and buffer is empty.

Definition at line 468 of file FIFOBuffer.h.

◆ isFull()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isFull ( ) const
inline

Returns true is buffer is full, false otherwise.

Definition at line 480 of file FIFOBuffer.h.

◆ isReadable()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isReadable ( ) const
inline

Returns true if buffer contains data and is not in error state.

Definition at line 486 of file FIFOBuffer.h.

◆ isValid()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isValid ( ) const
inline

Returns true if error flag is not set on the buffer, otherwise returns false.

Definition at line 435 of file FIFOBuffer.h.

◆ isWritable()

template<class T >
bool Poco::BasicFIFOBuffer< T >::isWritable ( ) const
inline

Returns true if buffer is not full and is not in error state.

Definition at line 493 of file FIFOBuffer.h.

◆ mutex()

template<class T >
Mutex & Poco::BasicFIFOBuffer< T >::mutex ( )
inline

Returns reference to mutex.

Definition at line 512 of file FIFOBuffer.h.

◆ next()

template<class T >
T * Poco::BasicFIFOBuffer< T >::next ( )
inline

Returns the pointer to the next available position in the buffer.

Definition at line 371 of file FIFOBuffer.h.

◆ notify()

template<class T >
void Poco::BasicFIFOBuffer< T >::notify ( std::size_t usedBefore)
inlineprivate

Definition at line 519 of file FIFOBuffer.h.

◆ operator=()

template<class T >
BasicFIFOBuffer & Poco::BasicFIFOBuffer< T >::operator= ( const BasicFIFOBuffer< T > & )
private

◆ operator[]() [1/2]

template<class T >
T & Poco::BasicFIFOBuffer< T >::operator[] ( std::size_t index)
inline

Returns value at index position. Throws InvalidAccessException if index is larger than the last valid (used) buffer position.

Definition at line 378 of file FIFOBuffer.h.

◆ operator[]() [2/2]

template<class T >
const T & Poco::BasicFIFOBuffer< T >::operator[] ( std::size_t index) const
inline

Returns value at index position. Throws InvalidAccessException if index is larger than the last valid (used) buffer position.

Definition at line 390 of file FIFOBuffer.h.

◆ peek() [1/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::peek ( Poco::Buffer< T > & buffer,
std::size_t length = 0 ) const
inline

Peeks into the data currently in the FIFO without actually extracting it. Resizes the supplied buffer to the size of data written to it. If length is not supplied by the caller or is greater than length of currently used data, the current FIFO used data length is substituted for it.

Returns the number of elements copied in the supplied buffer.

Definition at line 155 of file FIFOBuffer.h.

◆ peek() [2/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::peek ( T * pBuffer,
std::size_t length ) const
inline

Peeks into the data currently in the FIFO without actually extracting it. If length is zero, the return is immediate. If length is greater than used length, it is substituted with the the current FIFO used length.

Returns the number of elements copied in the supplied buffer.

Definition at line 136 of file FIFOBuffer.h.

◆ read() [1/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::read ( Poco::Buffer< T > & buffer,
std::size_t length = 0 )
inline

Copies the data currently in the FIFO into the supplied buffer. Resizes the supplied buffer to the size of data written to it.

Returns the size of the copied data.

Definition at line 197 of file FIFOBuffer.h.

◆ read() [2/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::read ( T * pBuffer,
std::size_t length )
inline

Copies the data currently in the FIFO into the supplied buffer, which must be preallocated to at least the length size before calling this function.

Returns the size of the copied data.

Definition at line 174 of file FIFOBuffer.h.

◆ resize()

template<class T >
void Poco::BasicFIFOBuffer< T >::resize ( std::size_t newSize,
bool preserveContent = true )
inline

Resizes the buffer. If preserveContent is true, the content of the old buffer is preserved. New size can be larger or smaller than the current size, but it must not be 0. Additionally, if the new length is smaller than currently used length and preserveContent is true, InvalidAccessException is thrown.

Definition at line 116 of file FIFOBuffer.h.

◆ setEOF()

template<class T >
void Poco::BasicFIFOBuffer< T >::setEOF ( bool eof = true)
inline

Sets end-of-file flag on the buffer.

Setting EOF flag to true prevents writing to the buffer; reading from the buffer will still be allowed until all data present in the buffer at the EOF set time is drained. After that, to re-enable FIFOBuffer for reading/writing, EOF must be set to false.

Setting EOF flag to false clears EOF state if it was previously set. If EOF was not set, it has no effect.

Definition at line 442 of file FIFOBuffer.h.

◆ setError()

template<class T >
void Poco::BasicFIFOBuffer< T >::setError ( bool error = true)
inline

Sets the error flag on the buffer and empties it. If notifications are enabled, they will be triggered if appropriate.

Setting error flag to true prevents reading and writing to the buffer; to re-enable FIFOBuffer for reading/writing, the error flag must be set to false.

Definition at line 408 of file FIFOBuffer.h.

◆ setNotify()

template<class T >
void Poco::BasicFIFOBuffer< T >::setNotify ( bool notify = true)
inline

Enables/disables notifications.

Definition at line 500 of file FIFOBuffer.h.

◆ size()

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::size ( ) const
inline

Returns the size of the buffer.

Definition at line 270 of file FIFOBuffer.h.

◆ used()

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::used ( ) const
inline

Returns the size of the used portion of the buffer.

Definition at line 276 of file FIFOBuffer.h.

◆ write() [1/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::write ( const Buffer< T > & buffer,
std::size_t length = 0 )
inline

Writes data from supplied buffer to the FIFO buffer. If there is no sufficient space for the whole buffer to be written, data up to available length is written. The length of data to be written is determined from the length argument or buffer size (when length argument is default zero or greater than buffer size).

Returns the length of data written.

Definition at line 253 of file FIFOBuffer.h.

◆ write() [2/2]

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::write ( const T * pBuffer,
std::size_t length )
inline

Writes data from supplied buffer to the FIFO buffer. If there is no sufficient space for the whole buffer to be written, data up to available length is written. The length of data to be written is determined from the length argument. Function does nothing and returns zero if length argument is equal to zero.

Returns the length of data written.

Definition at line 219 of file FIFOBuffer.h.

Member Data Documentation

◆ _begin

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::_begin
private

Definition at line 538 of file FIFOBuffer.h.

◆ _buffer

template<class T >
Buffer<T> Poco::BasicFIFOBuffer< T >::_buffer
private

Definition at line 537 of file FIFOBuffer.h.

◆ _eof

template<class T >
bool Poco::BasicFIFOBuffer< T >::_eof
private

Definition at line 542 of file FIFOBuffer.h.

◆ _error

template<class T >
bool Poco::BasicFIFOBuffer< T >::_error
private

Definition at line 543 of file FIFOBuffer.h.

◆ _mutex

template<class T >
Mutex Poco::BasicFIFOBuffer< T >::_mutex
mutableprivate

Definition at line 541 of file FIFOBuffer.h.

◆ _notify

template<class T >
bool Poco::BasicFIFOBuffer< T >::_notify
private

Definition at line 540 of file FIFOBuffer.h.

◆ _used

template<class T >
std::size_t Poco::BasicFIFOBuffer< T >::_used
private

Definition at line 539 of file FIFOBuffer.h.

◆ readable

template<class T >
Poco::BasicEvent<bool> Poco::BasicFIFOBuffer< T >::readable
mutable

Event indicating "writability" of the buffer, triggered as follows:

  • when buffer transitions from non-full to full, Writable event observers are notified, with false value as the argument
  • when buffer transitions from full to non-full, Writable event observers are notified, with true value as the argument

Definition at line 66 of file FIFOBuffer.h.

◆ writable

template<class T >
Poco::BasicEvent<bool> Poco::BasicFIFOBuffer< T >::writable
mutable

Definition at line 54 of file FIFOBuffer.h.


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