Ocular Engine
PriorityMultiQueue.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_UTILS_PRIORITY_MULTI_QUEUE__H__
19 #define __H__OCULAR_UTILS_PRIORITY_MULTI_QUEUE__H__
20 
21 #include "CircularQueue.hpp"
22 #include "Priority.hpp"
23 
24 //------------------------------------------------------------------------------------------
25 
30 namespace Ocular
31 {
36  namespace Utils
37  {
49  template<typename T, std::size_t MAX_ELEMENTS>
51  {
52  public:
53 
58  {
59 
60  }
61 
66  {
67 
68  }
69 
75  bool enqueue(T const element, Core::Priority priority)
76  {
77  bool result = false;
78 
79  switch(priority)
80  {
81  case Core::Priority::Critical:
82  result = m_CriticalPriority.enqueue(element);
83  break;
84 
85  case Core::Priority::High:
86  result = m_HighPriority.enqueue(element);
87  break;
88 
89  case Core::Priority::Medium:
90  result = m_MediumPriority.enqueue(element);
91  break;
92 
93  case Core::Priority::Low:
94  result = m_LowPriority.enqueue(element);
95  break;
96 
97  default:
98  break;
99  }
100 
101  return result;
102  }
103 
118  bool dequeue()
119  {
120  // Short-circuit evaluation ensures that we will
121  // return once a successful dequeue has occurred.
122 
123  return m_CriticalPriority.dequeue() ||
124  m_HighPriority.dequeue() ||
125  m_MediumPriority.dequeue() ||
126  m_LowPriority.dequeue();
127  }
128 
143  bool dequeue(T& retElement)
144  {
145  // Short-circuit evaluation ensures that we will
146  // return once a successful dequeue has occurred.
147 
148  return m_CriticalPriority.dequeue(retElement) ||
149  m_HighPriority.dequeue(retElement) ||
150  m_MediumPriority.dequeue(retElement) ||
151  m_LowPriority.dequeue(retElement);
152  }
153 
160  bool dequeue(Core::Priority priority, T& retElement)
161  {
162  bool result = false;
163 
164  switch(priority)
165  {
166  case Core::Priority::Critical:
167  result = m_CriticalPriority.dequeue(element);
168  break;
169 
170  case Core::Priority::High:
171  result = m_HighPriority.dequeue(element);
172  break;
173 
174  case Core::Priority::Medium:
175  result = m_MediumPriority.dequeue(element);
176  break;
177 
178  case Core::Priority::Low:
179  result = m_LowPriority.dequeue(element);
180  break;
181 
182  default:
183  break;
184  }
185 
186  return result;
187  }
188 
192  unsigned getNumElements() const
193  {
194  return getNumElementsCritical() +
198  }
199 
203  unsigned getNumElementsCritical() const
204  {
205  return m_CriticalPriority.getNumElements();
206  }
207 
211  unsigned getNumElementsHigh() const
212  {
213  return m_HighPriority.getNumElements();
214  }
215 
219  unsigned getNumElementsMedium() const
220  {
221  return m_MediumPriority.getNumElements();
222  }
223 
227  unsigned getNumElementsLow() const
228  {
229  return m_LowPriority.getNumElements();
230  }
231 
235  bool empty()
236  {
237  return (getNumElements() == 0);
238  }
239 
240  void clear()
241  {
242  while(dequeue());
243  }
244 
245  protected:
246 
247  private:
248 
249  CircularQueue<T, MAX_ELEMENTS> m_CriticalPriority;
250  CircularQueue<T, MAX_ELEMENTS> m_HighPriority;
251  CircularQueue<T, MAX_ELEMENTS> m_MediumPriority;
252  CircularQueue<T, MAX_ELEMENTS> m_LowPriority;
253  };
254  }
258 }
263 //------------------------------------------------------------------------------------------
264 
265 #endif
bool enqueue(T const element, Core::Priority priority)
Definition: PriorityMultiQueue.hpp:75
unsigned getNumElementsLow() const
Definition: PriorityMultiQueue.hpp:227
bool dequeue(Core::Priority priority, T &retElement)
Definition: PriorityMultiQueue.hpp:160
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
unsigned getNumElementsCritical() const
Definition: PriorityMultiQueue.hpp:203
unsigned getNumElementsHigh() const
Definition: PriorityMultiQueue.hpp:211
unsigned getNumElements() const
Definition: PriorityMultiQueue.hpp:192
bool dequeue(T &retElement)
Definition: PriorityMultiQueue.hpp:143
Definition: PriorityMultiQueue.hpp:50
bool dequeue()
Definition: PriorityMultiQueue.hpp:118
unsigned getNumElementsMedium() const
Definition: PriorityMultiQueue.hpp:219
bool empty()
Definition: PriorityMultiQueue.hpp:235