From 6459a79cec4a2cf67a04446334cafdf1fdac7ed6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 30 Sep 2020 20:34:16 +0200 Subject: [PATCH] reverted container changes --- container/ArrayList.h | 147 ++++++++++++++++++++++-------------------- container/FixedMap.h | 39 +---------- 2 files changed, 78 insertions(+), 108 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 6bd5c1d5a..19454777b 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -1,15 +1,15 @@ -#ifndef FSFW_CONTAINER_ARRAYLIST_H_ -#define FSFW_CONTAINER_ARRAYLIST_H_ +#ifndef ARRAYLIST_H_ +#define ARRAYLIST_H_ #include "../returnvalues/HasReturnvaluesIF.h" #include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeIF.h" /** - * @brief A List that stores its values in an array. - * @details - * The underlying storage is an array that can be allocated by the class - * itself or supplied via ctor. + * A List that stores its values in an array. + * + * The backend is an array that can be allocated by the class itself or supplied via ctor. + * * * @ingroup container */ @@ -20,53 +20,6 @@ public: static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST; static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01); - /** - * This is the allocating constructor. - * It allocates an array of the specified size. - * @param maxSize - */ - ArrayList(count_t maxSize) : - size(0), maxSize_(maxSize), allocated(true) { - entries = new T[maxSize]; - } - - /** - * This is the non-allocating constructor - * - * It expects a pointer to an array of a certain size and initializes - * itself to it. - * - * @param storage the array to use as backend - * @param maxSize size of storage - * @param size size of data already present in storage - */ - ArrayList(T *storage, count_t maxSize, count_t size = 0) : - size(size), entries(storage), maxSize_(maxSize), allocated(false) { - } - - /** - * Copying is forbiden by declaring copy ctor and copy assignment deleted - * It is too ambigous in this case. - * (Allocate a new backend? Use the same? What to do in an modifying call?) - */ - ArrayList(const ArrayList& other) = delete; - const ArrayList& operator=(const ArrayList& other) = delete; - - /** - * Number of Elements stored in this List - */ - count_t size; - - - /** - * Destructor, if the allocating constructor was used, it deletes the array. - */ - virtual ~ArrayList() { - if (allocated) { - delete[] entries; - } - } - /** * An Iterator to go trough an ArrayList * @@ -78,7 +31,10 @@ public: /** * Empty ctor, points to NULL */ - Iterator(): value(0) {} + Iterator() : + value(0) { + + } /** * Initializes the Iterator to point to an element @@ -116,31 +72,70 @@ public: return tmp; } - T& operator*() { + T& operator*(){ return *value; } - const T& operator*() const { + const T& operator*() const{ return *value; } - T *operator->() { + T *operator->(){ return value; } - const T *operator->() const { + const T *operator->() const{ return value; } + + //SHOULDDO this should be implemented as non-member + bool operator==(const typename ArrayList::Iterator& other) const{ + return (value == other.value); + } + + //SHOULDDO this should be implemented as non-member + bool operator!=(const typename ArrayList::Iterator& other) const { + return !(*this == other); + } }; - friend bool operator==(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return (lhs.value == rhs.value); + /** + * Number of Elements stored in this List + */ + count_t size; + + /** + * This is the allocating constructor; + * + * It allocates an array of the specified size. + * + * @param maxSize + */ + ArrayList(count_t maxSize) : + size(0), maxSize_(maxSize), allocated(true) { + entries = new T[maxSize]; } - friend bool operator!=(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return not (lhs.value == rhs.value); + /** + * This is the non-allocating constructor + * + * It expects a pointer to an array of a certain size and initializes itself to it. + * + * @param storage the array to use as backend + * @param maxSize size of storage + * @param size size of data already present in storage + */ + ArrayList(T *storage, count_t maxSize, count_t size = 0) : + size(size), entries(storage), maxSize_(maxSize), allocated(false) { + } + + /** + * Destructor, if the allocating constructor was used, it deletes the array. + */ + virtual ~ArrayList() { + if (allocated) { + delete[] entries; + } } /** @@ -196,7 +191,7 @@ public: * * @return maximum number of elements */ - size_t maxSize() const { + uint32_t maxSize() const { return this->maxSize_; } @@ -231,7 +226,19 @@ public: count_t remaining() { return (maxSize_ - size); } - +private: + /** + * This is the copy constructor + * + * It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same? + * What to do in an modifying call?) + * + * @param other + */ + ArrayList(const ArrayList& other) : + size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated( + false) { + } protected: /** * pointer to the array in which the entries are stored @@ -240,14 +247,12 @@ protected: /** * remembering the maximum size */ - size_t maxSize_; + uint32_t maxSize_; /** * true if the array was allocated and needs to be deleted in the destructor. */ bool allocated; + }; - - - -#endif /* FSFW_CONTAINER_ARRAYLIST_H_ */ +#endif /* ARRAYLIST_H_ */ diff --git a/container/FixedMap.h b/container/FixedMap.h index 7a5220faa..d1cc31ff1 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -7,21 +7,14 @@ #include /** - * @brief Map implementation for maps with a pre-defined size. - * @details - * Can be initialized with desired maximum size. - * Iterator is used to access pair and iterate through map entries. - * Complexity O(n). * @warning Iterators return a non-const key_t in the pair. * @warning A User is not allowed to change the key, otherwise the map is corrupted. * @ingroup container */ template class FixedMap: public SerializeIF { - static_assert (std::is_trivially_copyable::value or - std::is_base_of::value, - "Types used in FixedMap must either be trivial copy-able or a " - "derived class from SerializeIF to be serialize-able"); + static_assert (std::is_trivially_copyable::value or std::is_base_of::value, + "Types used in FixedMap must either be trivial copy-able or a derived Class from SerializeIF to be serialize-able"); public: static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); @@ -61,16 +54,6 @@ public: } }; - friend bool operator==(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return (lhs.value == rhs.value); - } - - friend bool operator!=(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return not (lhs.value == rhs.value); - } - Iterator begin() const { return Iterator(&theMap[0]); } @@ -153,24 +136,6 @@ public: return HasReturnvaluesIF::RETURN_OK; } - bool empty() { - if(_size == 0) { - return true; - } - else { - return false; - } - } - - bool full() { - if(_size >= theMap.maxSize()) { - return true; - } - else { - return false; - } - } - void clear() { _size = 0; }