taken over fixed array list from master
This commit is contained in:
parent
1ecca4b3d8
commit
5fbb8f8ef0
@ -1,51 +1,32 @@
|
||||
#ifndef FIXEDARRAYLIST_H_
|
||||
#define FIXEDARRAYLIST_H_
|
||||
|
||||
#include "../container/ArrayList.h"
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include <cmath>
|
||||
/**
|
||||
* @brief Array List with a fixed maximum size
|
||||
* @ingroup container
|
||||
* \ingroup container
|
||||
*/
|
||||
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
|
||||
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");
|
||||
private:
|
||||
T data[MAX_SIZE];
|
||||
public:
|
||||
/**
|
||||
* (Robin) Maybe we should also implement move assignment and move ctor.
|
||||
* Or at least delete them.
|
||||
*/
|
||||
FixedArrayList() :
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
}
|
||||
|
||||
// (Robin): 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?
|
||||
/**
|
||||
* Initialize a fixed array list with data and number of data fields.
|
||||
* Endianness of entries can be swapped optionally.
|
||||
* @param data_
|
||||
* @param count
|
||||
* @param swapArrayListEndianess
|
||||
*/
|
||||
FixedArrayList(T * data_, count_t count):
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, data_, count * sizeof(T));
|
||||
this->size = count;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
FixedArrayList& operator=(FixedArrayList other) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
this->entries = data;
|
||||
this->size = other.size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user