Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Grid2D< T > Class Template Reference

Fixed-size 2D grid storing values in column-major order. More...

#include <spk_grid_2d.hpp>

Collaboration diagram for spk::Grid2D< T >:
Collaboration graph

Classes

struct  ConstRow
 Immutable view over a single column in the grid. More...
struct  Row
 Mutable view over a single column in the grid. More...

Public Types

using Unit = T
 Stored element type for each grid cell.

Public Member Functions

 Grid2D ()=default
 Constructs an empty grid with zero dimensions.
 Grid2D (const spk::Vector2UInt &size, const Unit &fill=Unit{})
 Builds a grid with the given dimensions and fill value.
const spk::Vector2UIntsize () const
 Returns the grid dimensions.
size_t width () const
 Reports the horizontal cell count.
size_t height () const
 Reports the vertical cell count.
Unitoperator() (size_t x, size_t y)
 Mutable access to a cell using column and row indices.
const Unitoperator() (size_t x, size_t y) const
 Read-only access to a cell using column and row indices.
Row operator[] (size_t x)
 Provides a mutable column slice.
ConstRow operator[] (size_t x) const
 Provides a read-only column slice.
Unitdata ()
 Exposes the underlying contiguous buffer.
const Unitdata () const
 Exposes the underlying contiguous buffer (const overload).

Detailed Description

template<typename T>
class spk::Grid2D< T >

Fixed-size 2D grid storing values in column-major order.

Template Parameters
TCell value type stored in the grid.
spk::Grid2D<int> grid({3, 2}, 0);
grid(1, 1) = 5;
auto height = grid.height();
Fixed-size 2D grid storing values in column-major order.
Definition spk_grid_2d.hpp:20
size_t height() const
Reports the vertical cell count.
Definition spk_grid_2d.hpp:132

Constructor & Destructor Documentation

◆ Grid2D()

template<typename T>
spk::Grid2D< T >::Grid2D ( const spk::Vector2UInt & size,
const Unit & fill = Unit{} )
inlineexplicit

Builds a grid with the given dimensions and fill value.

Parameters
sizeWidth and height of the grid.
fillValue used to initialize every cell.
Here is the call graph for this function:

Member Function Documentation

◆ data() [1/2]

template<typename T>
Unit * spk::Grid2D< T >::data ( )
inline

Exposes the underlying contiguous buffer.

Returns
Pointer to the first stored element.

◆ data() [2/2]

template<typename T>
const Unit * spk::Grid2D< T >::data ( ) const
inline

Exposes the underlying contiguous buffer (const overload).

Returns
Const pointer to the first stored element.

◆ height()

template<typename T>
size_t spk::Grid2D< T >::height ( ) const
inline

Reports the vertical cell count.

Returns
Number of rows.

◆ operator()() [1/2]

template<typename T>
Unit & spk::Grid2D< T >::operator() ( size_t x,
size_t y )
inline

Mutable access to a cell using column and row indices.

Parameters
xColumn index.
yRow index.
Returns
Reference to the requested cell.

◆ operator()() [2/2]

template<typename T>
const Unit & spk::Grid2D< T >::operator() ( size_t x,
size_t y ) const
inline

Read-only access to a cell using column and row indices.

Parameters
xColumn index.
yRow index.
Returns
Const reference to the requested cell.

◆ operator[]() [1/2]

template<typename T>
Row spk::Grid2D< T >::operator[] ( size_t x)
inline

Provides a mutable column slice.

Parameters
xColumn index to view.
Returns
Row proxy with operator[] access.

◆ operator[]() [2/2]

template<typename T>
ConstRow spk::Grid2D< T >::operator[] ( size_t x) const
inline

Provides a read-only column slice.

Parameters
xColumn index to view.
Returns
ConstRow proxy with operator[] access.

◆ size()

template<typename T>
const spk::Vector2UInt & spk::Grid2D< T >::size ( ) const
inline

Returns the grid dimensions.

Returns
Vector where x is width and y is height.
Here is the caller graph for this function:

◆ width()

template<typename T>
size_t spk::Grid2D< T >::width ( ) const
inline

Reports the horizontal cell count.

Returns
Number of columns.

The documentation for this class was generated from the following file: