From 88f229cef924fcb45c46b8d6e002c3d8142f60d8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 23 Apr 2020 15:03:55 +0200 Subject: [PATCH 1/2] fifo enhancement --- container/FIFO.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/container/FIFO.h b/container/FIFO.h index 134da9b8..889d2ade 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -3,6 +3,11 @@ #include +/** + * @brief Simple First-In-First-Out data structure + * @tparam T Entry Type + * @tparam capacity Maximum capacity + */ template class FIFO { private: @@ -54,6 +59,26 @@ public: return HasReturnvaluesIF::RETURN_OK; } } + + ReturnValue_t peek(T * value) { + if(empty()) { + return EMPTY; + } else { + *value = data[readIndex]; + return HasReturnvaluesIF::RETURN_OK; + } + } + + ReturnValue_t pop() { + if(empty()) { + return EMPTY; + } else { + readIndex = next(readIndex); + --currentSize; + return HasReturnvaluesIF::RETURN_OK; + } + } + static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS; static const ReturnValue_t FULL = MAKE_RETURN_CODE(1); static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2); From df9e66834e5ccb7d7d81a07b199baaebd4f6826c Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 5 May 2020 19:07:11 +0200 Subject: [PATCH 2/2] pop() better --- container/FIFO.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/container/FIFO.h b/container/FIFO.h index 889d2ade..f70c78b0 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -70,13 +70,8 @@ public: } ReturnValue_t pop() { - if(empty()) { - return EMPTY; - } else { - readIndex = next(readIndex); - --currentSize; - return HasReturnvaluesIF::RETURN_OK; - } + T value; + return this->retrieve(&value); } static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;