1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex4.2/CaloGrid.hh

43 lines
724 B
C++

//CaloGrid.hh
#include "CaloCell.hh"
#ifndef CALOGRID_HH
#define CALOGRID_HH
class CaloGrid
{
public:
CaloGrid( int nx, int ny ) {
init(nx, ny );
}
CaloGrid( const CaloGrid& other ) {
// Set everything using init to allocate memory
init(other.nx, other.ny ) ;
// Copy elements
// Because we make it a 1Dim array, we can simply run over all elements in one go
for (int i=0 ; i<nx*ny ; i++ ) {
cells[i] = other.cells[i] ;
}
}
~CaloGrid() {
delete[] cells;
}
CaloCell* cell(int x, int y);
private:
int nx, ny ;
CaloCell* cells ;
void init( int in_nx, int in_ny ) {
nx = in_nx ;
ny = in_ny ;
// contigious cells
cells = new CaloCell[ nx*ny ];
}
} ;
#endif