F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FifoQueue.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file FifoQueue.hpp
3 // \author bocchino
4 // \brief A FIFO queue with internal storage
5 // ======================================================================
6 
7 #ifndef Fw_FifoQueue_HPP
8 #define Fw_FifoQueue_HPP
9 
12 
13 namespace Fw {
14 
15 template <typename T, FwSizeType C>
16 class FifoQueue final : public FifoQueueBase<T> {
17  // ----------------------------------------------------------------------
18  // Static assertions
19  // ----------------------------------------------------------------------
20 
21  static_assert(std::is_default_constructible<T>::value, "T must be default constructible");
22  static_assert(C > 0, "capacity must be greater than zero");
23 
24  // ----------------------------------------------------------------------
25  // Friend class for testing
26  // ----------------------------------------------------------------------
27 
28  template <typename TT, FwSizeType CC>
29  friend class FifoQueueTester;
30 
31  public:
32  // ----------------------------------------------------------------------
33  // Public constructors and destructors
34  // ----------------------------------------------------------------------
35 
37  FifoQueue() : FifoQueueBase<T>(), m_extQueue(m_items, C) {}
38 
40  FifoQueue(const FifoQueue<T, C>& queue) : FifoQueueBase<T>(), m_extQueue(m_items, C) { *this = queue; }
41 
43  ~FifoQueue() override = default;
44 
45  public:
46  // ----------------------------------------------------------------------
47  // Public member functions
48  // ----------------------------------------------------------------------
49 
52  this->m_extQueue.copyDataFrom(queue);
53  return *this;
54  }
55 
57  void clear() override { this->m_extQueue.clear(); }
58 
61  Success enqueue(const T& e
62  ) override {
63  return this->m_extQueue.enqueue(e);
64  }
65 
69  ) override {
70  return this->m_extQueue.dequeue(e);
71  }
72 
75  FwSizeType getSize() const override { return this->m_extQueue.getSize(); }
76 
79  FwSizeType getCapacity() const override { return this->m_extQueue.getCapacity(); }
80 
85  const T& at(FwSizeType index
86  ) const override {
87  return this->m_extQueue.at(index);
88  }
89 
90  private:
91  // ----------------------------------------------------------------------
92  // Private member variables
93  // ----------------------------------------------------------------------
94 
96  ExternalFifoQueue<T> m_extQueue = {};
97 
99  T m_items[C] = {};
100 };
101 
102 } // namespace Fw
103 
104 #endif
FwSizeType getCapacity() const override
Definition: FifoQueue.hpp:79
PlatformSizeType FwSizeType
FifoQueue< T, C > & operator=(const FifoQueue< T, C > &queue)
operator=
Definition: FifoQueue.hpp:51
~FifoQueue() override=default
Destructor.
FwSizeType getSize() const override
Definition: FifoQueue.hpp:75
FifoQueue()
Zero-argument constructor.
Definition: FifoQueue.hpp:37
Success dequeue(T &e) override
Definition: FifoQueue.hpp:68
const T & at(FwSizeType index) const override
Definition: FifoQueue.hpp:85
FifoQueue(const FifoQueue< T, C > &queue)
Copy constructor.
Definition: FifoQueue.hpp:40
Success enqueue(const T &e) override
Definition: FifoQueue.hpp:61
friend class FifoQueueTester
Definition: FifoQueue.hpp:21
Success/Failure.
void clear() override
Clear the queue.
Definition: FifoQueue.hpp:57