Page MenuHomec4science

grid.hh
No OneTemporary

File Metadata

Created
Sat, May 11, 22:27
#include <cstddef>
#ifndef GRID_H
#define GRID_H
class Grid {
typedef char T;
public:
Grid(std::size_t m, std::size_t n, std::size_t ghosts)
: _dims{m, n}, _offsets{0, 0}, _ghosts(ghosts),
_grid(new T[(m + 2 * _ghosts) * (n + 2 * _ghosts)]) {}
Grid(const Grid &other)
: _dims{other._dims[0], other._dims[1]},
_offsets{other._offsets[0], other._offsets[1]}, _ghosts(other._ghosts),
_grid(new T[(_dims[0] + 2 * _ghosts) * (_dims[1] + 2 * _ghosts)]) {}
~Grid() { delete[] _grid; }
T &operator()(std::size_t i, std::size_t j) {
return *(_grid + (i + _ghosts) * _dims[1] + (j + _ghosts));
}
void swap(Grid &other) {
T *tmp = _grid;
_grid = other._grid;
other._grid = tmp;
}
void setOffsets(std::size_t offsets[2]) {
_offsets[0] = offsets[0];
_offsets[1] = offsets[1];
}
std::size_t size(std::size_t i) const { return _dims[i]; }
std::size_t size() const { return _dims[0] * _dims[1]; }
std::size_t fullSize(std::size_t i) const { return (_dims[i]+2*_ghosts); }
std::size_t fullSize() const { return (_dims[0]+2*_ghosts) * (_dims[1]+2*_ghosts); }
std::size_t offset(std::size_t i) const { return _offsets[i]; }
std::size_t ghost() const { return _ghosts; }
const T * data() const { return _grid; }
private:
std::size_t _dims[2];
std::size_t _offsets[2];
std::size_t _ghosts;
T *_grid;
};
#endif /* GRID_H */

Event Timeline