From 73979c2fdece03ed2873be81a8f4eecbd888b540 Mon Sep 17 00:00:00 2001 From: lveyou <1339484752@qq.com> Date: Fri, 14 Jul 2023 18:49:19 +0800 Subject: [PATCH] =?UTF-8?q?*=E6=B7=BB=E5=8A=A0array2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/base/dl_array2.h | 76 +++++++++++++++++++++++++++++++++++++++++++++ dl/dl_platform.h | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 dl/base/dl_array2.h diff --git a/dl/base/dl_array2.h b/dl/base/dl_array2.h new file mode 100644 index 00000000..84103685 --- /dev/null +++ b/dl/base/dl_array2.h @@ -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 +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 _data; + std::array _ptrRow; +}; + + +} \ No newline at end of file diff --git a/dl/dl_platform.h b/dl/dl_platform.h index a15c9fc9..17481956 100644 --- a/dl/dl_platform.h +++ b/dl/dl_platform.h @@ -34,7 +34,7 @@ consteval bool is_x64() return sizeof(void*) == 8; } -//! 是否小端 +//! 字节序是否小端 consteval bool is_little_endian() { union