NDEVR
API Documentation
QueueBuffer.hpp
1#pragma once
2#include <NDEVR/Buffer.h>
3namespace NDEVR
4{
8 template<class t_type, class t_memory_manager = BufferAllocator<t_type, DetermineAlignment<sizeof(t_type)>(), ObjectInfo<t_type>::Primitive, uint04, false>>
9 class QueueBuffer : protected Buffer<t_type, t_memory_manager>
10 {
11 public:
12 using t_index_type = typename t_memory_manager::index_type;
13 constexpr QueueBuffer()
15 , m_start(0)
16 , m_end(0)
17 {}
18 constexpr QueueBuffer(const QueueBuffer& buffer)
20 , m_start(buffer.m_start)
21 , m_end(buffer.m_end)
22 {}
23 constexpr QueueBuffer(const Buffer<t_type, t_memory_manager>& buffer)
25 , m_start(0)
26 , m_end(buffer.size())
27 {}
28 constexpr QueueBuffer(QueueBuffer&& buffer) noexcept
29 : Buffer<t_type, t_memory_manager>(std::move(buffer))
30 , m_start(buffer.m_start)
31 , m_end(buffer.m_end)
32 {}
33
34 explicit QueueBuffer(uint04 size)
36 , m_start(0)
37 , m_end(0)
38 {}
39 void push(t_type&& object)
40 {
41 if(m_end == Buffer<t_type, t_memory_manager>::size())
42 {
44 }
45 else
46 {
47 std::swap(Buffer<t_type, t_memory_manager>::get(m_end), object);
48 }
49 m_end++;
50 }
51 void push(const t_type& object)
52 {
53 if (m_end == Buffer<t_type, t_memory_manager>::size())
54 {
56 }
57 else
58 {
59 Buffer<t_type, t_memory_manager>::get(m_end) = object;
60 }
61 m_end++;
62 }
63 void pushAll(const t_type* object, uint04 size)
64 {
65 if (size == 0)
66 return;
67 uint04 current_size = Buffer<t_type, t_memory_manager>::size();
68 if (size > current_size - m_end)
70 for (uint04 i = 0; i < size; i++)
71 Buffer<t_type, t_memory_manager>::get(i + m_end) = *(object + i);
72 m_end += size;
73 }
74 void pushAll(const Buffer<t_type>& object)
75 {
76 pushAll(object.begin(), object.size());
77 }
78 void clear()
79 {
80 m_start = m_end;
81 }
82 void pop()
83 {
84 m_start++;
85 checkMove();
86 }
87 void popAll(uint04 size)
88 {
89 m_start += size;
90 checkMove();
91 }
102
103 [[nodiscard]] decltype(auto) front()
104 {
105 return Buffer<t_type, t_memory_manager>::get(m_start);
106 }
107
118
119 [[nodiscard]] decltype(auto) front() const
120 {
121 return Buffer<t_type, t_memory_manager>::get(m_start);
122 }
123
124 bool empty() const
125 {
126 return m_end == m_start;
127 }
128 [[nodiscard]] constexpr static t_type Type() { return Buffer<t_type, t_memory_manager>::Type(); }
129
130 [[nodiscard]] constexpr t_memory_manager& memoryInterface()
131 {
133 }
134 [[nodiscard]] constexpr const t_memory_manager& memoryInterface() const
135 {
137 }
138 inline QueueBuffer& operator=(const QueueBuffer& buffer) noexcept
139 {
140 m_start = buffer.m_start;
141 m_end = buffer.m_end;
143 return *this;
144 }
145 inline QueueBuffer& operator=(QueueBuffer&& buffer) noexcept
146 {
147 m_start = buffer.m_start;
148 m_end = buffer.m_end;
150 return *this;
151 }
152 inline const t_type& operator[](t_index_type value) const noexcept
153 {
154 return Buffer<t_type, t_memory_manager>::get(value + m_start);
155 }
156 inline t_type& operator[](t_index_type value) noexcept
157 {
158 return Buffer<t_type, t_memory_manager>::get(value + m_start);
159 }
160 uint04 size() const
161 {
162 return m_end - m_start;
163 }
164 inline const t_type& last() const
165 {
167 }
168 inline t_type& last()
169 {
171 }
172 protected:
173 void checkMove()
174 {
175 //Check to see if we should resize back to 0
176 if(m_start * 2 >= Buffer<t_type, t_memory_manager>::size())
177 {
179 m_end -= m_start;
180 m_start = 0;
181 }
182 }
183 protected:
184 uint04 m_start;
185 uint04 m_end;
186 };
187}
void addSpace(t_index_type space_to_add)
Adds a space to the end of the buffer.
Definition Buffer.hpp:400
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:190
constexpr Buffer() noexcept
Creates an empty buffer.
Definition Buffer.hpp:65
decltype(auto) front()
decltype(auto) front() const
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Information about the object.
Definition ObjectInfo.h:55