From a0098e8b17e42d43e64d7d9ef7a78f8cc66b137b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 30 Sep 2020 18:57:30 +0200 Subject: [PATCH] non member comp operator for iterators --- container/FixedMap.h | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index d1cc31ff..7a5220fa 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -7,14 +7,21 @@ #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); @@ -54,6 +61,16 @@ 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]); } @@ -136,6 +153,24 @@ 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; }