![]() |
Gamedev Framework (gf)
0.10.0
A C++14 framework for 2D games
|
A two-dimensional array. More...
#include <gf/Array2D.h>
Public Member Functions | |
Array2D () | |
Default constructor. More... | |
Array2D (Vector< I, 2 > size) | |
Constructor with a size. More... | |
Array2D (Vector< I, 2 > size, const T &value) | |
Constructor with a size and a value. More... | |
Array2D (const Array2D &)=default | |
Default copy constructor. More... | |
Array2D & | operator= (const Array2D &)=default |
Default copy assignment. More... | |
Array2D (Array2D &&)=default | |
Default move constructor. More... | |
Array2D & | operator= (Array2D &&)=default |
Default move assignement. More... | |
void | swap (Array2D &other) |
Swap with another array. More... | |
Raw data access | |
const T * | getDataPtr () const noexcept |
Get the pointer to raw data. More... | |
std::size_t | getDataSize () const noexcept |
Get the raw data size. More... | |
constexpr Vector< I, 2 > | getSize () const noexcept |
Get the size of the array. More... | |
constexpr I | getCols () const noexcept |
Get the number of columns. More... | |
constexpr I | getRows () const noexcept |
Get the number of rows. More... | |
constexpr bool | isEmpty () const noexcept |
Check if the array is empty. More... | |
constexpr bool | isValid (Vector< I, 2 > pos) const noexcept |
Check if a position is valid. More... | |
Elements access | |
T & | operator() (Vector< I, 2 > pos) |
Get the element at a given 2D position. More... | |
T & | operator() (std::size_t index) |
Get the element at a given 1D index. More... | |
const T & | operator() (Vector< I, 2 > pos) const |
Get the element at a given 2D position. More... | |
const T & | operator() (std::size_t index) const |
Get the element at a given 1D index. More... | |
constexpr Vector< I, 2 > | toPosition (std::size_t pos) const noexcept |
Transform a 1D position into a 2D position. More... | |
Visitors | |
template<typename Func > | |
void | visit4Neighbors (Vector< I, 2 > pos, Func func) |
Visit the 4 neighbors of a given position. More... | |
template<typename Func > | |
void | visit4Neighbors (Vector< I, 2 > pos, Func func) const |
Visit the 4 neighbors of a given position. More... | |
template<typename Func > | |
void | visit12Neighbors (Vector< I, 2 > pos, Func func) |
Visit the 12 neighbors of a given position. More... | |
template<typename Func > | |
void | visit12Neighbors (Vector< I, 2 > pos, Func func) const |
Visit the 12 neighbors of a given position. More... | |
template<typename Func > | |
void | visit8Neighbors (Vector< I, 2 > pos, Func func) |
Visit the 8 neighbors of a given position. More... | |
template<typename Func > | |
void | visit8Neighbors (Vector< I, 2 > pos, Func func) const |
Visit the 8 neighbors of a given position. More... | |
template<typename Func > | |
void | visit24Neighbors (Vector< I, 2 > pos, Func func) |
Visit the 24 neighbors of a given position. More... | |
template<typename Func > | |
void | visit24Neighbors (Vector< I, 2 > pos, Func func) const |
Visit the 24 neighbors of a given position. More... | |
Iterators and ranges | |
const T * | begin () const noexcept |
Get an iterator to the first element of the array. More... | |
const T * | end () const noexcept |
Get an iterator to the element following the last element of the array. More... | |
T * | begin () noexcept |
Get an iterator to the first element of the array. More... | |
T * | end () noexcept |
Get an iterator to the element following the last element of the array. More... | |
constexpr RangeZ | getIndexRange () const noexcept |
Get the 1D index range of the array. More... | |
constexpr Range< I > | getRowRange () const noexcept |
Get the row range. More... | |
constexpr Range< I > | getColRange () const noexcept |
Get the column range. More... | |
constexpr PositionRange< I > | getPositionRange () const noexcept |
Get the position range. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T , typename I > | |
bool | operator== (const Array2D< T, I > &lhs, const Array2D< T, I > &rhs) |
Equality operator for 2D array. More... | |
A two-dimensional array.
gf::Array represents a two-dimensional array, organized in row-major order.
The array is templated with the type of the data and the type of the indices (defaults to unsigned
).
Contrary to the usual way of accessing 2D arrays, the first coordinate is the column and the second coordinate is the row. So that, if size
is the size of the array and pos
is the position in the array:
Some convinient visitors are provided to visit the four neighbors (up, down, left and right), or the eight neighbors.
|
inline |
Default constructor.
Creates an empty array.
|
inline |
Constructor with a size.
size | The size of the array |
|
inline |
Constructor with a size and a value.
size | The size of the array |
value | The initial value in the array |
|
default |
Default copy constructor.
|
default |
Default move constructor.
|
inlinenoexcept |
Get an iterator to the first element of the array.
begin
iterator to the array
|
inlinenoexcept |
Get an iterator to the first element of the array.
begin
iterator to the array
|
inlinenoexcept |
Get an iterator to the element following the last element of the array.
end
iterator to the array
|
inlinenoexcept |
Get an iterator to the element following the last element of the array.
end
iterator to the array
|
inlinenoexcept |
Get the column range.
|
inlinenoexcept |
Get the number of columns.
|
inlinenoexcept |
Get the pointer to raw data.
The returned pointer is const
so you can not modify the array with this function.
|
inlinenoexcept |
Get the raw data size.
|
inlinenoexcept |
Get the 1D index range of the array.
|
inlinenoexcept |
Get the position range.
|
inlinenoexcept |
Get the row range.
|
inlinenoexcept |
Get the number of rows.
|
inlinenoexcept |
Get the size of the array.
|
inlinenoexcept |
Check if the array is empty.
An empty array is an array with \( 0 \) elements, i.e. either the number of columns is \( 0 \) or the number of rows is \( 0 \).
|
inlinenoexcept |
Check if a position is valid.
A valid position is a position inside the array
|
inline |
Get the element at a given 2D position.
pos | The 2D position of the element |
|
inline |
Get the element at a given 1D index.
index | The 1D index of the element |
|
inline |
Get the element at a given 2D position.
pos | The 2D position of the element |
|
inline |
Get the element at a given 1D index.
index | The 1D index of the element |
|
default |
Default copy assignment.
|
default |
Default move assignement.
|
inline |
Swap with another array.
other | An other array |
|
inlinenoexcept |
Transform a 1D position into a 2D position.
pos | A 1D position |
|
inline |
Visit the 12 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical and horizontal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 12 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical and horizontal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 24 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical, horizontal and diagonal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 24 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical, horizontal and diagonal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 4 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical and horizontal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 4 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical and horizontal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 8 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical, horizontal and diagonal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |
|
inline |
Visit the 8 neighbors of a given position.
This function calls a callback function for every neighbor in the vertical, horizontal and diagonal direction. The function checks if the neighbor actually exists.
The callback function has the following prototype:
The callback function can be a simple function but also a lambda expression.
pos | The position |
func | A callback function |