28 template <
typename T,
typename Allocator = std::allocator<T>>
55 const T &
operator[](
const size_t offset)
const;
65 template <
typename... Args>
72 const T &
front(
void)
const;
82 template <
typename... Args>
89 const T &
back(
void)
const;
95 bool empty(
void)
const;
98 bool full(
void)
const;
101 size_t size(
void)
const;
117 Allocator _allocator;
127 template <
typename T>
128 T nextPow2(
const T &in)
131 while (out < in) out <<= 1;
137 template <
typename T,
typename A>
139 _allocator(allocator),
140 _mask(Detail::nextPow2(capacity)-1),
144 _container(_allocator.allocate(_mask+1))
146 assert(capacity > 0);
149 template <
typename T,
typename A>
152 _capacity(other._capacity),
155 _container(_allocator.allocate(_mask+1))
157 for (
size_t i = 0; i < other.
size(); i++)
159 this->push_back(other[i]);
163 template <
typename T,
typename A>
165 _allocator(std::move(other._allocator)),
166 _mask(std::move(other._mask)),
167 _capacity(std::move(other._capacity)),
168 _frontIndex(std::move(other._frontIndex)),
169 _numElements(std::move(other._numElements)),
170 _container(std::move(other._container))
172 other._numElements = 0;
174 other._container =
nullptr;
177 template <
typename T,
typename A>
181 this->set_capacity(other.
capacity());
182 for (
size_t i = 0; i < other.
size(); i++)
184 this->push_back(other[i]);
189 template <
typename T,
typename A>
193 _allocator.deallocate(_container, _mask+1);
194 _allocator = std::move(other._allocator);
195 _mask = std::move(other._mask);
196 _capacity = std::move(other._capacity);
197 _frontIndex = std::move(other._frontIndex);
198 _numElements = std::move(other._numElements);
199 _container = std::move(other._container);
200 other._numElements = 0;
202 other._container =
nullptr;
206 template <
typename T,
typename A>
209 if (_container ==
nullptr)
return;
211 _allocator.deallocate(_container, _mask+1);
214 template <
typename T,
typename A>
217 return _container[(_frontIndex + offset) & _mask];
220 template <
typename T,
typename A>
223 return _container[(_frontIndex + offset) & _mask];
226 template <
typename T,
typename A>
227 template <
typename U>
230 this->emplace_front(std::forward<U>(elem));
233 template <
typename T,
typename A>
234 template <
typename... Args>
237 assert(not this->full());
240 return *(
new(&front()) T(std::forward<Args>(args)...));
243 template <
typename T,
typename A>
246 assert(not this->empty());
252 template <
typename T,
typename A>
255 assert(not this->empty());
259 template <
typename T,
typename A>
262 assert(not this->empty());
266 template <
typename T,
typename A>
267 template <
typename U>
270 this->emplace_back(std::forward<U>(elem));
273 template <
typename T,
typename A>
274 template <
typename... Args>
277 assert(not this->full());
279 return *(
new(&back()) T(std::forward<Args>(args)...));
282 template <
typename T,
typename A>
285 assert(not this->empty());
290 template <
typename T,
typename A>
293 assert(not this->empty());
294 return (*
this)[size_t(_numElements-1)];
297 template <
typename T,
typename A>
300 assert(not this->empty());
301 return (*
this)[size_t(_numElements-1)];
304 template <
typename T,
typename A>
307 return _numElements == 0;
310 template <
typename T,
typename A>
313 return _numElements == _capacity;
316 template <
typename T,
typename A>
322 template <
typename T,
typename A>
328 template <
typename T,
typename A>
331 if (_numElements > capacity)
return;
333 while (not this->empty())
335 newRing.
push_back(std::move(this->front()));
338 *
this = std::move(newRing);
341 template <
typename T,
typename A>
344 while (not this->empty())
void pop_back(void)
Pop and element from the back of the queue.
Definition: RingDeque.hpp:283
bool full(void) const
Is the deque full? – num elements == capacity.
Definition: RingDeque.hpp:311
RingDeque & operator=(const RingDeque< T, Allocator > &other)
Copy assignment.
Definition: RingDeque.hpp:178
void push_front(U &&elem)
Push an element onto the front of the queue.
Definition: RingDeque.hpp:228
T value_type
The element type.
Definition: RingDeque.hpp:112
T & emplace_front(Args &&... args)
Emplace an element onto the front of the queue.
Definition: RingDeque.hpp:235
void pop_front(void)
Pop and element from the front of the queue.
Definition: RingDeque.hpp:244
RingDeque(const size_t capacity=1, const Allocator &allocator=Allocator())
Definition: RingDeque.hpp:138
void set_capacity(const size_t capacity)
Set the deque capacity if too small.
Definition: RingDeque.hpp:329
const T & front(void) const
Get a const reference to the front element.
Definition: RingDeque.hpp:253
Definition: ArchiveEntry.hpp:20
Allocator allocator_type
The allocator type.
Definition: RingDeque.hpp:114
bool empty(void) const
Is the deque empty? – no elements.
Definition: RingDeque.hpp:305
const T & back(void) const
Get a const reference to the back element.
Definition: RingDeque.hpp:291
Definition: RingDeque.hpp:29
size_t capacity(void) const
How many elements can be stored?
Definition: RingDeque.hpp:323
size_t size(void) const
How many elements are in the deque.
Definition: RingDeque.hpp:317
void push_back(U &&elem)
Push an element onto the back of the queue.
Definition: RingDeque.hpp:268
~RingDeque(void)
Destruct the ring queue and any elements held.
Definition: RingDeque.hpp:207
T & emplace_back(Args &&... args)
Emplace an element onto the back of the queue.
Definition: RingDeque.hpp:275
void clear(void)
Empty the contents of this queue.
Definition: RingDeque.hpp:342
const T & operator[](const size_t offset) const
Get a const ref at, where front == 0, back == size() - 1.
Definition: RingDeque.hpp:215