9#ifndef MAXOS_COMMON_VECTOR_H
10#define MAXOS_COMMON_VECTOR_H
16namespace MaxOS::common {
91 m_elements =
new Type[m_capacity];
105 m_elements =
new Type[size];
106 m_capacity = size > 0 ? size : 1;
110 for(
int i = 0; i < size; ++i)
121 : m_size(
other.m_size),
122 m_capacity(
other.m_capacity) {
136 : m_elements(
other.m_elements),
137 m_size(
other.m_size),
138 m_capacity(
other.m_capacity) {
141 other.m_elements =
nullptr;
143 other.m_capacity = 0;
165 reserve(m_capacity * 2);
185 for(
uint32_t i = 0; i < m_size; ++i)
207 return m_elements[index];
210 return m_elements[m_size - 1];
232 m_size =
other.m_size;
233 m_capacity =
other.m_capacity;
234 for(
uint32_t i = 0; i < m_size; ++i)
235 m_elements[i] =
other.m_elements[i];
255 m_elements =
other.m_elements;
256 m_size =
other.m_size;
257 m_capacity =
other.m_capacity;
260 other.m_elements =
nullptr;
262 other.m_capacity = 0;
284 return &m_elements[0];
294 return &m_elements[0] + m_size;
307 for(
iterator i = begin(); i != end(); ++i)
322 return begin() == end();
336 if(m_size == m_capacity)
340 m_elements[m_size++] =
element;
356 return m_elements[m_size];
369 if(m_size == m_capacity)
373 for(
iterator i = end(); i > begin(); --i)
401 for(
uint32_t i = 0; i < m_size - 1; ++i)
402 m_elements[i] = m_elements[i + 1];
419 for(
iterator i = begin(); i != end(); ++i) {
445 if(position < begin() || position >= end())
449 for(++position; position != end(); ++position)
450 *(position - 1) = *position;
474 for(
auto&
element : m_elements)
491 for(
auto&
element : m_elements)
Stores the left, top, width and height of a rectangle.
Rectangle()
_______________________________________________TEMPLATES_____________________________________________...
Handles the iteration of a Vector providing read and end of stream functions.
virtual void on_read(Type)
Called when an element is read from the Vector (overridden by subclasses, no default behavior)
virtual void on_end_of_stream()
Called when the end of the stream is reached (overridden by subclasses, no default behavior)
Dynamically stores an array of elements.
iterator end() const
Returns the last element of the Vector.
Type & operator[](uint32_t index) const
Overloads the [] operator to return the element at the index.
uint32_t size() const
Returns the number of elements in the Vector.
Vector< Type > & operator=(const Vector< Type > &other)
Assignment by copy, data is copied into a new buffer stored in this vector.
uint32_t m_capacity
How many elements can be stored without resizing.
Type * m_elements
The array of elements.
void erase(typename Vector< Type >::iterator position)
Removes the element at the m_position.
void reserve(size_t amount)
Reserves space in the Vector for a certain amount of elements.
iterator push_front(Type)
Adds an element to the front of the Vector and returns the iterator of the element.
void clear()
Removes all elements from the Vector.
void iterate(void callback(Type &))
Iterates over the Vector and calls the callback function for each element.
void increase_size()
Increases the size of the Vector by doubling the capacity.
Vector(int size, Type element)
Constructor for Vector.
~Vector()
Destructor for Vector, de-allocates the array.
void iterate(VectorIterationHandler< Type > *)
Iterates over the Vector and calls the OnRead function of the handler for each element.
Type * iterator
The iterator type for the Vector.
uint32_t m_size
How many elements are currently stored.
Vector(Vector< Type > &&other)
Move constructor for Vector.
iterator find(Type) const
Finds an element in the Vector and returns the iterator of the element.
iterator push_back(Type)
Adds an element to the end of the vector and returns the iterator of the element.
Vector()
______________________________________Implementation_________________________________________________...
Type pop_back()
Removes the last element from the Vector.
Vector(const Vector< Type > &other)
Copy constructor for Vector.
iterator begin() const
Returns the first element of the Vector.
Type pop_front()
Removes the m_first_memory_chunk element from the Vector.
bool empty() const
Checks if the Vector is empty.
void erase(Type)
Removes all elements from the Vector that are equal to the element.