2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FIXEDARRAYLIST_H_
|
|
|
|
#define FIXEDARRAYLIST_H_
|
|
|
|
|
|
|
|
#include <framework/container/ArrayList.h>
|
2020-01-22 14:24:48 +01:00
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2020-01-22 14:24:48 +01:00
|
|
|
* @brief Array List with a fixed maximum size
|
|
|
|
* @ingroup container
|
2019-08-28 14:50:24 +02:00
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
|
|
|
class FixedArrayList: public ArrayList<T, count_t> {
|
|
|
|
private:
|
|
|
|
T data[MAX_SIZE];
|
|
|
|
public:
|
|
|
|
FixedArrayList() :
|
|
|
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
|
|
|
}
|
|
|
|
|
2020-01-16 18:46:29 +01:00
|
|
|
//We could create a constructor to initialize the fixed array list with data and the known size field
|
|
|
|
//so it can be used for serialization too (with SerialFixedArrrayListAdapter)
|
|
|
|
//is this feasible?
|
2020-01-22 14:24:48 +01:00
|
|
|
FixedArrayList(T * data_, count_t count, bool swapArrayListEndianess = false):
|
2020-01-18 15:03:22 +01:00
|
|
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
2020-01-27 00:43:01 +01:00
|
|
|
memcpy(this->data, data_, count * sizeof(T));
|
2020-01-18 15:03:22 +01:00
|
|
|
this->size = count;
|
2020-01-22 14:24:48 +01:00
|
|
|
if(swapArrayListEndianess) {
|
|
|
|
ArrayList<T, count_t>::swapArrayListEndianness();
|
|
|
|
}
|
2020-01-18 15:03:22 +01:00
|
|
|
}
|
2020-01-16 18:46:29 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
FixedArrayList(const FixedArrayList& other) :
|
|
|
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
|
|
|
memcpy(this->data, other.data, sizeof(this->data));
|
|
|
|
this->entries = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
FixedArrayList& operator=(FixedArrayList other) {
|
|
|
|
memcpy(this->data, other.data, sizeof(this->data));
|
|
|
|
this->entries = data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FixedArrayList() {
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FIXEDARRAYLIST_H_ */
|