Merge pull request 'Added a compile time check in FixedArrayList and fixed copying' (#222) from gaisser/fsfw:gaisser_fixedArrayList_assert into master

Reviewed-on: fsfw/fsfw#222
This commit is contained in:
Robin Müller 2020-10-01 11:10:53 +02:00
commit d647c63da3
1 changed files with 5 additions and 1 deletions

View File

@ -2,11 +2,13 @@
#define FIXEDARRAYLIST_H_
#include "ArrayList.h"
#include <cmath>
/**
* \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:
@ -18,11 +20,13 @@ public:
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;
}