diff options
| author | Stefan Boberg <[email protected]> | 2021-05-24 14:27:43 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-24 14:27:43 +0200 |
| commit | 591e6e9fc8a63e4de44577cf972dc54eab40547a (patch) | |
| tree | b3213ad130ae94ef14f0871fc3d4e858750d0486 /zencore/include | |
| parent | Moved CRC32 compute into separate cpp/h to enable usage outside of the retro ... (diff) | |
| download | zen-591e6e9fc8a63e4de44577cf972dc54eab40547a.tar.xz zen-591e6e9fc8a63e4de44577cf972dc54eab40547a.zip | |
Added functions to allow constructing memory views from a pointer range
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/memory.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/zencore/include/zencore/memory.h b/zencore/include/zencore/memory.h index 1c681872b..ec945c07c 100644 --- a/zencore/include/zencore/memory.h +++ b/zencore/include/zencore/memory.h @@ -72,6 +72,12 @@ struct MutableMemoryView { } + MutableMemoryView(void* DataPtr, void* DataEndPtr) + : m_Data(reinterpret_cast<uint8_t*>(DataPtr)) + , m_DataEnd(reinterpret_cast<uint8_t*>(DataEndPtr)) + { + } + inline bool IsEmpty() const { return m_Data == m_DataEnd; } void* GetData() const { return m_Data; } void* GetDataEnd() const { return m_DataEnd; } @@ -144,6 +150,8 @@ private: inline constexpr uint8_t* GetDataAtOffsetNoCheck(uint64_t InOffset) const { return m_Data + InOffset; } }; +////////////////////////////////////////////////////////////////////////// + struct MemoryView { MemoryView() = default; @@ -318,8 +326,16 @@ MakeMemoryView(const R& Container) return MemoryView(Span.data(), Span.size() * sizeof(decltype(Span)::element_type)); } +/** Make a non-owning const view starting at Data and ending at DataEnd. */ + +[[nodiscard]] inline MemoryView +MakeMemoryView(const void* Data, const void* DataEnd) +{ + return MemoryView(Data, DataEnd); +} + /** - * Make a non-owning view of the memory of the initializer list. + * Make a non-owning mutable view of the memory of the initializer list. * * This overload is only available when the element type does not need to be deduced. */ @@ -330,7 +346,7 @@ MakeMutableMemoryView(std::initializer_list<typename std::type_identity<T>::type return MutableMemoryView(List.begin(), List.size() * sizeof(T)); } -/** Make a non-owning view of the memory of the contiguous container. */ +/** Make a non-owning mutable view of the memory of the contiguous container. */ template<std::ranges::contiguous_range R> [[nodiscard]] constexpr inline MutableMemoryView MakeMutableMemoryView(R& Container) @@ -339,6 +355,14 @@ MakeMutableMemoryView(R& Container) return MutableMemoryView(Span.data(), Span.size() * sizeof(decltype(Span)::element_type)); } +/** Make a non-owning mutable view starting at Data and ending at DataEnd. */ + +[[nodiscard]] inline MutableMemoryView +MakeMutableMemoryView(void* Data, void* DataEnd) +{ + return MutableMemoryView(Data, DataEnd); +} + void memory_forcelink(); // internal } // namespace zen |