BDS Public
Beamlib 3.3.4
This is the Beam C++ class library.
Loading...
Searching...
No Matches
BFifo.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BFifo.h BFifo class
3 * T.Barnaby, Beam Ltd, 2013-05-03
4 * Copyright (c) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5 * For license see LICENSE.txt at the root of the beamlib source tree.
6 *******************************************************************************
7 *
8 */
18#ifndef BFifo_h
19#define BFifo_h
20
21#include <BTypes.h>
22#include <BError.h>
23
25template <class Type> class BFifo {
26public:
29
30 void clear();
31
35
38 BError write(const Type v);
39 BError write(const Type* data, BUInt num);
40
41 Type* writeData();
42 Type* writeData(BUInt& num);
43 void writeDone(BUInt num);
44 void writeBackup(BUInt num);
45
48 Type read();
49 BError read(Type* data, BUInt num);
50
51 Type* readData();
52 Type* readData(BUInt& num);
53 void readDone(BUInt num);
54
55 Type readPos(BUInt pos);
56 void writePos(BUInt pos, const Type& v);
57 Type& operator[](int pos);
58
59protected:
61 Type* odata;
62 volatile BUInt owritePos;
63 volatile BUInt oreadPos;
64};
65
66#include <BFifo.inc>
67#endif
BUInt32 BUInt
Definition BTypes.h:33
char data[8]
Definition BoapMc1.h:2
Error return class. This class is used to return the error status from a function....
Definition BError.h:31
A template first in first out data buffer to store any object types.
Definition BFifo.h:25
Type read()
Read one item.
Type * odata
FIFO memory buffer.
Definition BFifo.h:61
BFifo(BUInt size)
BError resize(BUInt size)
Resize FIFO, clears it as well.
BUInt writeAvailableChunk()
How many items that can be written in a chunk.
BUInt size()
Returns fifo size.
void writeDone(BUInt num)
Indicates when write is complete.
BError rebase()
Rebases fifo so read pointer is at zero moving memory as needed.
Type readPos(BUInt pos)
Read item at given offset from current read position.
BError read(Type *data, BUInt num)
Read a set of items.
Type * writeData(BUInt &num)
Returns a pointer to the data and how many can be written in a chunk.
void clear()
void writeBackup(BUInt num)
Backup, remove num items at end of fifo. Careful, make sure read is not already happening.
BError write(const Type *data, BUInt num)
Write a set of items. Can only write a maximum of writeAvailableChunk() to save going beyond end of F...
void writePos(BUInt pos, const Type &v)
Write item at given offset from current read position.
Type & operator[](int pos)
Direct access to read samples in buffer.
BUInt osize
The size of the FIFO.
Definition BFifo.h:60
Type * readData(BUInt &num)
Returns a pointer to the data and how many can be read in a chunk.
volatile BUInt oreadPos
The read pointer.
Definition BFifo.h:63
BUInt readAvailableChunk()
How many items are available to read in a chunk.
volatile BUInt owritePos
The write pointer.
Definition BFifo.h:62
BUInt writeAvailable()
How many items that can be written.
void readDone(BUInt num)
Type * writeData()
Returns a pointer to the data.
BUInt readAvailable()
How many items are available to read.
BError write(const Type v)
Write a single item.
Type * readData()
Returns a pointer to the data.