12 namespace datastructure {
35 int rows = gridSize[0];
36 int cols = gridSize[1];
38 for (
int j = 0; j < rows; j++) {
39 grid[j] =
new E[cols];
43 void deallocateGrid() {
45 for (
int i = 0; i < gridSize[0]; i++) {
53 void checkRowCol(
int row,
int col)
const {
54 if (row < 0 || col < 0 || row >= gridSize[0] || col >= gridSize[1])
55 throw "invalid location in Grid";
64 int maxGridSize[2] = {1080, 1920};
84 setDimensions(rows, cols);
101 :
Grid(size[0], size[1]) {
111 :
Grid(g.gridSize[0], g.gridSize[1]) {
112 for (
int i = 0; i < gridSize[0]; i++) {
113 for (
int j = 0; j < gridSize[1]; j++) {
114 set (i, j, g.
get(i, j));
130 if (this->gridSize[0] != g.
gridSize[0] ||
131 this->gridSize[1] != g.
gridSize[1] ) {
135 for (
int i = 0; i < gridSize[0]; i++) {
136 for (
int j = 0; j < gridSize[1]; j++) {
137 set (i, j, g.
get(i, j));
154 if (rows > maxGridSize[0] || cols > maxGridSize[1]) {
155 cerr <<
"Grid Maximum Size (1080 x 1920) exceeded!\n" 156 <<
"Provided Size: " << rows <<
" x " << cols
157 <<
". Aborting" << endl << endl;
180 E
const&
get(
int row,
int col)
const {
181 checkRowCol(row, col);
183 return grid[row][col];
192 void set(
int row,
int col, E val) {
193 checkRowCol(row, col);
195 grid[row][col] = val;
212 E
const & operator[] (
int col)
const {
213 return gr.
get(row, col);
218 BracketHelperConst operator[] (
int row)
const {
219 return BracketHelperConst(*
this, row);
235 E & operator[] (
int col) {
236 gr.checkRowCol(row, col);
237 return gr.
grid[row][col];
242 BracketHelper operator[] (
int row) {
243 return BracketHelper(*
this, row);
This BracketHelperConst is a helper class to get the [] operators to work.
Definition: Grid.h:204
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
Grid & operator=(const Grid &g)
Definition: Grid.h:129
Grid()
Definition: Grid.h:90
virtual ~Grid()
Definition: Grid.h:122
E ** grid
Definition: Grid.h:61
BracketHelper(Grid< E > &g, int r)
Definition: Grid.h:231
This BracketHelper is a helper class to get the [] operators to work. It is not intended to be used b...
Definition: Grid.h:227
Grid(const Grid &g)
Grid constructor given an input grid.
Definition: Grid.h:110
This is a class in BRIDGES for representing an (n x n) grid.
Definition: Grid.h:31
Grid(int *size)
Grid constructor given size.
Definition: Grid.h:100
Grid(int rows, int cols)
Grid constructor.
Definition: Grid.h:83
virtual const string getDStype() const override
Return the data structure type.
Definition: Grid.h:71
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
int gridSize[2]
Definition: Grid.h:63
BracketHelperConst(Grid< E > const &g, int r)
Definition: Grid.h:208
int const * getDimensions()
Get dimenions of the grid.
Definition: Grid.h:168
void setDimensions(int rows, int cols)
Construct the grid given the dimensions.
Definition: Grid.h:151
E const & get(int row, int col) const
Get the (row, col) element in the grid.
Definition: Grid.h:180