fsfw/container/FIFO.h

48 lines
1.1 KiB
C
Raw Normal View History

2020-09-01 12:54:33 +02:00
#ifndef FSFW_CONTAINER_FIFO_H_
#define FSFW_CONTAINER_FIFO_H_
2020-08-28 18:33:29 +02:00
2020-09-01 12:48:51 +02:00
#include "FIFOBase.h"
2020-08-28 18:33:29 +02:00
#include <array>
/**
* @brief Simple First-In-First-Out data structure with size fixed at
* compile time
* @details
* Performs no dynamic memory allocation.
* The public interface of FIFOBase exposes the user interface for the FIFO.
* @tparam T Entry Type
* @tparam capacity Maximum capacity
*/
template<typename T, size_t capacity>
class FIFO: public FIFOBase<T> {
public:
2020-09-01 12:54:33 +02:00
FIFO(): FIFOBase<T>(nullptr, capacity) {
this->setContainer(fifoArray.data());
};
2020-08-28 18:33:29 +02:00
/**
* @brief Custom copy constructor to set pointer correctly.
* @param other
*/
FIFO(const FIFO& other): FIFOBase<T>(other) {
2020-09-07 15:23:27 +02:00
this->fifoArray = other.fifoArray;
2020-09-01 12:54:33 +02:00
this->setContainer(fifoArray.data());
2020-08-28 18:33:29 +02:00
}
2020-09-10 15:03:28 +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-08-28 18:33:29 +02:00
private:
std::array<T, capacity> fifoArray;
};
2020-09-01 12:54:33 +02:00
#endif /* FSFW_CONTAINER_FIFO_H_ */