PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
memory_mapped_file.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
16#pragma once
17
18#include "result.h"
19
20#include <cstdint>
21#include <filesystem>
22#include <span>
23
24namespace kcenon::pacs::core {
25
43public:
49 [[nodiscard]] static auto open(const std::filesystem::path& path)
51
56 [[nodiscard]] auto data() const noexcept -> const std::uint8_t*;
57
62 [[nodiscard]] auto size() const noexcept -> std::size_t;
63
68 [[nodiscard]] auto as_span() const noexcept -> std::span<const std::uint8_t>;
69
70 // Move-only
73
74 memory_mapped_file(memory_mapped_file&& other) noexcept;
75 auto operator=(memory_mapped_file&& other) noexcept -> memory_mapped_file&;
76
78
79private:
80 memory_mapped_file() = default;
81
82 void unmap() noexcept;
83
84 const std::uint8_t* data_ = nullptr;
85 std::size_t size_ = 0;
86
87#if defined(_WIN32)
88 void* file_handle_ = nullptr;
89 void* mapping_handle_ = nullptr;
90#else
91 int fd_ = -1;
92#endif
93};
94
95} // namespace kcenon::pacs::core
static auto open(const std::filesystem::path &path) -> kcenon::pacs::Result< memory_mapped_file >
Open and memory-map a file for reading.
auto as_span() const noexcept -> std::span< const std::uint8_t >
Get a span over the mapped data.
memory_mapped_file(const memory_mapped_file &)=delete
auto size() const noexcept -> std::size_t
Get the size of the mapped file.
auto operator=(const memory_mapped_file &) -> memory_mapped_file &=delete
auto data() const noexcept -> const std::uint8_t *
Get pointer to the mapped data.
Result<T> type aliases and helpers for PACS system.