Aleph-w  1.9
General library for algorithms and data structures
tpl_dynListQueue.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 
28 # ifndef TPL_DYNLISTQUEUE_H
29 # define TPL_DYNLISTQUEUE_H
30 
31 # include <iostream>
32 # include <ahDry.H>
33 # include <ahIterator.H>
34 # include <ah-args-ctor.H>
35 # include <htlist.H>
36 # include <tpl_dynDlist.H>
37 
38 using namespace std;
39 
40 
41 namespace Aleph {
42 
49  template <typename T>
51  : public LocateFunctions<DynListQueue<T>, T>,
52  public FunctionalMethods<DynListQueue<T>, T>,
53  public GenericKeys<DynListQueue<T>, T>,
54  public EqualToMethod<DynListQueue<T>>,
55  public StlAlephIterator<DynListQueue<T>>
56 {
57  DynList<T> q;
58  size_t num_items = 0;
59 
60  using Base = DynList<T>;
61 
62 public:
63 
65  void swap(DynListQueue & __q) noexcept
66  {
67  std::swap(num_items, __q.num_items);
68  q.swap(__q.q);
69  }
70 
72  DynListQueue() noexcept : num_items(0) { /* empty */ }
73 
75  DynListQueue(const DynListQueue & __q) : q(__q.q), num_items(__q.num_items)
76  {
77  // empty
78  }
79 
81  DynListQueue(DynListQueue && __q) noexcept
82  {
83  swap(__q);
84  }
85 
86  Special_Ctors(DynListQueue, T);
87 
89  DynListQueue & operator = (const DynListQueue & rhs)
90  {
91  if (this == &rhs)
92  return *this;
93 
94  q = rhs.q;
95  num_items = rhs.num_items;
96 
97  return *this;
98  }
99 
101  DynListQueue & operator = (DynListQueue && rhs) noexcept
102  {
103  std::swap(num_items, rhs.num_items);
104  q.swap(rhs.q);
105  return *this;
106  }
107 
109  size_t size() const noexcept { return num_items; }
110 
112  bool is_empty() const noexcept { return q.is_empty(); }
113 
114  using Set_Type = DynListQueue;
115 
116  using Item_Type = T;
117 
125  T & put(const T & data)
126  {
127  T & ret_val = q.append(data);
128  ++num_items;
129  return ret_val;
130  }
131 
139  T & put(T && data)
140  {
141  T & ret_val = q.append(std::forward<T>(data));
142  ++num_items;
143  return ret_val;
144  }
145 
146  T & append(const T & data) { return put(data); }
147 
148  T & append(T && data)
149  {
150  return put(std::forward<T>(data));
151  }
152 
153  T & insert(const T & data) { return put(data); }
154 
155  T & insert(T && data)
156  {
157  return put(std::forward<T>(data));
158  }
159 
165  T get()
166  {
167  T ret_val = q.remove_first();
168  --num_items;
169  return ret_val;
170  }
171 
173  T & front() const
174  {
175  return q.get_first();
176  }
177 
179  T & rear() const
180  {
181  return q.get_last();
182  }
183 
185  void empty() noexcept
186  {
187  q.empty();
188  num_items = 0;
189  assert(q.is_empty());
190  }
191 
199  template <class Operation>
200  bool traverse(Operation & operation) noexcept(noexcept(operation))
201  {
202  return q.traverse(operation);
203  }
204 
206  template <class Operation>
207  bool traverse(Operation & operation) const noexcept(noexcept(operation))
208  {
209  return q.traverse(operation);
210  }
211 
213  template <class Operation>
214  bool traverse(Operation && operation = Operation()) const
215  noexcept(noexcept(operation))
216  {
217  return q.traverse(std::forward<Operation>(operation));
218  }
219 
221  template <class Operation>
222  bool traverse(Operation && operation = Operation())
223  noexcept(noexcept(operation))
224  {
225  return q.traverse(std::forward<Operation>(operation));
226  }
227 
234  struct Iterator : public DynList<T>::Iterator
235  {
236  using Base = typename DynList<T>::Iterator;
237  using Base::Base;
238 
239  Iterator(const DynListQueue<T> & q) noexcept : Base(q.q) {}
240  };
241 };
242 
243 } // end namespace Aleph
244 # endif // TPL_DYNLISTQUEUE_H
245 
T & rear() const
Return a modifiable reference to the youngest item in the queue.
Definition: tpl_dynListQueue.H:179
Definition: htlist.H:450
Definition: htlist.H:1290
T remove_first()
Definition: htlist.H:1537
Definition: htlist.H:133
void empty() noexcept
empty the list
Definition: htlist.H:1598
Definition: tpl_dynListQueue.H:234
T & get_first() const
Definition: htlist.H:1584
bool is_empty() const noexcept
rioReturn true if this is empty
Definition: tpl_dynListQueue.H:112
bool traverse(Operation &operation) noexcept(noexcept(operation))
Definition: tpl_dynListQueue.H:200
bool is_empty() const noexcept
Definition: htlist.H:466
bool traverse(Operation &operation) noexcept(noexcept(operation))
Definition: htlist.H:67
bool traverse(Operation &operation) const noexcept(noexcept(operation))
Definition: tpl_dynListQueue.H:207
Definition: tpl_dynListQueue.H:50
DynListQueue(DynListQueue &&__q) noexcept
Construct in constant time a queue from __q
Definition: tpl_dynListQueue.H:81
T Item_Type
The type of set.
Definition: tpl_dynListQueue.H:116
Definition: ah-comb.H:35
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
Definition: tpl_dynListQueue.H:65
DynListQueue() noexcept
Contruct a empty queue.
Definition: tpl_dynListQueue.H:72
T & put(T &&data)
Definition: tpl_dynListQueue.H:139
bool traverse(Operation &&operation=Operation()) const noexcept(noexcept(operation))
Definition: tpl_dynListQueue.H:214
size_t size() const noexcept
Return the number of elements.
Definition: tpl_dynListQueue.H:109
T & front() const
Return a modifiable reference to the oldest item in the queue.
Definition: tpl_dynListQueue.H:173
void empty() noexcept
Empty the queue.
Definition: tpl_dynListQueue.H:185
DynList & swap(DynList &l) noexcept
Definition: htlist.H:1346
Definition: htlist.H:1622
Definition: ahDry.H:41
T & append(const T &item)
Definition: htlist.H:1471
bool traverse(Operation &&operation=Operation()) noexcept(noexcept(operation))
Definition: tpl_dynListQueue.H:222
DynListQueue(const DynListQueue &__q)
Construc a copy of __q
Definition: tpl_dynListQueue.H:75
Definition: htlist.H:1323
T & put(const T &data)
The type of element.
Definition: tpl_dynListQueue.H:125
T & get_last() const
Definition: htlist.H:1572

Leandro Rabindranath León