SimpleCxxLib
packageclass Grid<ValueType>
n
, in which
the elements are 1.0 along the main diagonal and 0.0 everywhere else:
Grid<double> createIdentityMatrix(int n) { Grid<double> matrix(n, n); for (int i = 0; i < n; i++) { matrix[i][i] = 1.0; } return matrix; }
Constructor | |
Grid(nRows, nCols) | Initializes a new grid. |
Methods | |
Returns the element at the specified row /col position in this grid. | |
Returns true if the specified row and column position is inside the bounds of the grid. | |
Calls the specified function on each element of the grid. | |
Returns the number of columns in the grid. | |
Returns the number of rows in the grid. | |
Reinitializes the grid to have the specified number of rows and columns. | |
Replaces the element at the specified row /col location in this grid with a new value. | |
Converts the grid to a printable string representation. | |
Operator | |
Overloads [] to select elements from this grid. |
Grid(); Grid(int nRows, int nCols);
resize
to
set the dimensions.
Usage:
Grid<ValueType> grid; Grid<ValueType> grid(nRows, nCols); Grid<ValueType> grid = {{ value1, value2, value3 }, { value4, value5, value6 }};
int numRows() const;
Usage:
int nRows = grid.numRows();
int numCols() const;
Usage:
int nCols = grid.numCols();
void resize(int nRows, int nCols);
Usage:
grid.resize(nRows, nCols);
bool inBounds(int row, int col) const;
true
if the specified row and column position
is inside the bounds of the grid.
Usage:
if (grid.inBounds(row, col)) ...
ValueType get(int row, int col); const ValueType & get(int row, int col) const;
row
/col
position in this grid. This method signals an error if the
row
and col
arguments are outside
the grid boundaries.
Usage:
ValueType value = grid.get(row, col);
void set(int row, int col, ValueType value);
row
/col
location in this grid with a new value. This method signals an error
if the row
and col
arguments are outside
the grid boundaries.
Usage:
grid.set(row, col, value);
string toString();
Usage:
string str = grid.toString();
void mapAll(void (*fn)(ValueType value)) const; void mapAll(void (*fn)(const ValueType & value)) const; void mapAll(FunctorType fn) const;
Usage:
grid.mapAll(fn);
GridRow operator[](int row); const GridRow operator[](int row) const;
[]
to select elements from this grid.
This extension enables the use of traditional array notation to
get or set individual elements. This method signals an error if
the row
and col
arguments are outside
the grid boundaries.
Usage:
grid[row][col]