2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FIXEDARRAYLIST_H_
|
|
|
|
#define FIXEDARRAYLIST_H_
|
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "ArrayList.h"
|
2020-09-30 12:50:52 +02:00
|
|
|
#include <cmath>
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
|
|
|
* \ingroup container
|
|
|
|
*/
|
2020-09-30 12:50:52 +02:00
|
|
|
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
|
2016-06-15 23:48:41 +02:00
|
|
|
class FixedArrayList: public ArrayList<T, count_t> {
|
2021-01-28 11:50:33 +01:00
|
|
|
static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
|
2016-06-15 23:48:41 +02:00
|
|
|
private:
|
2021-01-28 11:50:33 +01:00
|
|
|
T data[MAX_SIZE];
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2021-01-28 11:50:33 +01:00
|
|
|
FixedArrayList() :
|
|
|
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
FixedArrayList& operator=(FixedArrayList other) {
|
|
|
|
memcpy(this->data, other.data, sizeof(this->data));
|
|
|
|
this->entries = data;
|
|
|
|
this->size = other.size;
|
|
|
|
return *this;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
virtual ~FixedArrayList() {
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FIXEDARRAYLIST_H_ */
|