fsfw/container/FIFO.h

48 lines
1.1 KiB
C
Raw Normal View History

2020-09-01 12:53:53 +02:00
#ifndef FSFW_CONTAINER_FIFO_H_
#define FSFW_CONTAINER_FIFO_H_
#include "FIFOBase.h"
2020-07-07 17:44:15 +02:00
#include <array>
2020-07-06 13:38:11 +02:00
2020-04-23 15:03:55 +02:00
/**
2020-07-07 17:44:15 +02:00
* @brief Simple First-In-First-Out data structure with size fixed at
* compile time
2020-07-06 13:40:13 +02:00
* @details
2020-07-07 17:44:15 +02:00
* Performs no dynamic memory allocation.
2020-07-06 13:40:13 +02:00
* The public interface of FIFOBase exposes the user interface for the FIFO.
2020-04-23 15:03:55 +02:00
* @tparam T Entry Type
* @tparam capacity Maximum capacity
*/
2020-07-07 17:44:15 +02:00
template<typename T, size_t capacity>
2020-07-06 13:26:58 +02:00
class FIFO: public FIFOBase<T> {
public:
2020-09-01 12:53:53 +02:00
FIFO(): FIFOBase<T>(nullptr, capacity) {
this->setContainer(fifoArray.data());
};
2020-07-28 13:13:40 +02:00
/**
* @brief Custom copy constructor to set pointer correctly.
* @param other
*/
FIFO(const FIFO& other): FIFOBase<T>(other) {
2020-09-07 15:43:48 +02:00
this->fifoArray = other.fifoArray;
2020-09-01 12:53:53 +02:00
this->setContainer(fifoArray.data());
2020-07-28 13:13:40 +02:00
}
2020-09-07 15:43:48 +02:00
/**
* @brief Custom assignment operator
* @param other
*/
FIFO& operator=(const FIFO& other){
FIFOBase<T>::operator=(other);
this->fifoArray = other.fifoArray;
this->setContainer(fifoArray.data());
return *this;
}
2020-07-06 13:26:58 +02:00
private:
2020-07-28 13:13:40 +02:00
std::array<T, capacity> fifoArray;
};
2020-09-01 12:53:53 +02:00
#endif /* FSFW_CONTAINER_FIFO_H_ */