mn_shared_list.hpp
Go to the documentation of this file.
1 
21 #ifndef __MINILIB_BASIC_SHARED_LIST_H__
22 #define __MINILIB_BASIC_SHARED_LIST_H__
23 
24 #include "../mn_config.hpp"
25 
26 #include "mn_list.hpp"
27 
28 #include "../mn_autolock.hpp"
29 #include "../pointer/mn_shared_ptr.hpp"
30 
31 #include <list>
32 namespace mn {
33  namespace container {
42  template <typename T, typename TLockType = mn::mutex_t>
43  class basic_shared_list : public list< pointer::shared_atomic_ptr<T> > {
48  public:
50 
51  using lock_type = TLockType;
53 
55  using reference = typename base_type::value_type&;
56  using const_reference = const typename base_type::value_type&;
57  using pointer = typename base_type::value_type*;
58  using const_pointer = const typename base_type::value_type*;
60  using size_type = typename base_type::size_type;
61  using node_type = typename base_type::node_type;
62  using deleter = typename base_type::deleter;
63 
64  using iterator = typename base_type::iterator;
66 
71  : base_type(allocator), m_lockObject() { }
72 
77  basic_shared_list(lock_type& lLock, const allocator_type& allocator = allocator_type()) noexcept
78  : base_type(allocator), m_lockObject(lLock) { }
79 
89  template<class InputIterator>
90  basic_shared_list(InputIterator first, InputIterator last,
91  const allocator_type& allocator = allocator_type()) noexcept
92  : base_type(first, last, allocator_type), m_lockObject() { }
96  basic_shared_list(const basic_shared_list& rhs) noexcept
97  : base_type(rhs), m_lockObject(rhs.m_lockObject) { }
98 
105  iterator begin_save(unsigned long xTicksToWait = portMAX_DELAY) {
106  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
107  return base_type::begin();
108  }
109 
117  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
118  return base_type::begin();
119  }
120 
127  iterator end_save(unsigned long xTicksToWait = portMAX_DELAY) {
128  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
129  return base_type::end();
130  }
131 
138  const_iterator end_save(unsigned long xTicksToWait = portMAX_DELAY) const {
139  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
140  return base_type::end();
141  }
142 
149  const_reference front_save(unsigned long xTicksToWait = portMAX_DELAY) const {
150  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
151  return base_type::front();
152  }
153 
161  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
162  return base_type::front();
163  }
164 
171  const_reference back_save(unsigned long xTicksToWait = portMAX_DELAY) const {
172  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
173  return base_type::back();
174  }
175 
182  reference back_save(unsigned long xTicksToWait = portMAX_DELAY) {
183  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
184  return base_type::back();
185  }
186 
192  void push_front_save(pointer pValue, unsigned long xTicksToWait = portMAX_DELAY) {
193  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
195  }
196 
202  void push_back_save(pointer pValue, unsigned long xTicksToWait = portMAX_DELAY) {
203  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
204 
206  }
207 
213  void push_front_save(pointer_type pValue, unsigned long xTicksToWait = portMAX_DELAY) {
214  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
215 
217  }
218 
224  void push_back_save(pointer_type pValue, unsigned long xTicksToWait = portMAX_DELAY) {
225  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
226 
228  }
229 
234  inline void pop_back_save(unsigned long xTicksToWait = portMAX_DELAY) {
235  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
237  }
238 
243  inline void pop_front_save(unsigned long xTicksToWait = portMAX_DELAY) {
244  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
246  }
247 
255  iterator insert(iterator pos, pointer value, unsigned long xTicksToWait = portMAX_DELAY) {
256  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
257  return base_type::insert(pos, pointer_type(value) );
258  }
259 
267  iterator insert_save(iterator pos, pointer_type value, unsigned long xTicksToWait = portMAX_DELAY) {
268  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
269  return base_type::insert(pos, (value) );
270  }
271 
278  iterator erase_save(iterator it, unsigned long xTicksToWait = portMAX_DELAY) {
279  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
280  return base_type::erase(it);
281  }
282 
283 
291  iterator erase_save(iterator first, iterator last, unsigned long xTicksToWait = portMAX_DELAY) {
292  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
293  return base_type::erase(first, last);
294  }
295 
301  base_type& list(unsigned long xTicksToWait = portMAX_DELAY) noexcept {
302  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
303  return *(static_cast<base_type*>(this));
304  }
305 
311  const base_type& list(unsigned long xTicksToWait = portMAX_DELAY) const noexcept {
312  basic_autolock<TLockType> _lock(m_lockObject, xTicksToWait);
313  return *(static_cast<base_type*>(this));
314  }
315 
321  int lock(unsigned long xTicksToWait = portMAX_DELAY) {
322  return m_lockObject.lock(xTicksToWait);
323  }
328  int unlock() {
329  return m_lockObject.unlock();
330  }
331  protected:
336  };
337 
338  template <typename T, typename TLockType = mn::mutex_t>
340  }
341 }
342 
343 
344 #endif // __MINILIB_BASIC_SHARED_LIST_H__
Definition: mn_lock.hpp:122
Definition: mn_list.hpp:77
const T & back() const
Definition: mn_list.hpp:130
basic_node< T > node_type
Definition: mn_list.hpp:83
void push_back(const T &value)
Definition: mn_list.hpp:144
iterator erase(iterator it)
Definition: mn_list.hpp:161
iterator insert(iterator pos, const T &value)
Definition: mn_list.hpp:155
void pop_front()
Definition: mn_list.hpp:137
TAllocator allocator_type
Definition: mn_list.hpp:81
TDeleter deleter
Definition: mn_list.hpp:84
list_node_iterator< const node_type *, const value_type *, const value_type & > const_iterator
Definition: mn_list.hpp:87
list_node_iterator< node_type *, const value_type *, const value_type & > iterator
Definition: mn_list.hpp:86
mn::size_t size_type
Definition: mn_list.hpp:82
iterator end()
Definition: mn_list.hpp:124
void push_front(const T &value)
Definition: mn_list.hpp:133
void pop_back()
Definition: mn_list.hpp:148
const T & front() const
Definition: mn_list.hpp:127
iterator begin()
Definition: mn_list.hpp:121
T value_type
Definition: mn_list.hpp:80
Definition: mn_node.hpp:113
A simple list of shared_ptr items.
Definition: mn_shared_list.hpp:43
const_iterator begin_save() const
Get the read/write iterator that points to the first element from the list.
Definition: mn_shared_list.hpp:116
reference front_save()
Get a read/write reference to the data at the first element .
Definition: mn_shared_list.hpp:160
pointer::shared_atomic_ptr< T > pointer_type
Definition: mn_shared_list.hpp:52
TLockType lock_type
Definition: mn_shared_list.hpp:51
typename base_type::allocator_type allocator_type
Definition: mn_shared_list.hpp:59
base_type & list(unsigned long xTicksToWait=portMAX_DELAY) noexcept
Get the used list of this object.
Definition: mn_shared_list.hpp:301
iterator erase_save(iterator first, iterator last, unsigned long xTicksToWait=portMAX_DELAY)
Remove a range of elements.
Definition: mn_shared_list.hpp:291
const_iterator end_save(unsigned long xTicksToWait=portMAX_DELAY) const
Get the read/write iterator that points to the last element from the list.
Definition: mn_shared_list.hpp:138
reference back_save(unsigned long xTicksToWait=portMAX_DELAY)
Get a read/write reference to the data at the last element.
Definition: mn_shared_list.hpp:182
basic_shared_list(InputIterator first, InputIterator last, const allocator_type &allocator=allocator_type()) noexcept
Builds a basic_shared_list from a range.
Definition: mn_shared_list.hpp:90
iterator insert_save(iterator pos, pointer_type value, unsigned long xTicksToWait=portMAX_DELAY)
Inserts given value into the list before specified iterator.
Definition: mn_shared_list.hpp:267
iterator begin_save(unsigned long xTicksToWait=portMAX_DELAY)
Get the read/write iterator that points to the first element from the list.
Definition: mn_shared_list.hpp:105
basic_shared_list(lock_type &lLock, const allocator_type &allocator=allocator_type()) noexcept
Creates a basic_shared_list with no elements.
Definition: mn_shared_list.hpp:77
const_reference back_save(unsigned long xTicksToWait=portMAX_DELAY) const
Get a read/write reference to the data at the last element.
Definition: mn_shared_list.hpp:171
int unlock()
Unlock this object.
Definition: mn_shared_list.hpp:328
void push_back_save(pointer pValue, unsigned long xTicksToWait=portMAX_DELAY)
Add data to the back of the list.
Definition: mn_shared_list.hpp:202
void pop_front_save(unsigned long xTicksToWait=portMAX_DELAY)
Removes first element.
Definition: mn_shared_list.hpp:243
const typename base_type::value_type & const_reference
Definition: mn_shared_list.hpp:56
lock_type m_lockObject
The lock object.
Definition: mn_shared_list.hpp:335
list< pointer::shared_atomic_ptr< T > > base_type
The base type of this object.
Definition: mn_shared_list.hpp:47
void pop_back_save(unsigned long xTicksToWait=portMAX_DELAY)
Removes last element.
Definition: mn_shared_list.hpp:234
iterator erase_save(iterator it, unsigned long xTicksToWait=portMAX_DELAY)
remove given value into the list before specified iterator.
Definition: mn_shared_list.hpp:278
void push_front_save(pointer_type pValue, unsigned long xTicksToWait=portMAX_DELAY)
Add data to the front of the list.
Definition: mn_shared_list.hpp:213
const base_type & list(unsigned long xTicksToWait=portMAX_DELAY) const noexcept
Get the used list of this object.
Definition: mn_shared_list.hpp:311
void push_back_save(pointer_type pValue, unsigned long xTicksToWait=portMAX_DELAY)
Add data to the back of the list.
Definition: mn_shared_list.hpp:224
typename base_type::value_type & reference
Definition: mn_shared_list.hpp:55
int lock(unsigned long xTicksToWait=portMAX_DELAY)
Lock this object.
Definition: mn_shared_list.hpp:321
const_reference front_save(unsigned long xTicksToWait=portMAX_DELAY) const
Get a read/write reference to the data at the first element.
Definition: mn_shared_list.hpp:149
typename base_type::value_type * pointer
Definition: mn_shared_list.hpp:57
basic_shared_list(const allocator_type &allocator=allocator_type())
Creates a basic_shared_list with no elements.
Definition: mn_shared_list.hpp:70
iterator insert(iterator pos, pointer value, unsigned long xTicksToWait=portMAX_DELAY)
Inserts given value into the list before specified iterator.
Definition: mn_shared_list.hpp:255
basic_shared_list(const basic_shared_list &rhs) noexcept
Construct a new basic shared list object.
Definition: mn_shared_list.hpp:96
iterator end_save(unsigned long xTicksToWait=portMAX_DELAY)
Get the read/write iterator that points to the last element from the list.
Definition: mn_shared_list.hpp:127
const typename base_type::value_type * const_pointer
Definition: mn_shared_list.hpp:58
void push_front_save(pointer pValue, unsigned long xTicksToWait=portMAX_DELAY)
Add data to the front of the list.
Definition: mn_shared_list.hpp:192
Definition: mn_list.hpp:29
Definition: mn_shared_ptr.hpp:29
#define portMAX_DELAY
Definition: mn_autolock.hpp:34
Definition: mn_allocator_typetraits.hpp:25