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