Grid of the cellular automaton.
More...
#include <grid.hpp>
|
std::ostream & | operator<< (std::ostream &os, const Grid &grid) |
| Prints the grid on the stream, with the elements in a row separated by a whitespace and the rows separated by a newline. More...
|
|
bool | operator== (const Grid &lhs, const Grid &rhs) |
| Compare two grids for equality. More...
|
|
template<typename T>
class ca::Grid< T >
Grid of the cellular automaton.
- Template Parameters
-
◆ Grid() [1/4]
Construct a new Grid object.
- Parameters
-
rows | number of rows of the grid. |
cols | number of columns of the grid. |
- Exceptions
-
invalid_argument | if either rows or cols are zero. |
◆ Grid() [2/4]
Construct a new Grid object.
- Parameters
-
grid_ | vector containing the elements of the grid. |
rows | number of rows of the grid. |
- Note
- the number of columns will be calculated as grid_.size() / rows.
- Precondition
- rows >= 1 && rows
-
rows divides grid_.size()
◆ Grid() [3/4]
Construct a new Grid object.
- Parameters
-
◆ Grid() [4/4]
Construct a new Grid object.
- Parameters
-
◆ columns()
Returns the number of columns of the grid.
- Returns
- size_t number of columns.
◆ getInnerVector()
template<typename T >
std::vector<T>& ca::Grid< T >::getInnerVector |
( |
| ) |
|
|
inline |
Get a reference to the vector representing the grid.
- Returns
- std::vector<T>& vector representing the grid.
◆ newFromFile()
template<typename T >
static Grid ca::Grid< T >::newFromFile |
( |
std::string |
filepath | ) |
|
|
inlinestatic |
Load a grid from a file.
The file must contain the number of rows, the number of columns and then the elements of the grid.
- Parameters
-
filepath | path to the file. |
- Returns
- Grid grid initialized with the content of the file.
◆ newWithSameSize()
Return a grid of the same dimension of the grid passed as argument.
- Parameters
-
other | Grid whose dimension has to be taken. |
- Returns
- Grid new grid of same dimension.
◆ operator()() [1/2]
template<typename T >
T& ca::Grid< T >::operator() |
( |
unsigned |
row, |
|
|
unsigned |
col |
|
) |
| |
|
inline |
Get the element in position row,col.
- Parameters
-
row | row number. |
col | column number. |
- Precondition
- 0 <= rows < this->nrows
-
0 <= col < this->ncols
- Returns
- T& reference to the element in position row,col
◆ operator()() [2/2]
template<typename T >
T ca::Grid< T >::operator() |
( |
unsigned |
row, |
|
|
unsigned |
col |
|
) |
| const |
|
inline |
Get the element in position row,col.
- Parameters
-
row | row number. |
col | column number. |
- Precondition
- 0 <= rows < this->nrows
-
0 <= col < this->ncols
- Returns
- T& reference to the element in position row,col
◆ rows()
Returns the number of rows of the grid.
- Returns
- size_t number of rows.
◆ swap()
Swap the content of the grid with the one of another grid.
- Parameters
-
◆ toFile()
template<typename T >
void ca::Grid< T >::toFile |
( |
std::string |
filepath | ) |
|
|
inline |
Writes the grid to a file.
- Parameters
-
filepath | path of the file. |
◆ operator<<
template<typename T >
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const Grid< T > & |
grid |
|
) |
| |
|
friend |
Prints the grid on the stream, with the elements in a row separated by a whitespace and the rows separated by a newline.
- Parameters
-
os | output stream on which to print. |
grid | grid to print. |
- Returns
- std::ostream&
◆ operator==
template<typename T >
bool operator== |
( |
const Grid< T > & |
lhs, |
|
|
const Grid< T > & |
rhs |
|
) |
| |
|
friend |
Compare two grids for equality.
- Returns
- true if the grids are equal.
-
false if the grids differ.
The documentation for this class was generated from the following file: