From 1977942c4b2a785e503c21f5cd5cc235ee69e9ed Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 22 Jan 2020 14:24:48 +0100 Subject: [PATCH] Array List Entry swapper function And respective SerialAdapter functions to use it --- container/ArrayList.h | 19 +++++++++++++++++++ container/FixedArrayList.h | 9 +++++++-- serialize/SerialArrayListAdapter.h | 15 ++------------- serialize/SerialFixedArrayListAdapter.h | 4 ++++ serialize/SerializeElement.h | 4 ++++ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 9c4c4ceb..0a2c2ff7 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -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 diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index b9394cfe..36d37979 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -2,8 +2,10 @@ #define FIXEDARRAYLIST_H_ #include + /** - * \ingroup container + * @brief Array List with a fixed maximum size + * @ingroup container */ template class FixedArrayList: public ArrayList { @@ -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(data, MAX_SIZE) { memcpy(this->data, data_, count); this->size = count; + if(swapArrayListEndianess) { + ArrayList::swapArrayListEndianness(); + } } FixedArrayList(const FixedArrayList& other) : diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 21cbbc4d..3f80e97b 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -79,20 +79,9 @@ public: return result; } - /** - * Swap the endianness of the Array list (not the length field !) - * Useful if the case the buffer type is large than uint8_t and the endianness - * is inconsistent with other SerializeElements. - * @param list - */ + static void swapArrayListEndianness(ArrayList* list) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - count_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { - T newEntry = EndianSwapper::swap(list->entries[i]); - list->entries[i] = newEntry; - ++i; - } + list->swapArrayListEndianness(); } private: ArrayList *adaptee; diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 9613f6c1..67954d68 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -24,6 +24,10 @@ template class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { public: + /** + * Constructor Arguments are forwarded to FixedArrayList constructor + * @param args + */ template SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { } diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index 4f5a22b6..cd040c0f 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -19,6 +19,10 @@ template class SerializeElement : public SerializeIF, public LinkedElement { public: + /** + * Arguments are forwarded to the element datatype constructor + * @param args + */ template SerializeElement(Args... args) : LinkedElement(this), entry(std::forward(args)...) {