-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.h
72 lines (62 loc) · 1.54 KB
/
buffer.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <vector>
namespace hidden {
template <typename base_t>
using buf_1d = std::vector<base_t>;
template <typename base_t>
using buf_2d = std::vector<buf_1d<base_t>>;
template <typename base_t>
using buf_3d = std::vector<buf_2d<base_t>>;
};
//! simple 2d array
template <typename base_t>
class buffer2d {
private:
hidden::buf_2d<base_t> _buf;
public:
buffer2d() = default;
buffer2d(size_t x, size_t y)
: _buf(x, hidden::buf_1d<base_t>(y))
{}
buffer2d(size_t x, size_t y, base_t val)
: _buf(x, hidden::buf_1d<base_t>(y, val))
{}
void clear() {
_buf.clear();
}
hidden::buf_1d<base_t> &operator[](size_t i) {
return _buf[i];
}
const hidden::buf_1d<base_t> &operator[](size_t i) const {
return _buf[i];
}
};
//! simple 3d array
template <typename base_t>
class buffer3d {
private:
hidden::buf_3d<base_t> _buf;
public:
buffer3d() = default;
buffer3d(size_t x, size_t y, size_t z)
: _buf(x,
hidden::buf_2d<base_t>(y,
hidden::buf_1d<base_t>(z))
)
{}
buffer3d(size_t x, size_t y, size_t z, base_t val)
: _buf(x,
hidden::buf_2d<base_t>(y,
hidden::buf_1d<base_t>(z, val))
)
{}
void clear() {
_buf.clear();
}
hidden::buf_2d<base_t> &operator[](size_t i) {
return _buf[i];
}
const hidden::buf_2d<base_t> &operator[](size_t i) const {
return _buf[i];
}
};