aboutsummaryrefslogtreecommitdiff
path: root/src/data_cell_buffer.h
blob: 06c2644da05bcf37bdce11b29d2044a1bb9782cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include <memory>

#include "data_cell.h"

class DataCellBuffer {
	private:
		const std::size_t dim_x_;
		const std::size_t dim_y_;

		std::unique_ptr<DataCell[]> curr_;
		std::unique_ptr<DataCell[]> prev_;

	public:
		DataCellBuffer(std::size_t dimX, std::size_t dimY):
			dim_x_(dimX),
			dim_y_(dimY),
			curr_(new DataCell[dimX*dimY]),
			prev_(new DataCell[dimX*dimY]) { }

		std::size_t dimX() const {
			return dim_x_;
		}

		std::size_t dimY() const {
			return dim_y_;
		}

		void swap() {
			curr_.swap(prev_);
		}

		inline DataCell& curr(std::size_t x, std::size_t y) {
			return curr_[y*dim_x_ + x];
		}

		inline DataCell& curr(Vector<std::size_t> pos) {
			return curr(pos[0], pos[1]);
		}

		inline DataCell& prev(std::size_t x, std::size_t y) {
			return prev_[y*dim_x_ + x];
		}

		inline DataCell& prev(Vector<std::size_t> pos) {
			return prev(pos[0], pos[1]);
		}
};