3#include "../Memory/Allocator.h"
7#include <initializer_list>
19 capacityPtr(static_cast<uint8_t*>(firstPtr) + capacity),
23 void growPod(
const void* firstElement,
const size_t minSizeBytes);
27 return static_cast<size_t>(
static_cast<uint8_t*
>(lastPtr) -
static_cast<uint8_t*
>(firstPtr));
32 return static_cast<size_t>(
static_cast<uint8_t*
>(capacityPtr) -
static_cast<uint8_t*
>(firstPtr));
62 assert(index <
size() &&
"Index out of bounds");
63 return begin()[index];
68 assert(index <
size() &&
"Index out of bounds");
69 return begin()[index];
116 template<
typename T,
bool isPod>
126 new (this->
end())
T(t);
136 new (this->
end())
T(std::move(t));
140 template<
typename... Args>
147 new (this->
end())
T(std::forward<Args>(args)...);
160 const size_t index = pos - this->
begin();
161 assert(index < this->
size() &&
"Index out of bounds");
162 (this->
begin() + index)->~
T();
173 size_t newCapacity = this->
capacity() * 2;
174 if (minSize > newCapacity) newCapacity = minSize;
176 const size_t currentSize = this->
size();
185 this->
lastPtr = newBuffer + currentSize;
191 while (first != last) {
198 while (first != last) {
203 template<
typename T1,
typename T2>
206 while (first != last) {
207 new (dest++)
T(std::move(*first++));
211 template<
typename T1,
typename T2>
212 void move(T1 first, T1 last, T2 dest)
214 while (first != last) {
215 (*dest++) = std::move(*first++);
219 template<
typename T1,
typename T2>
220 void copy(T1 first, T1 last, T2 dest)
222 while (first != last) {
223 (*dest++) = *first++;
227 template<
typename T1,
typename T2>
230 while (first != last) {
231 new (dest++)
T(*first++);
246 new (this->
end())
T(t);
258 const size_t index = pos - this->
begin();
259 assert(index < this->
size() &&
"Index out of bounds");
277 template<
typename T1,
typename T2>
278 void move(T1 first, T1 last, T2 dest)
280 copy(first, last, dest);
283 template<
typename T1,
typename T2>
284 void copy(T1 first, T1 last, T2 dest)
289 template<
typename T1,
typename T2>
292 std::memcpy(dest, first, (last - first) *
sizeof(
T));
311 if (
this == &other)
return *
this;
328 if (
this == &other)
return *
this;
332 if (!other.isSmall()) {
347 if (this->
capacity() < other.capacity()) {
348 this->
grow(other.size());
351 this->
move(other.begin(), other.end(), this->begin());
369 if (newCapacity >= this->
capacity()) {
370 this->
grow(newCapacity);
381 template<
typename T1>
385 const size_t newSize = last - first;
397 assign(il.begin(), il.end());
400 template<
typename T1>
403 const size_t newSize = last - first + this->
size();
415 append(il.begin(), il.end());
429 template<
typename T,
size_t Size>
432 template<
typename Ts,
size_t Sizes>
#define COGSFOUNDATION_API
Definition: FoundationBase.h:31
Definition: SmallVector.h:14
SmallVectorBase(void *data, size_t capacity, Memory::Allocator *allocator)
Definition: SmallVector.h:16
Memory::Allocator * allocator
Definition: SmallVector.h:38
void * capacityPtr
Definition: SmallVector.h:37
void * lastPtr
Definition: SmallVector.h:36
size_t capacityInBytes() const
Definition: SmallVector.h:30
size_t sizeInBytes() const
Definition: SmallVector.h:25
void growPod(const void *firstElement, const size_t minSizeBytes)
Definition: SmallVector.cpp:3
void * firstPtr
Definition: SmallVector.h:35
void initialize(T *, T *)
Definition: SmallVector.h:274
void copy(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:284
SmallVectorImplBase(size_t capacity, Memory::Allocator *allocator)
Definition: SmallVector.h:265
void pop_back()
Definition: SmallVector.h:250
void grow(size_t minSize=0)
Definition: SmallVector.h:269
void copyNew(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:290
void erase(const T *pos)
Definition: SmallVector.h:256
void destroy(T *, T *)
Definition: SmallVector.h:275
void push_back(const T &t)
Definition: SmallVector.h:240
void move(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:278
Definition: SmallVector.h:118
void emplace_back(Args &&... args)
Definition: SmallVector.h:141
void destroy(T *first, const T *last)
Definition: SmallVector.h:196
void initialize(T *first, const T *last)
Definition: SmallVector.h:189
void push_back(const T &t)
Definition: SmallVector.h:120
void pop_back()
Definition: SmallVector.h:151
void erase(const T *pos)
Definition: SmallVector.h:158
void copy(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:220
void push_back(T &&t)
Definition: SmallVector.h:130
void moveNew(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:204
void copyNew(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:228
void move(T1 first, T1 last, T2 dest)
Definition: SmallVector.h:212
SmallVectorImplBase(size_t capacity, Memory::Allocator *allocator)
Definition: SmallVector.h:168
void grow(size_t minSize=0)
Definition: SmallVector.h:171
Definition: SmallVector.h:298
void assign(std::initializer_list< T > il)
Definition: SmallVector.h:395
void reserve(size_t newCapacity)
Definition: SmallVector.h:367
SmallVectorImpl & operator=(SmallVectorImpl &&other) noexcept
Definition: SmallVector.h:326
void release()
Definition: SmallVector.h:423
SmallVectorImpl & operator=(const SmallVectorImpl &other)
Definition: SmallVector.h:309
void assign(T1 first, T1 last)
Definition: SmallVector.h:382
void resize(size_t newSize)
Definition: SmallVector.h:358
SmallVectorImpl(size_t capacity, Memory::Allocator *allocator=Memory::Allocator::overflowAllocator())
Definition: SmallVector.h:419
void append(std::initializer_list< T > il)
Definition: SmallVector.h:413
void append(T1 first, T1 last)
Definition: SmallVector.h:401
~SmallVectorImpl()
Definition: SmallVector.h:300
void clear()
Definition: SmallVector.h:374
Definition: SmallVector.h:43
size_t size() const
Definition: SmallVector.h:46
T * end()
Definition: SmallVector.h:53
T & front()
Definition: SmallVector.h:84
void setSize(size_t newSize)
Definition: SmallVector.h:102
SmallVectorTemplateBase(size_t capacity, Memory::Allocator *allocator)
Definition: SmallVector.h:97
const T & front() const
Definition: SmallVector.h:90
size_t capacity() const
Definition: SmallVector.h:47
const T * end() const
Definition: SmallVector.h:56
void reset()
Definition: SmallVector.h:108
const T * data() const
Definition: SmallVector.h:50
const T & back() const
Definition: SmallVector.h:78
bool empty() const
Definition: SmallVector.h:45
const T * begin() const
Definition: SmallVector.h:55
uint8_t firstElement[sizeof(T)]
Definition: SmallVector.h:113
bool isSmall() const
Definition: SmallVector.h:100
T * begin()
Definition: SmallVector.h:52
T * data()
Definition: SmallVector.h:49
T & back()
Definition: SmallVector.h:72
const T & operator[](const size_t index) const
Definition: SmallVector.h:66
const T * cend() const
Definition: SmallVector.h:58
T & operator[](const size_t index)
Definition: SmallVector.h:60
const T * cbegin() const
Definition: SmallVector.h:57
Definition: SmallVector.h:431
ptrdiff_t difference_type
Definition: SmallVector.h:444
SmallVector()
Definition: SmallVector.h:448
SmallVector & operator=(SmallVectorImpl< T > &&other) noexcept
Definition: SmallVector.h:489
SmallVector & operator=(SmallVector &&other) noexcept
Definition: SmallVector.h:483
SmallVector(SmallVector &&other) noexcept
Definition: SmallVector.h:452
SmallVector & operator=(const SmallVector &other)
Definition: SmallVector.h:477
SmallVectorStorage< T, Size > inlineStorage
Definition: SmallVector.h:496
SmallVector(Memory::Allocator *allocator)
Definition: SmallVector.h:450
SmallVector(const SmallVector &other)
Definition: SmallVector.h:462
SmallVector(const SmallVectorImpl< T > &other)
Definition: SmallVector.h:467
T value_type
Definition: SmallVector.h:443
const T * pointer
Definition: SmallVector.h:445
SmallVector(std::initializer_list< T > il)
Definition: SmallVector.h:472
const T & reference
Definition: SmallVector.h:446
SmallVector(SmallVectorImpl< T > &&other) noexcept
Definition: SmallVector.h:457
SmallVector(size_t size)
Definition: SmallVector.h:449
Base allocator implementation.
Definition: Allocator.h:30
virtual void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
Deallocate the memory block at the given pointer, with the given size.
Definition: Allocator.cpp:58
virtual void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
Allocate raw memory.
Definition: Allocator.cpp:29
static Allocator * overflowAllocator()
Definition: Allocator.cpp:24
Main Cogs namespace.
Definition: MortonCode.h:5
Definition: SmallVector.h:434
uint8_t inlineStorage[sizeof(Ts) *Sizes]
Definition: SmallVector.h:435