Array List Entry swapper function
And respective SerialAdapter functions to use it
This commit is contained in:
@ -223,6 +223,25 @@ public:
|
||||
count_t remaining() {
|
||||
return (maxSize_ - size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the endianness of the Array list (not the length field !)
|
||||
* Useful if the case the buffer type is larger than uint8_t
|
||||
* @param list
|
||||
*/
|
||||
void swapArrayListEndianness() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
count_t i = 0;
|
||||
// uint8_t buffer does not require swapping of entries.
|
||||
if(sizeof(T) == 1) {
|
||||
return;
|
||||
}
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < size)) {
|
||||
T newEntry = EndianSwapper::swap(entries[i]);
|
||||
entries[i] = newEntry;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* This is the copy constructor
|
||||
|
@ -2,8 +2,10 @@
|
||||
#define FIXEDARRAYLIST_H_
|
||||
|
||||
#include <framework/container/ArrayList.h>
|
||||
|
||||
/**
|
||||
* \ingroup container
|
||||
* @brief Array List with a fixed maximum size
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class FixedArrayList: public ArrayList<T, count_t> {
|
||||
@ -17,10 +19,13 @@ public:
|
||||
//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?
|
||||
FixedArrayList(T * data_, count_t count):
|
||||
FixedArrayList(T * data_, count_t count, bool swapArrayListEndianess = false):
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, data_, count);
|
||||
this->size = count;
|
||||
if(swapArrayListEndianess) {
|
||||
ArrayList<T, count_t>::swapArrayListEndianness();
|
||||
}
|
||||
}
|
||||
|
||||
FixedArrayList(const FixedArrayList& other) :
|
||||
|
Reference in New Issue
Block a user