openMSX
LocalFile.hh
Go to the documentation of this file.
1#ifndef LOCALFILE_HH
2#define LOCALFILE_HH
3
4#if defined _WIN32
5#include <windows.h>
6#endif
7#include "File.hh"
8#include "FileBase.hh"
9#include "FileOperations.hh"
10#include "PreCacheFile.hh"
11#include "systemfuncs.hh"
12#include <cstdio>
13#include <optional>
14
15namespace openmsx {
16
17class LocalFile final : public FileBase
18{
19public:
20 LocalFile(std::string filename, File::OpenMode mode);
21 LocalFile(std::string filename, const char* mode);
22 ~LocalFile() override;
23 void read(std::span<uint8_t> buffer) override;
24 void write(std::span<const uint8_t> buffer) override;
25#if HAVE_MMAP || defined _WIN32
26 [[nodiscard]] std::span<const uint8_t> mmap() override;
27 void munmap() override;
28#endif
29 [[nodiscard]] size_t getSize() override;
30 void seek(size_t pos) override;
31 [[nodiscard]] size_t getPos() override;
32#if HAVE_FTRUNCATE
33 void truncate(size_t size) override;
34#endif
35 void flush() override;
36 [[nodiscard]] const std::string& getURL() const override;
37 [[nodiscard]] std::string getLocalReference() override;
38 [[nodiscard]] bool isReadOnly() const override;
39 [[nodiscard]] time_t getModificationDate() override;
40
41 void preCacheFile();
42
43private:
44 std::string filename;
46#if HAVE_MMAP
47 uint8_t* mmem = nullptr;
48#endif
49#if defined _WIN32
50 uint8_t* mmem = nullptr;
51 HANDLE hMmap = nullptr;
52#endif
53 std::optional<PreCacheFile> cache;
54 bool readOnly = false;
55};
56
57} // namespace openmsx
58
59#endif
virtual std::span< const uint8_t > mmap()
Definition FileBase.cc:9
virtual void truncate(size_t size)
Definition FileBase.cc:30
virtual void munmap()
Definition FileBase.cc:25
time_t getModificationDate() override
Definition LocalFile.cc:271
void write(std::span< const uint8_t > buffer) override
Definition LocalFile.cc:103
void read(std::span< uint8_t > buffer) override
Definition LocalFile.cc:91
void seek(size_t pos) override
Definition LocalFile.cc:224
~LocalFile() override
Definition LocalFile.cc:81
bool isReadOnly() const override
Definition LocalFile.cc:266
std::string getLocalReference() override
Definition LocalFile.cc:261
size_t getPos() override
Definition LocalFile.cc:236
void flush() override
Definition LocalFile.cc:251
const std::string & getURL() const override
Definition LocalFile.cc:256
size_t getSize() override
Definition LocalFile.cc:201
std::unique_ptr< FILE, FClose > FILE_t
This file implemented 3 utility functions:
Definition Autofire.cc:11