dl
dl_array2.h
浏览该文件的文档.
1
15#pragma once
16
17
18namespace dl
19{
21template<typename T, size_t W, size_t H>
22class Array2
23{
24public:
28 T* operator[](std::size_t j)
29 {
30 assert(j < H);
31 return &_data[j * W];
32 }
33
36 const T* operator[](std::size_t j) const
37 {
38 assert(j < H);
39 return &_data[j * W];
40 }
41
42 const T& Get(size_t j, size_t i) const
43 {
44 assert(j < H);
45 assert(i < W);
46 return _data[j * W + i];
47 }
48 T& GetRef(size_t j, size_t i)
49 {
50 assert(j < H);
51 assert(i < W);
52 return _data[j * W + i];
53 }
54
58 void Fill(const T& v)
59 {
60 for (auto& iter : _data)
61 iter = v;
62 }
63
64 std::byte* GetBuffer()
65 {
66 return (std::byte*)_data.data();
67 }
68
70 {
71 return _data.data();
72 }
73
74 unsigned GetWidth()
75 {
76 return (unsigned)W;
77 }
78
79 unsigned GetHeight()
80 {
81 return (unsigned)H;
82 }
83
85 {
86 return { (unsigned)W, (unsigned)H };
87 }
88
89 size_t GetSizeByte()
90 {
91 return _data.size() * sizeof(T);
92 }
93
94 auto begin()
95 {
96 return _data.begin();
97 }
98 auto end()
99 {
100 return _data.end();
101 }
102private:
103 std::array<T, W * H> _data;
104};
105
106
107}
二维array
T & GetRef(size_t j, size_t i)
void Fill(const T &v)
填充值
const T & Get(size_t j, size_t i) const
unsigned GetHeight()
size_t GetSizeByte()
T * operator[](std::size_t j)
返回第j行
std::byte * GetBuffer()
unsigned GetWidth()
const T * operator[](std::size_t j) const
返回第j行
PointU Size