fsfw/src/fsfw/container/FixedArrayList.h

43 lines
1.0 KiB
C
Raw Normal View History

#ifndef FIXEDARRAYLIST_H_
#define FIXEDARRAYLIST_H_
#include <cmath>
2022-05-02 16:14:23 +02:00
#include <limits>
2022-02-02 10:29:30 +01:00
#include "ArrayList.h"
/**
* \ingroup container
*/
2022-02-02 10:29:30 +01:00
template <typename T, size_t MAX_SIZE, typename count_t = uint8_t>
class FixedArrayList : public ArrayList<T, count_t> {
2022-05-02 16:14:23 +02:00
static_assert(MAX_SIZE <= std::numeric_limits<count_t>::max(),
2022-02-02 10:29:30 +01:00
"count_t is not large enough to hold MAX_SIZE");
2022-02-02 10:29:30 +01:00
private:
T data[MAX_SIZE];
2022-02-02 10:29:30 +01:00
public:
FixedArrayList() : ArrayList<T, count_t>(data, MAX_SIZE) {}
2022-02-02 10:29:30 +01:00
FixedArrayList(const FixedArrayList& other) : ArrayList<T, count_t>(data, MAX_SIZE) {
this->entries = data;
this->size = other.size;
2022-11-10 16:15:28 +01:00
for (size_t idx = 0; idx < this->size; idx++) {
data[idx] = other.data[idx];
}
2022-02-02 10:29:30 +01:00
}
2022-02-02 10:29:30 +01:00
FixedArrayList& operator=(FixedArrayList other) {
this->entries = data;
this->size = other.size;
2022-11-10 16:18:36 +01:00
for (size_t idx = 0; idx < this->size; idx++) {
data[idx] = other.data[idx];
}
2022-02-02 10:29:30 +01:00
return *this;
}
2022-02-02 10:29:30 +01:00
virtual ~FixedArrayList() {}
};
#endif /* FIXEDARRAYLIST_H_ */