Alex Pirciu
/
BFMC
a
include/Queue/queue.inl@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | /** |
alexpirciu | 1:ceee5a608e7c | 2 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 3 | * @file Queue.inl |
alexpirciu | 1:ceee5a608e7c | 4 | * @author RBRO/PJ-IU |
alexpirciu | 1:ceee5a608e7c | 5 | * @version V1.0.0 |
alexpirciu | 1:ceee5a608e7c | 6 | * @date day-month-year |
alexpirciu | 1:ceee5a608e7c | 7 | * @brief This file contains the class definition for the queue |
alexpirciu | 1:ceee5a608e7c | 8 | * functionality. Inlin eimplementation. |
alexpirciu | 1:ceee5a608e7c | 9 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 10 | */ |
alexpirciu | 1:ceee5a608e7c | 11 | |
alexpirciu | 1:ceee5a608e7c | 12 | /** @brief Queue Class constructor |
alexpirciu | 1:ceee5a608e7c | 13 | * |
alexpirciu | 1:ceee5a608e7c | 14 | * Constructor method |
alexpirciu | 1:ceee5a608e7c | 15 | * |
alexpirciu | 1:ceee5a608e7c | 16 | * |
alexpirciu | 1:ceee5a608e7c | 17 | */ |
alexpirciu | 1:ceee5a608e7c | 18 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 19 | CQueue<T,N>::CQueue() |
alexpirciu | 1:ceee5a608e7c | 20 | : m_buffer() |
alexpirciu | 1:ceee5a608e7c | 21 | , m_start(0) |
alexpirciu | 1:ceee5a608e7c | 22 | , m_end(N-1) |
alexpirciu | 1:ceee5a608e7c | 23 | , m_size(0) |
alexpirciu | 1:ceee5a608e7c | 24 | { |
alexpirciu | 1:ceee5a608e7c | 25 | } |
alexpirciu | 1:ceee5a608e7c | 26 | |
alexpirciu | 1:ceee5a608e7c | 27 | /** @brief Queue Class destructor |
alexpirciu | 1:ceee5a608e7c | 28 | * |
alexpirciu | 1:ceee5a608e7c | 29 | * Destructor method |
alexpirciu | 1:ceee5a608e7c | 30 | * |
alexpirciu | 1:ceee5a608e7c | 31 | * |
alexpirciu | 1:ceee5a608e7c | 32 | */ |
alexpirciu | 1:ceee5a608e7c | 33 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 34 | CQueue<T,N>::~CQueue() |
alexpirciu | 1:ceee5a608e7c | 35 | { |
alexpirciu | 1:ceee5a608e7c | 36 | } |
alexpirciu | 1:ceee5a608e7c | 37 | |
alexpirciu | 1:ceee5a608e7c | 38 | /** @brief Is full method |
alexpirciu | 1:ceee5a608e7c | 39 | * |
alexpirciu | 1:ceee5a608e7c | 40 | * |
alexpirciu | 1:ceee5a608e7c | 41 | * @return True if Queue FULL |
alexpirciu | 1:ceee5a608e7c | 42 | */ |
alexpirciu | 1:ceee5a608e7c | 43 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 44 | bool CQueue<T,N>::isFull() |
alexpirciu | 1:ceee5a608e7c | 45 | { |
alexpirciu | 1:ceee5a608e7c | 46 | return (m_start + 1)%N == m_end; |
alexpirciu | 1:ceee5a608e7c | 47 | } |
alexpirciu | 1:ceee5a608e7c | 48 | |
alexpirciu | 1:ceee5a608e7c | 49 | /** @brief Is empty method |
alexpirciu | 1:ceee5a608e7c | 50 | * |
alexpirciu | 1:ceee5a608e7c | 51 | * |
alexpirciu | 1:ceee5a608e7c | 52 | * @return True if Queue EMPTY |
alexpirciu | 1:ceee5a608e7c | 53 | */ |
alexpirciu | 1:ceee5a608e7c | 54 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 55 | bool CQueue<T,N>::isEmpty() |
alexpirciu | 1:ceee5a608e7c | 56 | { |
alexpirciu | 1:ceee5a608e7c | 57 | return (m_end + 1)%N == m_start; |
alexpirciu | 1:ceee5a608e7c | 58 | } |
alexpirciu | 1:ceee5a608e7c | 59 | |
alexpirciu | 1:ceee5a608e7c | 60 | /** @brief Peek method |
alexpirciu | 1:ceee5a608e7c | 61 | * |
alexpirciu | 1:ceee5a608e7c | 62 | * |
alexpirciu | 1:ceee5a608e7c | 63 | * @return Value on top of queue |
alexpirciu | 1:ceee5a608e7c | 64 | */ |
alexpirciu | 1:ceee5a608e7c | 65 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 66 | T CQueue<T,N>::peek() |
alexpirciu | 1:ceee5a608e7c | 67 | { |
alexpirciu | 1:ceee5a608e7c | 68 | return m_buffer[(m_end+1) % N]; |
alexpirciu | 1:ceee5a608e7c | 69 | } |
alexpirciu | 1:ceee5a608e7c | 70 | |
alexpirciu | 1:ceee5a608e7c | 71 | /** @brief Pop method |
alexpirciu | 1:ceee5a608e7c | 72 | * |
alexpirciu | 1:ceee5a608e7c | 73 | * Method for removing the item on top of the queue and returning it |
alexpirciu | 1:ceee5a608e7c | 74 | * |
alexpirciu | 1:ceee5a608e7c | 75 | * |
alexpirciu | 1:ceee5a608e7c | 76 | * @return Element at top of the queue |
alexpirciu | 1:ceee5a608e7c | 77 | */ |
alexpirciu | 1:ceee5a608e7c | 78 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 79 | T CQueue<T,N>::pop() |
alexpirciu | 1:ceee5a608e7c | 80 | { |
alexpirciu | 1:ceee5a608e7c | 81 | if(!isEmpty()) |
alexpirciu | 1:ceee5a608e7c | 82 | { |
alexpirciu | 1:ceee5a608e7c | 83 | m_end = (m_end+1) % N; |
alexpirciu | 1:ceee5a608e7c | 84 | T l_char = m_buffer[m_end]; |
alexpirciu | 1:ceee5a608e7c | 85 | m_size--; |
alexpirciu | 1:ceee5a608e7c | 86 | return l_char; |
alexpirciu | 1:ceee5a608e7c | 87 | } |
alexpirciu | 1:ceee5a608e7c | 88 | else |
alexpirciu | 1:ceee5a608e7c | 89 | { |
alexpirciu | 1:ceee5a608e7c | 90 | return 0; |
alexpirciu | 1:ceee5a608e7c | 91 | } |
alexpirciu | 1:ceee5a608e7c | 92 | } |
alexpirciu | 1:ceee5a608e7c | 93 | |
alexpirciu | 1:ceee5a608e7c | 94 | /** @brief Push method |
alexpirciu | 1:ceee5a608e7c | 95 | * |
alexpirciu | 1:ceee5a608e7c | 96 | * Method for inserting an item on top of the queue |
alexpirciu | 1:ceee5a608e7c | 97 | * |
alexpirciu | 1:ceee5a608e7c | 98 | * @param f_char element to be added to the queue |
alexpirciu | 1:ceee5a608e7c | 99 | * @return None |
alexpirciu | 1:ceee5a608e7c | 100 | */ |
alexpirciu | 1:ceee5a608e7c | 101 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 102 | void CQueue<T,N>::push(T& f_char) |
alexpirciu | 1:ceee5a608e7c | 103 | { |
alexpirciu | 1:ceee5a608e7c | 104 | if (!isFull()) |
alexpirciu | 1:ceee5a608e7c | 105 | { |
alexpirciu | 1:ceee5a608e7c | 106 | m_buffer[m_start] = f_char; |
alexpirciu | 1:ceee5a608e7c | 107 | m_start = (m_start+1) % N; |
alexpirciu | 1:ceee5a608e7c | 108 | m_size++; |
alexpirciu | 1:ceee5a608e7c | 109 | } |
alexpirciu | 1:ceee5a608e7c | 110 | } |
alexpirciu | 1:ceee5a608e7c | 111 | |
alexpirciu | 1:ceee5a608e7c | 112 | /** @brief Push method |
alexpirciu | 1:ceee5a608e7c | 113 | * |
alexpirciu | 1:ceee5a608e7c | 114 | * Method for inserting a sequence of items on top of the queue |
alexpirciu | 1:ceee5a608e7c | 115 | * |
alexpirciu | 1:ceee5a608e7c | 116 | * @param f_char pointer to element to be added to the queue |
alexpirciu | 1:ceee5a608e7c | 117 | * @param f_len number of elements to be added |
alexpirciu | 1:ceee5a608e7c | 118 | * @return None |
alexpirciu | 1:ceee5a608e7c | 119 | */ |
alexpirciu | 1:ceee5a608e7c | 120 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 121 | inline void CQueue<T,N>::push(T *f_char, unsigned int f_len) |
alexpirciu | 1:ceee5a608e7c | 122 | { |
alexpirciu | 1:ceee5a608e7c | 123 | for ( unsigned int l_idx = 0; l_idx < f_len; ++l_idx) |
alexpirciu | 1:ceee5a608e7c | 124 | { |
alexpirciu | 1:ceee5a608e7c | 125 | push(f_char[l_idx]); |
alexpirciu | 1:ceee5a608e7c | 126 | } |
alexpirciu | 1:ceee5a608e7c | 127 | } |
alexpirciu | 1:ceee5a608e7c | 128 | |
alexpirciu | 1:ceee5a608e7c | 129 | /** @brief Get size method |
alexpirciu | 1:ceee5a608e7c | 130 | * |
alexpirciu | 1:ceee5a608e7c | 131 | * Returns the size of the queue |
alexpirciu | 1:ceee5a608e7c | 132 | * |
alexpirciu | 1:ceee5a608e7c | 133 | * |
alexpirciu | 1:ceee5a608e7c | 134 | * @return Queue size |
alexpirciu | 1:ceee5a608e7c | 135 | */ |
alexpirciu | 1:ceee5a608e7c | 136 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 137 | unsigned int CQueue<T,N>::getSize() |
alexpirciu | 1:ceee5a608e7c | 138 | { |
alexpirciu | 1:ceee5a608e7c | 139 | return m_size; |
alexpirciu | 1:ceee5a608e7c | 140 | } |
alexpirciu | 1:ceee5a608e7c | 141 | |
alexpirciu | 1:ceee5a608e7c | 142 | /** @brief Empty queue method |
alexpirciu | 1:ceee5a608e7c | 143 | * |
alexpirciu | 1:ceee5a608e7c | 144 | * |
alexpirciu | 1:ceee5a608e7c | 145 | * @return None |
alexpirciu | 1:ceee5a608e7c | 146 | */ |
alexpirciu | 1:ceee5a608e7c | 147 | template <class T, unsigned int N> |
alexpirciu | 1:ceee5a608e7c | 148 | inline void CQueue<T,N>::empty() |
alexpirciu | 1:ceee5a608e7c | 149 | { |
alexpirciu | 1:ceee5a608e7c | 150 | m_start = 0; |
alexpirciu | 1:ceee5a608e7c | 151 | m_end = N-1; |
alexpirciu | 1:ceee5a608e7c | 152 | m_size = 0; |
alexpirciu | 1:ceee5a608e7c | 153 | } |