33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
58 template<
class t_index_type,
bool is_primitive>
70 template<
class t_index_type>
74 template<
class t_buffer_type,
class t_type>
75 static void _allocate(t_buffer_type&, t_index_type, t_index_type)
95 template<
class t_buffer_type,
class t_type>
96 static void _deallocate(t_buffer_type&, t_index_type, t_index_type)
117 template<
class t_buffer_type,
class t_type>
118 static void _allocateElement(t_buffer_type& buff, t_index_type start, t_index_type size,
const t_type&
object)
120 buff.setAll(
object, start, size);
140 template<
class t_buffer_type,
class t_type>
141 static void _allocateElement(t_buffer_type& buff, t_index_type index,
const t_type&
object)
143 buff.get(index) = object;
145 template<
class t_buffer_type,
class t_type>
148 buff.get(index) = std::forward<t_type>(
object);
162 template<
class t_index_type>
182 template<
class t_buffer_type,
class t_type>
183 static void _allocate(t_buffer_type& buff, t_index_type start, t_index_type size)
185 for (t_index_type i = 0; i < size; i++)
187 new (&buff.get(i + start)) t_type();
207 template<
class t_buffer_type,
class t_type>
208 static void _deallocate(t_buffer_type& buff, t_index_type start, t_index_type size)
210 for (t_index_type i = 0; i < size; i++)
212 (&buff.get(i + start))->~t_type();
234 template<
class t_buffer_type,
class t_type>
235 static void _allocateElement(t_buffer_type& buff, t_index_type start, t_index_type size,
const t_type&
object)
237 for (t_index_type i = 0; i < size; i++)
239 new (&buff.get(i + start)) t_type(
object);
260 template<
class t_buffer_type,
class t_type>
261 static void _allocateElement(t_buffer_type& buff, t_index_type index,
const t_type&
object)
263 new (&buff.get(index)) t_type(
object);
265 template<
class t_buffer_type,
class t_type>
268 new (&buff.get(index)) t_type(std::move(
object));
281 template<
bool t_is_primitive,
class t_index_type = u
int04>
301 template<
class t_type,
class t_buffer_type>
302 static void allocate(t_buffer_type& buffer, t_index_type start, t_index_type size)
321 template<
class t_type,
class t_buffer_type>
322 static void deallocate(t_buffer_type& buffer, t_index_type start, t_index_type size)
343 template<
class t_type,
class t_buffer_type>
344 static void allocateElement(t_buffer_type& buffer, t_index_type start, t_index_type size,
const t_type&
object)
348 template<
class t_type,
class t_buffer_type>
349 static void allocateElement(t_buffer_type& buffer, t_index_type start, t_index_type size, t_type&
object)
368 template<
class t_type,
class t_buffer_type>
369 static void allocateElement(t_buffer_type& buffer, t_index_type index,
const t_type&
object)
373 template<
class t_type,
class t_buffer_type>
374 static void allocateElement(t_buffer_type& buffer, t_index_type index, t_type&&
object)
392 return t_is_primitive;
405 template<
class t_type,
class t_index_type,
bool t_null_term = false>
406 class BufferAllocator
409 [[nodiscard]]
static constexpr bool IsNullTerm() {
return t_null_term; }
414#ifndef NDEVR_LIB_SIZE_FUNCTION
421#ifndef NDEVR_LIB_SIZE_FUNCTION
425 std::swap(allocator.m_buffer,
m_buffer);
427#ifndef NDEVR_LIB_SIZE_FUNCTION
460 template<
bool t_managed>
481 template<
bool t_managed>
534 [[nodiscard]] t_index_type
count(
const t_type& value)
const
536 t_index_type
count = 0;
594 #pragma clang diagnostic push
595 #pragma clang diagnostic ignored "-Wdynamic-class-memaccess"
605 #pragma clang diagnostic pop
667 void swap(t_index_type index_a, t_index_type index_b)
723 t_type&
get(t_index_type index)
743 [[nodiscard]]
const t_type&
get(t_index_type index)
const
753 [[nodiscard]]
const t_type*
ptr()
const
792 [[nodiscard]]
const t_type*
begin()
const
812 [[nodiscard]] t_type*
begin(t_index_type index)
const
830#ifdef NDEVR_LIB_SIZE_FUNCTION
855 [[nodiscard]] t_type*
end()
874 [[nodiscard]]
const t_type*
end()
const
896 t_type*
end(t_index_type index)
925 m_buffer = (t_type*)malloc(
sizeof(t_type) * (t_null_term ? new_size + 1 : new_size));
927 m_buffer = (t_type*)realloc(
m_buffer,
sizeof(t_type) * (t_null_term ? new_size + 1 : new_size));
931 lib_assert(
false,
"Unable to allocate buffer: Perhaps out of system memory!");
934#ifndef NDEVR_LIB_SIZE_FUNCTION
954 void setAll(
const t_type&
object, t_index_type offset, t_index_type size)
962 for (t_index_type i = offset; i < offset + size; i++)
987 template<
bool is_primitive>
988 void setAll(
const t_type* src, t_index_type offset, t_index_type size)
990 if constexpr (is_primitive)
992 memmove(&
m_buffer[offset], src, size *
sizeof(t_type));
996 for (t_index_type i = 0; i < size; i++)
1069 template<
bool is_primitive,
class t_other_index_type,
bool t_other_null_term>
1072 if constexpr (is_primitive)
1074 memmove(&
m_buffer[offset], &(allocator.m_buffer[other_offset]), size *
sizeof(t_type));
1078 for (t_index_type i = 0; i < size; i++)
1080 m_buffer[i + offset] = allocator.get(i + other_offset);
1101 template<
class t_other_allocator>
1102 void setAllFromSource(
const t_other_allocator& allocator, t_index_type offset, t_index_type other_offset, t_index_type size)
1104 for (t_index_type i = 0; i < size; i++)
1106 m_buffer[i + offset] = allocator.get(i + other_offset);
1119 template<
bool t_managed>
1122 if constexpr (t_managed)
1171 template<
class t_range_buffer>
1175 for (
uint04 i = 0; i < ranges.size(); i++)
1177 auto range = ranges[i];
1178 t_index_type start = range.first;
1179 t_index_type
end = range.second;
1182 offset += (
end - start);
1201 template<
bool t_is_null>
1204 if constexpr (t_is_null)
1235 template<
bool t_is_null>
1238 if constexpr(t_is_null)
1240 static constexpr t_type null_object = {};
1241 return const_cast<t_type*
>(&null_object);
1284 std::swap(value.m_buffer,
m_buffer);
1286#ifndef NDEVR_LIB_SIZE_FUNCTION
1295#ifndef NDEVR_LIB_SIZE_FUNCTION
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
static void _allocateElement(t_buffer_type &buff, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:235
static void _deallocate(t_buffer_type &buff, t_index_type start, t_index_type size)
Definition MemoryManager.h:208
static void _allocate(t_buffer_type &buff, t_index_type start, t_index_type size)
Definition MemoryManager.h:183
static void _allocateElement(t_buffer_type &buff, t_index_type index, t_type &&object)
Definition MemoryManager.h:266
static void _allocateElement(t_buffer_type &buff, t_index_type index, const t_type &object)
Definition MemoryManager.h:261
static void _allocate(t_buffer_type &, t_index_type, t_index_type)
Definition MemoryManager.h:75
static void _allocateElement(t_buffer_type &buff, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:118
static void _allocateElement(t_buffer_type &buff, t_index_type index, t_type &&object)
Definition MemoryManager.h:146
static void _deallocate(t_buffer_type &, t_index_type, t_index_type)
Definition MemoryManager.h:96
static void _allocateElement(t_buffer_type &buff, t_index_type index, const t_type &object)
Definition MemoryManager.h:141
The default object allocator for Buffer.
Definition MemoryManager.h:59
Definition Pointer.hpp:297
void createSpace(t_index_type location, t_index_type size)
Definition MemoryManager.h:482
const t_type & get(t_index_type index) const
Definition MemoryManager.h:743
sint04 compare(const BufferAllocator &allocator, t_index_type start, t_index_type end) const
Definition MemoryManager.h:648
void setAllFromSource(const t_other_allocator &allocator, t_index_type offset, t_index_type other_offset, t_index_type size)
Definition MemoryManager.h:1102
void createSpace(t_index_type size)
Definition MemoryManager.h:461
void setAll(const BufferAllocator< t_type, t_other_index_type, t_other_null_term > &allocator, t_index_type offset, t_index_type other_offset, t_index_type size)
Definition MemoryManager.h:1070
t_index_type m_filled_size
Definition MemoryManager.h:1294
const t_type * begin() const
Definition MemoryManager.h:792
void addIndex(t_index_type location)
Definition MemoryManager.h:573
sint04 compare(const BufferAllocator &allocator) const
Definition MemoryManager.h:624
static constexpr bool IsNullTerm()
Definition MemoryManager.h:409
t_type * end()
Definition MemoryManager.h:855
t_index_type capacity() const
Definition MemoryManager.h:828
void allocationSizeCheck()
Definition MemoryManager.h:1120
constexpr BufferAllocator(BufferAllocator &&allocator) noexcept
Definition MemoryManager.h:418
void removeAllIndex(t_index_type start, t_index_type end)
Definition MemoryManager.h:1158
void nullTerminatorCheck()
Definition MemoryManager.h:1202
void removeAllIndices(const t_range_buffer &ranges)
Definition MemoryManager.h:1172
constexpr t_index_type filledSize() const
Definition MemoryManager.h:1261
t_type * begin(t_index_type index) const
Definition MemoryManager.h:812
t_type * end(t_index_type index)
Definition MemoryManager.h:896
void swap(t_index_type index_a, t_index_type index_b)
Definition MemoryManager.h:667
const t_type * end() const
Definition MemoryManager.h:874
t_type & get(t_index_type index)
Definition MemoryManager.h:723
BufferAllocator & operator=(BufferAllocator &&value) noexcept
Definition MemoryManager.h:1282
t_type * emptyPtr() const
Definition MemoryManager.h:1236
void removeIndex(t_index_type location)
Definition MemoryManager.h:597
void setAll(const t_type *src, t_index_type offset, t_index_type size)
Definition MemoryManager.h:988
t_index_type m_allocated_size
Definition MemoryManager.h:1296
void addLast()
Definition MemoryManager.h:498
const t_type * ptr() const
Definition MemoryManager.h:753
t_index_type memSize() const
Definition MemoryManager.h:758
constexpr BufferAllocator()
Definition MemoryManager.h:411
t_type * begin()
Definition MemoryManager.h:775
t_type * ptr()
Definition MemoryManager.h:748
void clear()
Definition MemoryManager.h:682
~BufferAllocator()
Definition MemoryManager.h:442
void resizeSpace(t_index_type new_size)
Definition MemoryManager.h:914
void setAll(const t_type &object, t_index_type offset, t_index_type size)
Definition MemoryManager.h:954
t_type * m_buffer
Definition MemoryManager.h:1293
void setSize(t_index_type size)
Definition MemoryManager.h:701
t_index_type count(const t_type &value) const
Definition MemoryManager.h:534
void removeLast()
Definition MemoryManager.h:513
void addIndex()
Definition MemoryManager.h:555
Definition MemoryManager.h:283
static constexpr bool isPrimitive()
Definition MemoryManager.h:390
static void deallocate(t_buffer_type &buffer, t_index_type start, t_index_type size)
Definition MemoryManager.h:322
static void allocate(t_buffer_type &buffer, t_index_type start, t_index_type size)
Definition MemoryManager.h:302
static void allocateElement(t_buffer_type &buffer, t_index_type index, t_type &&object)
Definition MemoryManager.h:374
static void allocateElement(t_buffer_type &buffer, t_index_type index, const t_type &object)
Definition MemoryManager.h:369
static void allocateElement(t_buffer_type &buffer, t_index_type start, t_index_type size, t_type &object)
Definition MemoryManager.h:349
static void allocateElement(t_buffer_type &buffer, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:344
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67
Definition BaseValues.hpp:272