added copy ctor and assignment for FIFObase

This commit is contained in:
Robin Müller 2020-07-11 01:06:01 +02:00
parent 444ee80f35
commit 6a6395313f
2 changed files with 19 additions and 1 deletions

View File

@ -18,7 +18,7 @@ template<typename T>
class DynamicFIFO: public FIFOBase<T> {
public:
DynamicFIFO(size_t maxCapacity): FIFOBase<T>(values.data(), maxCapacity),
values(maxCapacity) {};
values(maxCapacity) {};
private:
std::vector<T> values;

View File

@ -3,6 +3,7 @@
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <cstddef>
#include <cstring>
template <typename T>
class FIFOBase {
@ -43,6 +44,23 @@ public:
bool full();
size_t size();
FIFOBase(const FIFOBase& other): readIndex(other.readIndex),
writeIndex(other.writeIndex), currentSize(other.currentSize),
maxCapacity(other.maxCapacity) {
std::memcpy(values, other.values, sizeof(T) * currentSize);
}
FIFOBase& operator=(const FIFOBase& other) {
if(&other == this)
return *this;
maxCapacity = other.maxCapacity;
readIndex = other.readIndex;
writeIndex = other.writeIndex;
currentSize = other.currentSize;
std::memcpy(values, other.values, sizeof(T) * currentSize);
return *this;
}
size_t getMaxCapacity() const;
private: