1
0
forked from fsfw/fsfw

fifo replacements

This commit is contained in:
2020-07-07 17:42:37 +02:00
parent dd48f7ccad
commit 399fc0e287
10 changed files with 48 additions and 61 deletions

27
container/DynamicFIFO.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
#define FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
#include <framework/container/FIFOBase.h>
#include <vector>
/**
* @brief Simple First-In-First-Out data structure. The maximum size
* can be set in the constructor.
* @details
* The maximum capacity can be determined at run-time, so this container
* performs 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>
class DynamicFIFO: public FIFOBase<T> {
public:
DynamicFIFO(size_t maxCapacity): FIFOBase<T>(values.data(), maxCapacity),
values(maxCapacity) {};
private:
std::vector<T> values;
};
#endif /* FRAMEWORK_CONTAINER_DYNAMICFIFO_H_ */

View File

@ -1,31 +1,26 @@
#ifndef FRAMEWORK_CONTAINER_FIFO_H_
#define FRAMEWORK_CONTAINER_FIFO_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/container/FIFOBase.h>
#include <vector>
namespace fsfw {
#include <array>
/**
* @brief Simple First-In-First-Out data structure. The maximum size
* can be set in the constructor.
* @brief Simple First-In-First-Out data structure with size fixed at
* compile time
* @details
* The maximum capacity can be determined at run-time, so this container
* performs dynamic memory allocation!
* 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>
template<typename T, size_t capacity>
class FIFO: public FIFOBase<T> {
public:
FIFO(size_t maxCapacity): FIFOBase<T>(values.data(), maxCapacity),
values(maxCapacity) {};
FIFO(): FIFOBase<T>(values.data(), capacity) {};
private:
std::vector<T> values;
std::array<T, capacity> values;
};
}
#endif /* FRAMEWORK_CONTAINER_FIFO_H_ */
#endif /* FRAMEWORK_CONTAINERS_STATICFIFO_H_ */

View File

@ -4,8 +4,6 @@
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <cstddef>
namespace fsfw {
template <typename T>
class FIFOBase {
public:
@ -60,6 +58,4 @@ private:
#include <framework/container/FIFOBase.tpp>
}
#endif /* FRAMEWORK_CONTAINER_FIFOBASE_H_ */

View File

@ -17,7 +17,7 @@ SimpleRingBuffer::~SimpleRingBuffer() {
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
uint32_t amount) {
if (availableWriteSpace() >= amount || overwriteOld) {
if (availableWriteSpace() >= amount or overwriteOld) {
uint32_t amountTillWrap = writeTillWrap();
if (amountTillWrap >= amount) {
memcpy(&buffer[write], data, amount);
@ -43,7 +43,7 @@ ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
return HasReturnvaluesIF::RETURN_FAILED;
}
}
if (trueAmount != NULL) {
if (trueAmount != nullptr) {
*trueAmount = amount;
}
if (amountTillWrap >= amount) {
@ -65,7 +65,7 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
return HasReturnvaluesIF::RETURN_FAILED;
}
}
if (trueAmount != NULL) {
if (trueAmount != nullptr) {
*trueAmount = amount;
}
incrementRead(amount, READ_PTR);

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_
#include <framework/container/RingBufferBase.h>
#include <stddef.h>
#include <cstddef>
/**
* @brief Circular buffer implementation, useful for buffering

View File

@ -1,30 +0,0 @@
#ifndef FRAMEWORK_CONTAINER_STATICFIFO_H_
#define FRAMEWORK_CONTAINER_STATICFIFO_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/container/FIFOBase.h>
#include <array>
namespace fsfw {
/**
* @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 StaticFIFO: public FIFOBase<T> {
public:
StaticFIFO(): FIFOBase<T>(values.data(), capacity) {};
private:
std::array<T, capacity> values;
};
}
#endif /* FRAMEWORK_CONTAINERS_STATICFIFO_H_ */