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
55 bool CheckRange(size_t j, size_t i) const
56 {
57 return j < H && i < W;
58 }
59 bool CheckRange(const SizeT& xy) const
60 {
61 return CheckRange(xy.y, xy.x);
62 }
63
67 void Fill(const T& v)
68 {
69 for (auto& iter : _data)
70 iter = v;
71 }
72
73 std::byte* GetBuffer()
74 {
75 return (std::byte*)_data.data();
76 }
77
79 {
80 return _data.data();
81 }
82
83 unsigned GetWidth()
84 {
85 return (unsigned)W;
86 }
87
88 unsigned GetHeight()
89 {
90 return (unsigned)H;
91 }
92
94 {
95 return { (unsigned)W, (unsigned)H };
96 }
97
98 size_t GetSizeByte()
99 {
100 return _data.size() * sizeof(T);
101 }
102
103 auto begin()
104 {
105 return _data.begin();
106 }
107 auto end()
108 {
109 return _data.end();
110 }
111private:
112 std::array<T, W * H> _data;
113};
114
115
116}
二维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()
bool CheckRange(size_t j, size_t i) const
bool CheckRange(const SizeT &xy) const
unsigned GetWidth()
const T * operator[](std::size_t j) const
返回第j行
Array< std::size_t, 2 > SizeT
< rgba
PointU Size