GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/FifoQueueBase.hpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 4 4 100.0%
Branches: 12 15 80.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title FifoQueueBase
3 // \author bocchino
4 // \brief An abstract base class template for a FIFO queue
5 // ======================================================================
6
7 #ifndef Fw_FifoQueueBase_HPP
8 #define Fw_FifoQueueBase_HPP
9
10 #include "Fw/DataStructures/SizedContainer.hpp"
11 #include "Fw/Types/Assert.hpp"
12 #include "Fw/Types/SuccessEnumAc.hpp"
13
14 namespace Fw {
15
16 template <typename T>
17 class FifoQueueBase : public SizedContainer {
18 private:
19 // ----------------------------------------------------------------------
20 // Private constructors
21 // ----------------------------------------------------------------------
22
23 //! Copy constructor deleted in the base class
24 //! Behavior depends on the implementation
25 FifoQueueBase(const FifoQueueBase<T>&) = delete;
26
27 protected:
28 // ----------------------------------------------------------------------
29 // Protected constructors and destructors
30 // ----------------------------------------------------------------------
31
32 //! Zero-argument constructor
33 53 FifoQueueBase() : SizedContainer() {}
34
35 //! Destructor
36 106 virtual ~FifoQueueBase() = default;
37
38 private:
39 // ----------------------------------------------------------------------
40 // Private member functions
41 // ----------------------------------------------------------------------
42
43 //! operator= deleted in the base class
44 //! Behavior depends on the implementation
45 //! We avoid virtual user-defined operators
46 FifoQueueBase<T>& operator=(const FifoQueueBase<T>&) = delete;
47
48 public:
49 // ----------------------------------------------------------------------
50 // Public member functions
51 // ----------------------------------------------------------------------
52
53 //! Get an item at an index.
54 //! Indices go from left to right in the queue.
55 //! Fails an assertion if the index is out of range.
56 //! \return The item
57 virtual const T& at(FwSizeType index //!< The index
58 ) const = 0;
59
60 //! Copy data from another queue
61 8 void copyDataFrom(const FifoQueueBase<T>& queue //!< The queue
62 ) {
63
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (&queue != this) {
64 8 this->clear();
65
2/2
✓ Branch 21 taken 4 times.
✓ Branch 22 taken 4 times.
8 const FwSizeType size = FW_MIN(queue.getSize(), this->getCapacity());
66
2/2
✓ Branch 3 taken 4098 times.
✓ Branch 4 taken 8 times.
8204 for (FwSizeType i = 0; i < size; i++) {
67
1/1
✓ Branch 7 taken 4098 times.
4098 const auto& e = queue.at(i);
68
1/1
✓ Branch 5 taken 4098 times.
4098 const auto status = this->enqueue(e);
69 4098 FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(status));
70 }
71 }
72 8 }
73
74 //! Enqueue an item (add to the right)
75 //! \return SUCCESS if item enqueued
76 virtual Success enqueue(const T& e //!< The item (output)
77 ) = 0;
78
79 //! Peek an item at an index
80 //! Indices go from left to right in the range [0, size)
81 //! \return SUCCESS if item exists
82 8444 Success peek(T& e, //!< The item (output)
83 FwSizeType index = 0 //!< The index (input)
84 ) const {
85 8444 auto status = Success::FAILURE;
86
2/3
✓ Branch 11 taken 8444 times.
✓ Branch 13 taken 8444 times.
✗ Branch 14 not taken.
8444 if (index < this->getSize()) {
87
1/1
✓ Branch 7 taken 8444 times.
8444 e = this->at(index);
88 8444 status = Success::SUCCESS;
89 }
90
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 8444 times.
✓ Branch 3 taken 8444 times.
16888 return status;
91 }
92
93 //! Dequeue an item (remove from the left)
94 //! \return SUCCESS if item dequeued
95 virtual Success dequeue(T& e //!< The item (output)
96 ) = 0;
97 };
98
99 } // namespace Fw
100
101 #endif
102