Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A two-dimensional array. More...
#include <gf/Array2D.h>
Public Member Functions | |
Array2D () | |
Default constructor. More... | |
Array2D (Vector2u size) | |
Constructor with a size. More... | |
Array2D (Vector2u 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... | |
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 Vector2u | getSize () const noexcept |
Get the size of the array. More... | |
constexpr unsigned | getCols () const noexcept |
Get the number of columns. More... | |
constexpr unsigned | getRows () const noexcept |
Get the number of rows. More... | |
constexpr bool | isEmpty () const noexcept |
Check if the array is empty. More... | |
Elements access | |
T & | operator() (Vector2u pos) |
Get the element at a given 2D position. More... | |
T & | operator() (std::size_t pos) |
Get the element at a given 1D position. More... | |
const T & | operator() (Vector2u pos) const |
Get the element at a given 2D position. More... | |
const T & | operator() (std::size_t pos) const |
Get the element at a given 1D position. More... | |
constexpr Vector2u | toPosition (std::size_t pos) const noexcept |
Transform a 1D position into a 2D position. More... | |
Visitors | |
template<typename Func > | |
void | visit4Neighbours (Vector2u pos, Func func) |
Visit the 4 neighbours of a given position. More... | |
template<typename Func > | |
void | visit4Neighbours (Vector2u pos, Func func) const |
Visit the 4 neighbours of a given position. More... | |
template<typename Func > | |
void | visit8Neighbours (const Vector2u &pos, Func func) |
Visit the 8 neighbours of a given position. More... | |
template<typename Func > | |
void | visit8Neighbours (Vector2u pos, Func func) const |
Visit the 8 neighbours 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 | getPositionRange () const noexcept |
Get the 1D position range of the array. More... | |
constexpr RangeU | getRowRange () const noexcept |
Get the row range. More... | |
constexpr RangeU | getColRange () const noexcept |
Get the column range. More... | |
A two-dimensional array.
gf::Array represents a two-dimensional array, organized in row-major order.
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
if the position in the array:
Some convinient visitors are provided to visit the four neighbours (up, down, left and right), or the eight neighbours.
|
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 position range of the array.
|
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 \).
|
inline |
Get the element at a given 2D position.
pos | The 2D position of the element |
|
inline |
Get the element at a given 1D position.
pos | The 1D position 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 position.
pos | The 1D position of the element |
|
default |
Default copy assignment.
|
default |
Default move assignement.
|
inlinenoexcept |
Transform a 1D position into a 2D position.
pos | A 1D position |
|
inline |
Visit the 4 neighbours of a given position.
This function calls a callback function for every neighbour in the vertical and horizontal direction. The function checks if the neighbour 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 neighbours of a given position.
This function calls a callback function for every neighbour in the vertical and horizontal direction. The function checks if the neighbour 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 neighbours of a given position.
This function calls a callback function for every neighbour in the vertical, horizontal and diagonal direction. The function checks if the neighbour 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 neighbours of a given position.
This function calls a callback function for every neighbour in the vertical, horizontal and diagonal direction. The function checks if the neighbour 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 |