2 #ifdef USE_INITIALIZER_LIST
3 #include "InitializerList.h"
82 #ifdef USE_INITIALIZER_LIST
85 Vector(std::initializer_list<T> iniList) {
88 for (
auto &obj : iniList) {
108 for (
int j = 0; j <
size; j++) {
130 for (
int j = 0; j < copyFrom.
size(); j++) {
139 for (
int j = 0; j < copyFrom.
size(); j++) {
149 this->
len = to - from;
151 for (
size_t j = 0; j < this->
len; j++) {
182 for (
int j =
len; j >= 0; j--) {
192 for (
int j =
len; j >= 0; j--) {
208 size_t newLen = v2 - v1;
212 for (
auto ptr = v1; ptr != v2; ptr++) {
220 for (
int j = 0; j < number; j++) {
241 assert(
p_data !=
nullptr);
249 for (
int j = 0; j < newSize; j++) {
262 int oldSize = this->
len;
265 return this->
len != oldSize;
280 int lenToEnd =
len - pos - 1;
284 memmove((
void *)&
p_data[pos], (
void *)(&
p_data[pos + 1]),
285 lenToEnd *
sizeof(T));
296 operator bool()
const {
return p_data !=
nullptr; }
299 for (
int j = 0; j <
size(); j++) {
300 if (
p_data[j] == obj)
return j;
317 other.bufferLen = temp_blen;
318 other.len = temp_len;
319 other.p_data = temp_data;
336 if (newSize <= 0)
return;
337 if (newSize >
max_capacity || this->p_data ==
nullptr || shrink) {
341 assert(
p_data !=
nullptr);
342 this->max_capacity = newSize;
343 if (oldData !=
nullptr) {
344 if (copy && this->len > 0) {
346 memmove((
void *)
p_data, (
void *)oldData,
len *
sizeof(T));
348 memset((
void *)oldData, 0,
len *
sizeof(T));
351 cleanup(oldData, newSize, oldBufferLen);
363 data =
new T[newSize];
377 for (
int j = from; j < to; j++) {
Memory allocateator which uses malloc.
Definition: Allocator.h:21
void removeArray(T *obj, int len)
Definition: Allocator.h:52
T * createArray(int len)
Definition: Allocator.h:42
Iterator for the Vector class.
Definition: Vector.h:29
iterator operator--(int n)
Definition: Vector.h:55
iterator(const iterator ©From)
Definition: Vector.h:41
T * operator->()
Definition: Vector.h:76
T & operator*()
Definition: Vector.h:75
bool operator>(iterator it)
Definition: Vector.h:72
size_t pos_
Definition: Vector.h:32
size_t pos()
Definition: Vector.h:78
T * getPtr()
Definition: Vector.h:77
iterator operator+(int offset)
Definition: Vector.h:65
size_t operator-(iterator it)
Definition: Vector.h:79
bool operator>=(iterator it)
Definition: Vector.h:73
iterator operator++(int n)
Definition: Vector.h:45
bool operator<(iterator it)
Definition: Vector.h:70
bool operator!=(iterator it)
Definition: Vector.h:74
iterator(T *parPtr, size_t pos)
Definition: Vector.h:36
iterator()
Definition: Vector.h:35
bool operator<=(iterator it)
Definition: Vector.h:71
T * ptr
Definition: Vector.h:31
bool operator==(iterator it)
Definition: Vector.h:69
iterator operator--()
Definition: Vector.h:60
iterator operator++()
Definition: Vector.h:50
Vector implementation which provides the most important methods as defined by std::vector....
Definition: Vector.h:21
virtual ~Vector()
Destructor.
Definition: Vector.h:157
void assign(iterator v1, iterator v2)
Definition: Vector.h:207
T & operator[](int index)
Definition: Vector.h:240
void erase(int pos)
Definition: Vector.h:278
void resize_internal(int newSize, bool copy, bool shrink=false)
Definition: Vector.h:335
void swap(T &other)
Definition: Vector.h:307
Allocator * p_allocator
Definition: Vector.h:333
Vector & operator=(Vector &&moveFrom)
Move operator.
Definition: Vector.h:120
Vector< T > & operator=(Vector< T > ©From)
copy operator
Definition: Vector.h:137
void clear()
Definition: Vector.h:161
void cleanup(T *data, int from, int to)
Definition: Vector.h:376
bool resize(int newSize, T value)
Definition: Vector.h:247
bool empty()
Definition: Vector.h:165
void assign(size_t number, T value)
Definition: Vector.h:217
Vector(Vector< T > &&moveFrom)
Move constructor.
Definition: Vector.h:114
Vector(T *from, T *to, Allocator &allocator=DefaultAllocator)
legacy constructor with pointer range
Definition: Vector.h:147
Vector(Allocator &allocator)
Constructor with only allocator.
Definition: Vector.h:102
void reset()
Definition: Vector.h:322
iterator end()
Definition: Vector.h:272
int size()
Definition: Vector.h:163
bool contains(T obj)
Definition: Vector.h:305
void push_back(T &&value)
Definition: Vector.h:167
T & back()
Definition: Vector.h:270
T & operator[](const int index) const
Definition: Vector.h:245
iterator begin()
Definition: Vector.h:268
bool resize(int newSize)
Definition: Vector.h:261
void swap(Vector< T > &in)
Definition: Vector.h:225
void pop_front()
Definition: Vector.h:205
int indexOf(T obj)
Definition: Vector.h:298
void push_front(T &value)
Definition: Vector.h:179
void push_front(T &&value)
Definition: Vector.h:189
int max_capacity
Definition: Vector.h:330
int len
Definition: Vector.h:331
void shrink_to_fit()
Definition: Vector.h:257
T * p_data
Definition: Vector.h:332
T * data()
Definition: Vector.h:294
void deleteArray(T *oldData, int oldBufferLen)
Definition: Vector.h:368
void push_back(T &value)
Definition: Vector.h:173
Vector(int size, T value, Allocator &allocator=DefaultAllocator)
Allocate size and initialize array.
Definition: Vector.h:105
void pop_back()
Definition: Vector.h:199
Vector(Vector< T > ©From)
copy constructor
Definition: Vector.h:127
void erase(iterator it)
Definition: Vector.h:275
T * newArray(int newSize)
Definition: Vector.h:358
int capacity()
Definition: Vector.h:259
Vector(size_t len=0, Allocator &allocator=DefaultAllocator)
Default constructor: size 0 with DefaultAllocator.
Definition: Vector.h:96
void setAllocator(Allocator &allocator)
Definition: Vector.h:159
Definition: Allocator.h:6