adtf_file_library
0.13.1
|
#include <fileringbuffer.h>
Classes | |
class | DropCallback |
struct | Item |
struct | ItemPiece |
Public Types | |
typedef std::deque< Item > | Items |
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 FileSize & | getCurrentSize () |
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 () |
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.
|
inline |
Constructor.
[in] | file | A pointer to an open file. |
[in] | start_offset | The offset where the ring buffer should start. |
[in] | max_size | An optional size after which wrapping around will start. automatically, if zero, use StartWrappingAround. |
[in] | drop_callback | A callback that will inform about dropped items. |
|
inline |
Adds a new item that is made up by multiple data buffers at the end of the buffer.
[in] | pieces | An array of item pieces. |
[in] | count | The amount of pieces in the array. |
[in] | additional | Additional bookkeeping data. |
[out] | file_pos | The postion where the item was stored. |
|
inline |
Adds a new item at the end of the buffer.
[in] | data | The data of the item. |
[in] | data_size | The size of the data. |
[in] | additional | Additional bookkeeping data. |
[out] | file_pos | The postion where the item was stored. |
|
inline |
Retunrs an iterator to the beginning of the buffer.
|
inline |
Retuns an iterator to the end of the buffer.
|
inlineprotected |
Writes data to the file until a field position is reached that satisfies the alignment requirement.
|
inline |
Returns the current size of the buffer.
|
inlineprotected |
Removes the first item in the buffer.
|
inline |
After a call to this method, data will be appended after the ring buffer.
[out] | rear_data_item | A pointer that will bes set to point to the rear item in the buffer (the position where the buffer wraps around). |
[out] | last_data_item | A pointer that will bes set to point to the last item in the buffer. |
|
inline |
Limits the size of the buffer by the current size.