12 namespace datastructure {
34 int rows = gridSize[0];
35 int cols = gridSize[1];
37 for (
int j = 0; j < rows; j++) {
38 grid[j] =
new E[cols];
42 void deallocateGrid() {
44 for (
int i = 0; i < gridSize[0]; i++) {
52 void checkRowCol(
int row,
int col)
const {
53 if (row < 0 || col < 0 || row >= gridSize[0] || col >= gridSize[1])
54 throw "invalid location in Grid";
62 int maxGridSize[2] = {1080, 1920};
82 setDimensions(rows, cols);
98 :
Grid(size[0], size[1]) {
108 :
Grid(g.gridSize[0], 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));
127 if (this->gridSize[0] != g.gridSize[0] ||
128 this->gridSize[1] != g.gridSize[1] ) {
130 setDimensions(g.gridSize[0], g.gridSize[1]);
132 for (
int i = 0; i < gridSize[0]; i++) {
133 for (
int j = 0; j < gridSize[1]; j++) {
134 set (i, j, g.get(i, j));
150 if (rows > maxGridSize[0] || cols > maxGridSize[1]) {
151 cerr <<
"Grid Maximum Size (1080 x 1920) exceeded!\n"
152 <<
"Provided Size: " << rows <<
" x " << cols
153 <<
". Aborting" << endl << endl;
174 E
const&
get(
int row,
int col)
const {
175 checkRowCol(row, col);
177 return grid[row][col];
186 void set(
int row,
int col, E val) {
187 checkRowCol(row, col);
189 grid[row][col] = val;
206 E
const & operator[] (
int col)
const {
207 return gr.
get(row, col);
229 E & operator[] (
int col) {
230 gr.checkRowCol(row, col);
231 return gr.
grid[row][col];
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:74
This BracketHelperConst is a helper class to get the [] operators to work.
Definition: Grid.h:198
BracketHelperConst(Grid< E > const &g, int r)
Definition: Grid.h:202
This BracketHelper is a helper class to get the [] operators to work. It is not intended to be used b...
Definition: Grid.h:221
BracketHelper(Grid< E > &g, int r)
Definition: Grid.h:225
This is a class in BRIDGES for representing an (n x n) grid.
Definition: Grid.h:30
virtual const string getDStype() const override
Return the data structure type.
Definition: Grid.h:69
E const & get(int row, int col) const
Get the (row, col) element in the grid.
Definition: Grid.h:174
void setDimensions(int rows, int cols)
Construct the grid given the dimensions.
Definition: Grid.h:147
Grid & operator=(const Grid &g)
Definition: Grid.h:126
Grid()
Definition: Grid.h:88
int const * getDimensions()
Get dimenions of the grid.
Definition: Grid.h:164
Grid(int rows, int cols)
Grid constructor.
Definition: Grid.h:81
virtual ~Grid()
Definition: Grid.h:119
E ** grid
Definition: Grid.h:59
void set(int row, int col, E val)
Set the grid value for the (row, col) element.
Definition: Grid.h:186
Grid(int *size)
Grid constructor given size.
Definition: Grid.h:97
Grid(const Grid &g)
Grid constructor given an input grid.
Definition: Grid.h:107
Support for drawing Bar charts.
Definition: alltypes.h:4