container/mn_queue.hpp
Go to the documentation of this file.
1 
18 #ifndef _MINILIB_51e64b00_707b_44f3_93dc_0b4c69dfd91c_H_
19 #define _MINILIB_51e64b00_707b_44f3_93dc_0b4c69dfd91c_H_
20 
21 #include "../mn_config.hpp"
22 #include "../queue/mn_queue.hpp"
23 #include "../mn_algorithm.hpp"
24 
25 namespace mn {
26  namespace container {
27  template <class T, class TQUEUE>
29  public:
31  using value_type = T;
32  using pointer = value_type*;
35 
36  using queue_type = TQUEUE;
38  using pointer_queue = TQUEUE*;
39 
40  explicit basic_queue_iterator(pointer_queue _pQueue, bool isEnd = false)
41  : m_pValue(NULL), m_pQueue(_pQueue), m_bIsEnd(isEnd) { }
42 
43  explicit basic_queue_iterator(pointer value, pointer_queue _pQueue, bool isEnd = false)
44  : m_pValue(value), m_pQueue(_pQueue), m_bIsEnd(isEnd) { }
45 
46  template<class U, class UQUEUE>
48  : m_pValue(rhs.m_pValue), m_pQueue(rhs._pQueue), m_bIsEnd(rhs.isEnd) { }
49 
50  pointer get() const { return m_pValue; }
51 
52  reference operator*() const { return *m_pValue; }
53  pointer operator->() const { return m_pValue; }
54 
56  if(!m_bIsEnd) { m_pQueue.dequeue(m_pValue); } return *this; }
57 
59  self_type copy(*this); ++(*this); return copy; }
60 
61  bool operator == (const self_type& rhs) const {
62  return rhs.m_pValue == m_pValue; }
63 
64  bool operator != (const self_type& rhs) const {
65  return !(rhs == *this); }
66  private:
69  bool m_bIsEnd;
70  };
71 
72 
80  template <class T, mn::size_t TMAXITEMS, mn::size_t TITEMSIZE = sizeof(T) >
81  class basic_queue {
82  public:
84  using value_type = T;
85  using pointer = T*;
86  using reference = T&;
87  using const_reference = const T&;
90  using const_iterator = const iterator;
92 
96  basic_queue() : m_queue(TMAXITEMS, TITEMSIZE) { m_queue.create(); }
97 
98  basic_queue(const self_type& other)
99  : m_queue(other.m_queue), m_pEnd(other.m_pEnd), m_pFront(other.m_pFront) { }
100 
105 
111  return iterator( intern_getfront(), m_queue);
112  }
118  return iterator(m_pEnd, &m_queue, true);
119  }
120 
126  return iterator( intern_getfront(), m_queue);
127  }
132  const_iterator end() const {
133  return iterator(m_pEnd, &m_queue, true);
134  }
136  assert(!empty()); return *intern_getfront(); }
137 
139  assert(!empty()); return *intern_getfront(); }
140 
142  assert(!empty()); return *m_pEnd; }
143 
145  assert(!empty()); return *m_pEnd; }
146 
151  void push(reference _Element) {
152  if( m_queue.enqueue(&_Element) == ERR_QUEUE_OK) {
153  m_pEnd = &_Element;
154  }
155  }
160  inline pointer pop() {
161  pointer tmp = NULL;
162  m_queue.dequeue(tmp);
163 
164  return tmp;
165  }
169  inline void clear() {
170  m_queue.clear();
171  }
177  inline bool empty() {
178  return m_queue.is_empty();
179  }
184  inline mn::size_t length() {
185  return TMAXITEMS;
186  }
191  inline mn::size_t size() {
192  return m_queue.get_num_items();
193  }
194 
199  inline mn::size_t left() {
200  return m_queue.get_left();
201  }
202 
203  void swap(const self_type& other) {
204  self_type _temp(this);
205  other = this;
206  this = _temp;
207  }
208 
209  self_type& operator = (const self_type& other) {
210  m_queue = other.m_queue;
211  m_pEnd = other.m_pEnd;
212  m_pFront = other.m_pFront;
213  return *this;
214  }
215 
216  private:
219  return m_pFront;
220  }
221  private:
225  };
226 
227  template <class T, mn::size_t TMAXITEMS, mn::size_t TITEMSIZE>
230  a.swap(b);
231  }
232 
238  template <class T, mn::size_t TMAXITEMS, mn::size_t TITEMSIZE = sizeof(T)>
240 
241  }
242 }
243 
244 
245 
246 #endif
Definition: container/mn_queue.hpp:28
value_type * pointer
Definition: container/mn_queue.hpp:32
TQUEUE queue_type
Definition: container/mn_queue.hpp:36
pointer operator->() const
Definition: container/mn_queue.hpp:53
T value_type
Definition: container/mn_queue.hpp:31
self_type & operator++()
Definition: container/mn_queue.hpp:55
value_type & reference
Definition: container/mn_queue.hpp:33
bool operator!=(const self_type &rhs) const
Definition: container/mn_queue.hpp:64
basic_queue_iterator(const basic_queue_iterator< U, UQUEUE > &rhs)
Definition: container/mn_queue.hpp:47
pointer get() const
Definition: container/mn_queue.hpp:50
pointer * m_pValue
Definition: container/mn_queue.hpp:67
basic_queue_iterator(pointer_queue _pQueue, bool isEnd=false)
Definition: container/mn_queue.hpp:40
pointer_queue m_pQueue
Definition: container/mn_queue.hpp:68
bool m_bIsEnd
Definition: container/mn_queue.hpp:69
TQUEUE * pointer_queue
Definition: container/mn_queue.hpp:38
ptrdiff_t difference_type
Definition: container/mn_queue.hpp:34
bool operator==(const self_type &rhs) const
Definition: container/mn_queue.hpp:61
self_type operator++(int)
Definition: container/mn_queue.hpp:58
reference operator*() const
Definition: container/mn_queue.hpp:52
basic_queue_iterator(pointer value, pointer_queue _pQueue, bool isEnd=false)
Definition: container/mn_queue.hpp:43
A basic wrapper for the MiniLib queue's as Template queue.
Definition: container/mn_queue.hpp:81
T value_type
Definition: container/mn_queue.hpp:84
const T & const_reference
Definition: container/mn_queue.hpp:87
T & reference
Definition: container/mn_queue.hpp:86
self_type & operator=(const self_type &other)
Definition: container/mn_queue.hpp:209
mn::size_t size_type
Definition: container/mn_queue.hpp:91
reference front()
Definition: container/mn_queue.hpp:138
basic_queue()
Construct a new basic queue object.
Definition: container/mn_queue.hpp:96
mn::size_t length()
How many items can queue.
Definition: container/mn_queue.hpp:184
reference back()
Definition: container/mn_queue.hpp:144
void push(reference _Element)
Push a element to the queue.
Definition: container/mn_queue.hpp:151
T * intern_getfront()
Definition: container/mn_queue.hpp:217
T * pointer
Definition: container/mn_queue.hpp:85
queue_type m_queue
Definition: container/mn_queue.hpp:222
const_iterator end() const
Get the end iterator.
Definition: container/mn_queue.hpp:132
iterator end()
Get the end iterator.
Definition: container/mn_queue.hpp:117
mn::size_t size()
Definition: container/mn_queue.hpp:191
basic_queue(const self_type &other)
Definition: container/mn_queue.hpp:98
pointer m_pEnd
Definition: container/mn_queue.hpp:223
basic_queue_iterator< T, queue_type > iterator
Definition: container/mn_queue.hpp:89
const_iterator begin() const
Get the begin iterator.
Definition: container/mn_queue.hpp:125
const_reference front() const
Definition: container/mn_queue.hpp:135
pointer pop()
Pop the oldest entry from the queue.
Definition: container/mn_queue.hpp:160
pointer m_pFront
Definition: container/mn_queue.hpp:224
bool empty()
Check, if queue is empty.
Definition: container/mn_queue.hpp:177
mn::size_t left()
Definition: container/mn_queue.hpp:199
const_reference back() const
Definition: container/mn_queue.hpp:141
~basic_queue()
Destroy the basic queue object.
Definition: container/mn_queue.hpp:104
iterator begin()
Get the begin iterator.
Definition: container/mn_queue.hpp:110
void clear()
Clear the queue.
Definition: container/mn_queue.hpp:169
void swap(const self_type &other)
Definition: container/mn_queue.hpp:203
Queue class wrapper for FreeRTOS queues.
Definition: queue/mn_queue.hpp:31
virtual int enqueue(void *item, unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT)
Definition: mn_queue.cpp:50
virtual unsigned int get_num_items()
Definition: mn_queue.cpp:117
virtual int peek(void *item, unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT)
Definition: mn_queue.cpp:86
virtual int destroy()
Definition: mn_queue.cpp:41
virtual bool is_empty()
Definition: mn_queue.cpp:100
virtual int clear()
Definition: mn_queue.cpp:111
virtual int create()
Definition: mn_queue.cpp:34
virtual unsigned int get_left()
Definition: mn_queue.cpp:122
virtual int dequeue(void *item, unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT)
Definition: mn_queue.cpp:68
#define MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT
Definition: mn_config.hpp:387
#define ERR_QUEUE_OK
Definition: mn_error.hpp:137
void swap(basic_any &x, basic_any &y) noexcept
Definition: mn_any.hpp:272
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
basic_queue queue_t
Definition: queue/mn_queue.hpp:142
Definition: mn_allocator_typetraits.hpp:25
long ptrdiff_t
Definition: mn_def.hpp:49
void copy(const T *src, const T *last, T *dest)
Definition: mn_algorithm.hpp:79
MN_THREAD_CONFIG_SIZE_TYPE size_t
Definition: mn_def.hpp:48
Definition: mn_iterator.hpp:34