Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
MemoryMappedFileReader.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_IO_FileSystem_MemoryMappedFileReader_h_
5#define _Stroika_Foundation_IO_FileSystem_MemoryMappedFileReader_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#if qStroika_Foundation_Common_Platform_Windows
10#include <Windows.h>
11#endif
12
13#include <filesystem>
14
15#include "Stroika/Foundation/IO/FileSystem/Common.h"
16
17/**
18 * TODO:
19 * @todo Add API variant that allows multiple sub-regions of a file to be mapped.
20 *
21 * @todo Add API controlling if mapping is readonly or read/write
22 *
23 * @todo Consider adding a writable MemoryMappedFileReader variant
24 */
25
27
28 /**
29 * MemoryMappedFileReader is a utility to allow memory mapping of a file.
30 *
31 * \note - this code doesn't facilitiate create a BLOB from this class, because doing so well requires application specific info
32 * about lifetimes. You can use Memory::BLOB::Adopt (mf.AsSpan<> ()) - but BEWARE - user doing so MUST make sure lifetime
33 * of MemoryMappedFileReader >= that of the produced BLOB (or any derivatives - its shared_rep).
34 */
36 public:
37 MemoryMappedFileReader (const filesystem::path& fileName);
40
41 public:
42 nonvirtual MemoryMappedFileReader& operator= (const MemoryMappedFileReader&) = delete;
43
44 public:
45 /**
46 */
47 nonvirtual const byte* begin () const;
48
49 public:
50 /**
51 */
52 nonvirtual const byte* end () const;
53
54 public:
55 /**
56 */
57 nonvirtual size_t size () const;
58
59 public:
60 nonvirtual span<const byte> AsSpan () const;
61
62 public:
63 nonvirtual span<const byte> operator() () const;
64
65 private:
66 span<const byte> fSpan_;
67#if qStroika_Foundation_Common_Platform_Windows
68 HANDLE fFileHandle_{INVALID_HANDLE_VALUE};
69 HANDLE fFileMapping_{INVALID_HANDLE_VALUE};
70#endif
71 };
72
73}
74
75/*
76 ********************************************************************************
77 ***************************** Implementation Details ***************************
78 ********************************************************************************
79 */
80#include "MemoryMappedFileReader.inl"
81
82#endif /*_Stroika_Foundation_IO_FileSystem_MemoryMappedFileReader_h_*/