33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
52 template<
class t_index_type,
bool is_primitive>
62 template<
class t_index_type>
66 template<
class t_buffer_type,
class t_type>
67 static void Allocate(t_buffer_type&, t_index_type, t_index_type)
85 template<
class t_buffer_type,
class t_type>
86 static void Deallocate(t_buffer_type&, t_index_type, t_index_type)
105 template<
class t_buffer_type,
class t_type>
106 static void AllocateElement(t_buffer_type& buff, t_index_type start, t_index_type size,
const t_type&
object)
108 buff.setAll(
object, start, size);
126 template<
class t_buffer_type,
class t_type>
127 static void AllocateElement(t_buffer_type& buff, t_index_type index,
const t_type&
object)
129 buff.get(index) = object;
131 template<
class t_buffer_type,
class t_type>
134 buff.get(index) = std::forward<t_type>(
object);
148 template<
class t_index_type>
166 template<
class t_buffer_type,
class t_type>
167 static void Allocate(t_buffer_type& buff, t_index_type start, t_index_type size)
169 for (t_index_type i = 0; i < size; i++)
171 new (&buff.get(i + start)) t_type();
189 template<
class t_buffer_type,
class t_type>
190 static void Deallocate(t_buffer_type& buff, t_index_type start, t_index_type size)
192 for (t_index_type i = 0; i < size; i++)
194 (&buff.get(i + start))->~t_type();
214 template<
class t_buffer_type,
class t_type>
215 static void AllocateElement(t_buffer_type& buff, t_index_type start, t_index_type size,
const t_type&
object)
217 for (t_index_type i = 0; i < size; i++)
219 new (&buff.get(i + start)) t_type(
object);
238 template<
class t_buffer_type,
class t_type>
239 static void AllocateElement(t_buffer_type& buff, t_index_type index,
const t_type&
object)
241 new (&buff.get(index)) t_type(
object);
243 template<
class t_buffer_type,
class t_type>
246 new (&buff.get(index)) t_type(std::move(
object));
259 template<
bool t_is_primitive,
class t_index_type = u
int04>
277 template<
class t_type,
class t_buffer_type>
278 static void Allocate(t_buffer_type& buffer, t_index_type start, t_index_type size)
295 template<
class t_type,
class t_buffer_type>
296 static void Deallocate(t_buffer_type& buffer, t_index_type start, t_index_type size)
315 template<
class t_type,
class t_buffer_type>
316 static void AllocateElement(t_buffer_type& buffer, t_index_type start, t_index_type size,
const t_type&
object)
320 template<
class t_type,
class t_buffer_type>
321 static void AllocateElement(t_buffer_type& buffer, t_index_type start, t_index_type size, t_type&
object)
338 template<
class t_type,
class t_buffer_type>
339 static void AllocateElement(t_buffer_type& buffer, t_index_type index,
const t_type&
object)
343 template<
class t_type,
class t_buffer_type>
344 static void AllocateElement(t_buffer_type& buffer, t_index_type index, t_type&&
object)
360 return t_is_primitive;
368 template<
class t_type,
class t_index_type,
bool t_null_term = false>
369 class BufferAllocator
372 [[nodiscard]]
static constexpr bool IsNullTerm() {
return t_null_term; }
377#ifndef NDEVR_LIB_SIZE_FUNCTION
384#ifndef NDEVR_LIB_SIZE_FUNCTION
388 std::swap(allocator.m_buffer,
m_buffer);
390#ifndef NDEVR_LIB_SIZE_FUNCTION
399 template<
bool t_managed>
406 template<
bool t_managed>
422 [[nodiscard]] t_index_type
count(
const t_type& value)
const
424 t_index_type
count = 0;
476 #pragma clang diagnostic push
477 #pragma clang diagnostic ignored "-Wdynamic-class-memaccess"
487 #pragma clang diagnostic pop
543 void swap(t_index_type index_a, t_index_type index_b)
593 t_type&
get(t_index_type index)
611 [[nodiscard]]
const t_type&
get(t_index_type index)
const
621 [[nodiscard]]
const t_type*
ptr()
const
656 [[nodiscard]]
const t_type*
begin()
const
674 [[nodiscard]] t_type*
begin(t_index_type index)
const
690#ifdef NDEVR_LIB_SIZE_FUNCTION
713 [[nodiscard]] t_type*
end()
730 [[nodiscard]]
const t_type*
end()
const
750 t_type*
end(t_index_type index)
777 m_buffer = (t_type*)malloc(
sizeof(t_type) * (t_null_term ? new_size + 1 : new_size));
779 m_buffer = (t_type*)realloc(
m_buffer,
sizeof(t_type) * (t_null_term ? new_size + 1 : new_size));
783 lib_assert(
false,
"Unable to allocate buffer: Perhaps out of system memory!");
786#ifndef NDEVR_LIB_SIZE_FUNCTION
804 void setAll(
const t_type&
object, t_index_type offset, t_index_type size)
812 for (t_index_type i = offset; i < offset + size; i++)
835 template<
bool is_primitive>
836 void setAll(
const t_type* src, t_index_type offset, t_index_type size)
838 if constexpr (is_primitive)
840 memmove(&
m_buffer[offset], src, size *
sizeof(t_type));
844 for (t_index_type i = 0; i < size; i++)
911 template<
bool is_primitive,
class t_other_index_type,
bool t_other_null_term>
914 if constexpr (is_primitive)
916 memmove(&
m_buffer[offset], &(allocator.m_buffer[other_offset]), size *
sizeof(t_type));
920 for (t_index_type i = 0; i < size; i++)
922 m_buffer[i + offset] = allocator.get(i + other_offset);
941 template<
class t_other_allocator>
942 void setAllFromSource(
const t_other_allocator& allocator, t_index_type offset, t_index_type other_offset, t_index_type size)
944 for (t_index_type i = 0; i < size; i++)
946 m_buffer[i + offset] = allocator.get(i + other_offset);
957 template<
bool t_managed>
960 if constexpr (t_managed)
1007 template<
class t_range_buffer>
1011 for (
uint04 i = 0; i < ranges.size(); i++)
1013 auto range = ranges[i];
1014 t_index_type start = range.first;
1015 t_index_type
end = range.second;
1018 offset += (
end - start);
1035 template<
bool t_is_null>
1038 if constexpr (t_is_null)
1067 template<
bool t_is_null>
1070 if constexpr(t_is_null)
1072 static constexpr t_type null_object = {};
1073 return const_cast<t_type*
>(&null_object);
1112 std::swap(value.m_buffer,
m_buffer);
1114#ifndef NDEVR_LIB_SIZE_FUNCTION
1123#ifndef NDEVR_LIB_SIZE_FUNCTION
#define lib_assert(expression, message)
Definition LibAssert.h:61
Specific logic for reserving memory for a Buffer. When managed, and more memory is needed memory is r...
Definition Pointer.hpp:311
void createSpace(t_index_type location, t_index_type size)
Definition MemoryManager.h:407
const t_type & get(t_index_type index) const
Definition MemoryManager.h:611
sint04 compare(const BufferAllocator &allocator, t_index_type start, t_index_type end) const
Definition MemoryManager.h:526
void setAllFromSource(const t_other_allocator &allocator, t_index_type offset, t_index_type other_offset, t_index_type size)
Definition MemoryManager.h:942
void createSpace(t_index_type size)
Definition MemoryManager.h:400
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:912
t_index_type m_filled_size
Definition MemoryManager.h:1122
const t_type * begin() const
Definition MemoryManager.h:656
void addIndex(t_index_type location)
Definition MemoryManager.h:457
sint04 compare(const BufferAllocator &allocator) const
Definition MemoryManager.h:504
static constexpr bool IsNullTerm()
Definition MemoryManager.h:372
t_type * end()
Definition MemoryManager.h:713
t_index_type capacity() const
Definition MemoryManager.h:688
void allocationSizeCheck()
Definition MemoryManager.h:958
constexpr BufferAllocator(BufferAllocator &&allocator) noexcept
Definition MemoryManager.h:381
void removeAllIndex(t_index_type start, t_index_type end)
Definition MemoryManager.h:994
void nullTerminatorCheck()
Definition MemoryManager.h:1036
void removeAllIndices(const t_range_buffer &ranges)
Definition MemoryManager.h:1008
constexpr t_index_type filledSize() const
Definition MemoryManager.h:1091
t_type * begin(t_index_type index) const
Definition MemoryManager.h:674
t_type * end(t_index_type index)
Definition MemoryManager.h:750
void swap(t_index_type index_a, t_index_type index_b)
Definition MemoryManager.h:543
const t_type * end() const
Definition MemoryManager.h:730
t_type & get(t_index_type index)
Definition MemoryManager.h:593
BufferAllocator & operator=(BufferAllocator &&value) noexcept
Definition MemoryManager.h:1110
t_type * emptyPtr() const
Definition MemoryManager.h:1068
void removeIndex(t_index_type location)
Definition MemoryManager.h:479
void setAll(const t_type *src, t_index_type offset, t_index_type size)
Definition MemoryManager.h:836
t_index_type m_allocated_size
Definition MemoryManager.h:1124
void addLast()
Definition MemoryManager.h:412
const t_type * ptr() const
Definition MemoryManager.h:621
t_index_type memSize() const
Definition MemoryManager.h:626
constexpr BufferAllocator()
Definition MemoryManager.h:374
t_type * begin()
Definition MemoryManager.h:641
t_type * ptr()
Definition MemoryManager.h:616
void clear()
Definition MemoryManager.h:556
~BufferAllocator()
Definition MemoryManager.h:394
void resizeSpace(t_index_type new_size)
Definition MemoryManager.h:766
void setAll(const t_type &object, t_index_type offset, t_index_type size)
Definition MemoryManager.h:804
t_type * m_buffer
Definition MemoryManager.h:1121
void setSize(t_index_type size)
Definition MemoryManager.h:573
t_index_type count(const t_type &value) const
Definition MemoryManager.h:422
void removeLast()
Definition MemoryManager.h:416
void addIndex()
Definition MemoryManager.h:441
Definition MemoryManager.h:261
static void AllocateElement(t_buffer_type &buffer, t_index_type start, t_index_type size, t_type &object)
Definition MemoryManager.h:321
static constexpr bool isPrimitive()
Definition MemoryManager.h:358
static void Deallocate(t_buffer_type &buffer, t_index_type start, t_index_type size)
Definition MemoryManager.h:296
static void AllocateElement(t_buffer_type &buffer, t_index_type index, t_type &&object)
Definition MemoryManager.h:344
static void AllocateElement(t_buffer_type &buffer, t_index_type index, const t_type &object)
Definition MemoryManager.h:339
static void AllocateElement(t_buffer_type &buffer, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:316
static void Allocate(t_buffer_type &buffer, t_index_type start, t_index_type size)
Definition MemoryManager.h:278
static void AllocateElement(t_buffer_type &buff, t_index_type index, const t_type &object)
Definition MemoryManager.h:239
static void AllocateElement(t_buffer_type &buff, t_index_type index, t_type &&object)
Definition MemoryManager.h:244
static void Allocate(t_buffer_type &buff, t_index_type start, t_index_type size)
Definition MemoryManager.h:167
static void Deallocate(t_buffer_type &buff, t_index_type start, t_index_type size)
Definition MemoryManager.h:190
static void AllocateElement(t_buffer_type &buff, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:215
static void AllocateElement(t_buffer_type &buff, t_index_type index, const t_type &object)
Definition MemoryManager.h:127
static void AllocateElement(t_buffer_type &buff, t_index_type index, t_type &&object)
Definition MemoryManager.h:132
static void Allocate(t_buffer_type &, t_index_type, t_index_type)
Definition MemoryManager.h:67
static void AllocateElement(t_buffer_type &buff, t_index_type start, t_index_type size, const t_type &object)
Definition MemoryManager.h:106
static void Deallocate(t_buffer_type &, t_index_type, t_index_type)
Definition MemoryManager.h:86
The default object allocator for Buffer.
Definition MemoryManager.h:53
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233