fsfw/container/FixedArrayList.h

39 lines
894 B
C
Raw Normal View History

2020-08-28 18:33:29 +02:00
#ifndef FIXEDARRAYLIST_H_
#define FIXEDARRAYLIST_H_
#include "ArrayList.h"
#include <cmath>
2020-08-28 18:33:29 +02:00
/**
* \ingroup container
2020-08-28 18:33:29 +02:00
*/
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
2020-08-28 18:33:29 +02:00
class FixedArrayList: public ArrayList<T, count_t> {
static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
2020-08-28 18:33:29 +02:00
private:
T data[MAX_SIZE];
public:
FixedArrayList() :
ArrayList<T, count_t>(data, MAX_SIZE) {
}
FixedArrayList(const FixedArrayList& other) :
ArrayList<T, count_t>(data, MAX_SIZE) {
memcpy(this->data, other.data, sizeof(this->data));
this->entries = data;
this->size = other.size;
2020-08-28 18:33:29 +02:00
}
FixedArrayList& operator=(FixedArrayList other) {
memcpy(this->data, other.data, sizeof(this->data));
this->entries = data;
this->size = other.size;
2020-08-28 18:33:29 +02:00
return *this;
}
virtual ~FixedArrayList() {
}
};
#endif /* FIXEDARRAYLIST_H_ */