adtf_file_library  0.13.1
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment > Class Template Reference

#include <fileringbuffer.h>

Classes

class  DropCallback
 
struct  Item
 
struct  ItemPiece
 

Public Types

typedef std::deque< ItemItems
 Typedef for convienient access.
 
typedef Items::const_iterator const_iterator
 An const iterator in the buffer.
 

Public Member Functions

 FileRingBuffer (File *file, FilePos start_offset=0, FileSize max_size=0, DropCallback *drop_callback=nullptr)
 
const FileSizegetCurrentSize ()
 
void startWrappingAround ()
 
void startAppending (Item *rear_data_item=nullptr, Item *last_data_item=nullptr)
 
void appendItem (const void *data, size_t data_size, const ADDITIONAL_DATA &additional, FilePos *file_pos=nullptr)
 
void appendItem (const ItemPiece *pieces, size_t count, const ADDITIONAL_DATA &additional, FilePos *file_pos=nullptr)
 
const_iterator begin () const
 
const_iterator end () const
 

Protected Member Functions

void fillForAlignment ()
 
void popFront ()
 

Detailed Description

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
class utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >

File-based ring buffer.

A ring buffer implementation that supports variable sized elements and stores the actual data in a file. Mind that bookkeeping data is still kept in memory.

Use the template argument to store any additional data that you need in the drop callback which is called whenever an item is removed from the head of the buffer.

Start by calling the constructor with an already opend file. Then append items using the AppendItem() method. When you want to start wrapping around, call StartWrappingAround(). This will limit the ring buffer size by the current size. When you want to continue writing past the end of the ringbuffer, call StartAppending() and the file will then grow indefinitly.

Constructor & Destructor Documentation

◆ FileRingBuffer()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::FileRingBuffer ( File file,
FilePos  start_offset = 0,
FileSize  max_size = 0,
DropCallback drop_callback = nullptr 
)
inline

Constructor.

Parameters
[in]fileA pointer to an open file.
[in]start_offsetThe offset where the ring buffer should start.
[in]max_sizeAn optional size after which wrapping around will start. automatically, if zero, use StartWrappingAround.
[in]drop_callbackA callback that will inform about dropped items.

Member Function Documentation

◆ appendItem() [1/2]

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::appendItem ( const ItemPiece pieces,
size_t  count,
const ADDITIONAL_DATA &  additional,
FilePos file_pos = nullptr 
)
inline

Adds a new item that is made up by multiple data buffers at the end of the buffer.

Parameters
[in]piecesAn array of item pieces.
[in]countThe amount of pieces in the array.
[in]additionalAdditional bookkeeping data.
[out]file_posThe postion where the item was stored.

◆ appendItem() [2/2]

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::appendItem ( const void *  data,
size_t  data_size,
const ADDITIONAL_DATA &  additional,
FilePos file_pos = nullptr 
)
inline

Adds a new item at the end of the buffer.

Parameters
[in]dataThe data of the item.
[in]data_sizeThe size of the data.
[in]additionalAdditional bookkeeping data.
[out]file_posThe postion where the item was stored.

◆ begin()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
const_iterator utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::begin ( ) const
inline

Retunrs an iterator to the beginning of the buffer.

Returns
An iterator to the beginning of the buffer.

◆ end()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
const_iterator utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::end ( ) const
inline

Retuns an iterator to the end of the buffer.

Returns
An iterator to the end of the buffer.

◆ fillForAlignment()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::fillForAlignment ( )
inlineprotected

Writes data to the file until a field position is reached that satisfies the alignment requirement.

◆ getCurrentSize()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
const FileSize& utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::getCurrentSize ( )
inline

Returns the current size of the buffer.

Returns
The current size of the buffer.

◆ popFront()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::popFront ( )
inlineprotected

Removes the first item in the buffer.

◆ startAppending()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::startAppending ( Item rear_data_item = nullptr,
Item last_data_item = nullptr 
)
inline

After a call to this method, data will be appended after the ring buffer.

Parameters
[out]rear_data_itemA pointer that will bes set to point to the rear item in the buffer (the position where the buffer wraps around).
[out]last_data_itemA pointer that will bes set to point to the last item in the buffer.

◆ startWrappingAround()

template<typename ADDITIONAL_DATA = uint8_t, uint8_t alignment = 1>
void utils5ext::FileRingBuffer< ADDITIONAL_DATA, alignment >::startWrappingAround ( )
inline

Limits the size of the buffer by the current size.


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

Copyright © CARIAD SE.
Generated on Fri Apr 19 2024 by doxygen 1.9.1
GIT Commit Hash: 82d535f82776c20b12fc60740bdae991b62444a7