Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
hgps::core::Array2D< TYPE > Class Template Reference

Defines a contiguous storage for two-dimensional numerical data in row-major format. More...

#include <array2d.h>

Public Member Functions

 Array2D ()=default
 Initialises new instance of the Array2D class with no storage. More...
 
 Array2D (const size_t nrows, const size_t ncols)
 Initialises new instance of the Array2D class. More...
 
 Array2D (const size_t nrows, const size_t ncols, TYPE value)
 Initialises new instance of the Array2D class with custom default value. More...
 
 Array2D (const size_t nrows, const size_t ncols, std::vector< TYPE > &values)
 Initialises new instance of the Array2D class with custom values. More...
 
size_t size () const noexcept
 Gets the total size of the array storage. More...
 
size_t rows () const noexcept
 Gets the number of rows in the array. More...
 
size_t columns () const noexcept
 Gets the number of coluns in the array. More...
 
TYPE & operator() (size_t row, size_t column)
 Gets a value from the array. More...
 
const TYPE & operator() (size_t row, size_t column) const
 Gets a read-only value from the array. More...
 
void fill (TYPE value)
 Fill the array data with a default value. More...
 
void clear ()
 Clears the array data with the default type value. More...
 
std::vector< TYPE > to_vector ()
 Creates a vector copy of the array data. More...
 
std::string to_string () noexcept
 Creates a string representation of the array data. More...
 

Detailed Description

template<Numerical TYPE>
class hgps::core::Array2D< TYPE >

Defines a contiguous storage for two-dimensional numerical data in row-major format.

Template Parameters
TYPEThe numerical type to store

Constructor & Destructor Documentation

◆ Array2D() [1/4]

template<Numerical TYPE>
hgps::core::Array2D< TYPE >::Array2D ( )
default

Initialises new instance of the Array2D class with no storage.

◆ Array2D() [2/4]

template<Numerical TYPE>
hgps::core::Array2D< TYPE >::Array2D ( const size_t  nrows,
const size_t  ncols 
)
inline

Initialises new instance of the Array2D class.

Parameters
nrowsThe number of rows in the array
ncolsThe number fo columns in the array
Exceptions
std::invalid_argumentfor array with zero size storage;

◆ Array2D() [3/4]

template<Numerical TYPE>
hgps::core::Array2D< TYPE >::Array2D ( const size_t  nrows,
const size_t  ncols,
TYPE  value 
)
inline

Initialises new instance of the Array2D class with custom default value.

Parameters
nrowsThe number of rows in the array
ncolsThe number of columns in the array
valueThe default value to initialise the array values
Exceptions
std::invalid_argumentfor array with zero size storage;
Here is the call graph for this function:

◆ Array2D() [4/4]

template<Numerical TYPE>
hgps::core::Array2D< TYPE >::Array2D ( const size_t  nrows,
const size_t  ncols,
std::vector< TYPE > &  values 
)
inline

Initialises new instance of the Array2D class with custom values.

Parameters
nrowsThe number of rows in the array
ncolsThe number of columns in the array
valuesArray of values to initialise the storage
Exceptions
std::invalid_argumentfor array size and values size mismatch.
Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<Numerical TYPE>
void hgps::core::Array2D< TYPE >::clear ( )
inline

Clears the array data with the default type value.

Here is the call graph for this function:

◆ columns()

template<Numerical TYPE>
size_t hgps::core::Array2D< TYPE >::columns ( ) const
inlinenoexcept

Gets the number of coluns in the array.

Returns
The number of columns
Here is the caller graph for this function:

◆ fill()

template<Numerical TYPE>
void hgps::core::Array2D< TYPE >::fill ( TYPE  value)
inline

Fill the array data with a default value.

Parameters
valueThe default value to store in the array
Here is the caller graph for this function:

◆ operator()() [1/2]

template<Numerical TYPE>
TYPE& hgps::core::Array2D< TYPE >::operator() ( size_t  row,
size_t  column 
)
inline

Gets a value from the array.

Parameters
rowThe zero-based row index
columnThe zero-based columns index
Returns
The respective value at location throws std::out_of_range for row or column index out of array bounds
Here is the caller graph for this function:

◆ operator()() [2/2]

template<Numerical TYPE>
const TYPE& hgps::core::Array2D< TYPE >::operator() ( size_t  row,
size_t  column 
) const
inline

Gets a read-only value from the array.

Parameters
rowThe zero-based row index
columnThe zero-based columns index
Returns
The respective value at location throws std::out_of_range for row or column index out of array bounds

◆ rows()

template<Numerical TYPE>
size_t hgps::core::Array2D< TYPE >::rows ( ) const
inlinenoexcept

Gets the number of rows in the array.

Returns
The number of rows
Here is the caller graph for this function:

◆ size()

template<Numerical TYPE>
size_t hgps::core::Array2D< TYPE >::size ( ) const
inlinenoexcept

Gets the total size of the array storage.

Returns
The total size
Here is the caller graph for this function:

◆ to_string()

template<Numerical TYPE>
std::string hgps::core::Array2D< TYPE >::to_string ( )
inlinenoexcept

Creates a string representation of the array data.

Returns
The string representation
Here is the call graph for this function:

◆ to_vector()

template<Numerical TYPE>
std::vector<TYPE> hgps::core::Array2D< TYPE >::to_vector ( )
inline

Creates a vector copy of the array data.

Returns
The vector with a copy of the data

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