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

@ -3,6 +3,7 @@
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
#include <cstddef> #include <cstddef>
#include <cstring>
template <typename T> template <typename T>
class FIFOBase { class FIFOBase {
@ -43,6 +44,23 @@ public:
bool full(); bool full();
size_t size(); 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; size_t getMaxCapacity() const;
private: private: