2020-08-27 20:19:27 +02:00
|
|
|
#ifndef FSFW_CONTAINER_FIFOBASE_H_
|
|
|
|
#define FSFW_CONTAINER_FIFOBASE_H_
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2020-08-27 20:18:06 +02:00
|
|
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
2020-07-06 13:26:58 +02:00
|
|
|
#include <cstddef>
|
2020-07-28 13:13:40 +02:00
|
|
|
#include <cstring>
|
2020-07-06 13:26:58 +02:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class FIFOBase {
|
|
|
|
public:
|
2021-01-28 11:44:49 +01:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;
|
|
|
|
static const ReturnValue_t FULL = MAKE_RETURN_CODE(1);
|
|
|
|
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2);
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
/** Default ctor, takes pointer to first entry of underlying container
|
|
|
|
* and maximum capacity */
|
|
|
|
FIFOBase(T* values, const size_t maxCapacity);
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
/**
|
|
|
|
* Insert value into FIFO
|
|
|
|
* @param value
|
|
|
|
* @return RETURN_OK on success, FULL if full
|
|
|
|
*/
|
|
|
|
ReturnValue_t insert(T value);
|
|
|
|
/**
|
|
|
|
* Retrieve item from FIFO. This removes the item from the FIFO.
|
|
|
|
* @param value Must point to a valid T
|
|
|
|
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
|
|
|
*/
|
|
|
|
ReturnValue_t retrieve(T *value);
|
|
|
|
/**
|
|
|
|
* Retrieve item from FIFO without removing it from FIFO.
|
|
|
|
* @param value Must point to a valid T
|
|
|
|
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
|
|
|
*/
|
|
|
|
ReturnValue_t peek(T * value);
|
|
|
|
/**
|
|
|
|
* Remove item from FIFO.
|
|
|
|
* @return RETURN_OK on success, EMPTY if empty
|
|
|
|
*/
|
|
|
|
ReturnValue_t pop();
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
/***
|
|
|
|
* Check if FIFO is empty
|
|
|
|
* @return True if empty, False if not
|
|
|
|
*/
|
|
|
|
bool empty();
|
|
|
|
/***
|
|
|
|
* Check if FIFO is Full
|
|
|
|
* @return True if full, False if not
|
|
|
|
*/
|
|
|
|
bool full();
|
|
|
|
/***
|
|
|
|
* Current used size (elements) used
|
|
|
|
* @return size_t in elements
|
|
|
|
*/
|
|
|
|
size_t size();
|
|
|
|
/***
|
|
|
|
* Get maximal capacity of fifo
|
|
|
|
* @return size_t with max capacity of this fifo
|
|
|
|
*/
|
|
|
|
size_t getMaxCapacity() const;
|
2020-07-06 23:08:31 +02:00
|
|
|
|
2020-07-28 13:13:40 +02:00
|
|
|
protected:
|
2021-01-28 11:44:49 +01:00
|
|
|
void setContainer(T* data);
|
|
|
|
size_t maxCapacity = 0;
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
T* values;
|
2020-07-28 13:13:40 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
size_t readIndex = 0;
|
|
|
|
size_t writeIndex = 0;
|
|
|
|
size_t currentSize = 0;
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2021-01-28 11:44:49 +01:00
|
|
|
size_t next(size_t current);
|
2020-07-06 13:26:58 +02:00
|
|
|
};
|
|
|
|
|
2020-08-27 20:18:06 +02:00
|
|
|
#include "FIFOBase.tpp"
|
2020-07-06 13:26:58 +02:00
|
|
|
|
2020-08-27 20:19:27 +02:00
|
|
|
#endif /* FSFW_CONTAINER_FIFOBASE_H_ */
|