*添加array2
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @file dl_array2.h
|
||||
* @brief 2维array
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
* @author lveyou
|
||||
* @date 23-07-09
|
||||
*
|
||||
* @note 提供行指针,避免乘法计算
|
||||
* @note 设计为深拷贝,与std::array一致
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace dl
|
||||
{
|
||||
|
||||
template<typename T, size_t W, size_t H>
|
||||
class Array2
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief 填充值
|
||||
*/
|
||||
void Fill(const T& v)
|
||||
{
|
||||
for (auto& iter : _data)
|
||||
iter = v;
|
||||
}
|
||||
|
||||
std::byte* GetBuffer()
|
||||
{
|
||||
return (std::byte*)_data.data();
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
return _data.data();
|
||||
}
|
||||
|
||||
unsigned GetWidth()
|
||||
{
|
||||
return (unsigned)W;
|
||||
}
|
||||
|
||||
unsigned GetHeight()
|
||||
{
|
||||
return (unsigned)H;
|
||||
}
|
||||
|
||||
Size GetSize()
|
||||
{
|
||||
return { (unsigned)W, (unsigned)H };
|
||||
}
|
||||
|
||||
size_t GetSizeByte()
|
||||
{
|
||||
return _data.size() * sizeof(T);
|
||||
}
|
||||
|
||||
auto begin()
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
auto end()
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
private:
|
||||
std::array<T, W * H> _data;
|
||||
std::array<T*, H> _ptrRow;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ consteval bool is_x64()
|
||||
return sizeof(void*) == 8;
|
||||
}
|
||||
|
||||
//! 是否小端
|
||||
//! 字节序是否小端
|
||||
consteval bool is_little_endian()
|
||||
{
|
||||
union
|
||||
|
||||
Reference in New Issue
Block a user