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};
78 setDimensions(rows, cols);
87 :
Grid(size[0], size[1]) {
91 :
Grid(g.gridSize[0], g.gridSize[1]) {
92 for (
int i = 0; i < gridSize[0]; i++) {
93 for (
int j = 0; j < gridSize[1]; j++) {
94 set (i, j, g.
get(i, j));
104 if (this->gridSize[0] != g.
gridSize[0] ||
105 this->gridSize[1] != g.
gridSize[1] ) {
109 for (
int i = 0; i < gridSize[0]; i++) {
110 for (
int j = 0; j < gridSize[1]; j++) {
111 set (i, j, g.
get(i, j));
122 if (rows > maxGridSize[0] || cols > maxGridSize[1]) {
123 cerr <<
"Grid Maximum Size (1080 x 1920) exceeded!\n" 124 <<
"Provided Size: " << rows <<
" x " << cols
125 <<
". Aborting" << endl << endl;
138 E
const&
get(
int row,
int col)
const {
139 checkRowCol(row, col);
141 return grid[row][col];
144 void set(
int row,
int col, E val) {
145 checkRowCol(row, col);
147 grid[row][col] = val;
160 E
const & operator[] (
int col)
const {
161 return gr.
get(row, col);
166 BracketHelperConst operator[] (
int row)
const {
167 return BracketHelperConst(*
this, row);
180 E & operator[] (
int col) {
181 gr.checkRowCol(row, col);
182 return gr.
grid[row][col];
187 BracketHelper operator[] (
int row) {
188 return BracketHelper(*
this, row);
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
Grid & operator=(const Grid &g)
Definition: Grid.h:103
Grid()
Definition: Grid.h:81
virtual ~Grid()
Definition: Grid.h:99
E ** grid
Definition: Grid.h:61
BracketHelper(Grid< E > &g, int r)
Definition: Grid.h:176
Grid(const Grid &g)
Definition: Grid.h:90
This is a class in BRIDGES for representing an (n x n) grid.
Definition: Grid.h:31
Grid(int *size)
Definition: Grid.h:86
Grid(int rows, int cols)
Definition: Grid.h:77
virtual const string getDStype() const override
Definition: Grid.h:67
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:156
int const * getDimensions()
Definition: Grid.h:131
void setDimensions(int rows, int cols)
Definition: Grid.h:119
E const & get(int row, int col) const
Definition: Grid.h:138