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 
15 namespace openmsx {
16 
17 class LocalFile final : public FileBase
18 {
19 public:
20  LocalFile(std::string filename, File::OpenMode mode);
21  LocalFile(std::string filename, const char* mode);
22  ~LocalFile() override;
23  void read (void* buffer, size_t num) override;
24  void write(const void* buffer, size_t num) override;
25 #if HAVE_MMAP || defined _WIN32
26  [[nodiscard]] 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 
43 private:
44  std::string filename;
46 #if HAVE_MMAP
47  uint8_t* mmem;
48 #endif
49 #if defined _WIN32
50  uint8_t* mmem;
51  HANDLE hMmap;
52 #endif
53  std::optional<PreCacheFile> cache;
54  bool readOnly;
55 };
56 
57 } // namespace openmsx
58 
59 #endif
time_t getModificationDate() override
Definition: LocalFile.cc:282
void seek(size_t pos) override
Definition: LocalFile.cc:235
~LocalFile() override
Definition: LocalFile.cc:92
void munmap() override
Definition: LocalFile.cc:198
span< const uint8_t > mmap() override
Definition: LocalFile.cc:179
bool isReadOnly() const override
Definition: LocalFile.cc:277
LocalFile(std::string filename, File::OpenMode mode)
Definition: LocalFile.cc:23
void truncate(size_t size) override
Definition: LocalFile.cc:253
std::string getLocalReference() override
Definition: LocalFile.cc:272
void read(void *buffer, size_t num) override
Definition: LocalFile.cc:102
size_t getPos() override
Definition: LocalFile.cc:247
void flush() override
Definition: LocalFile.cc:262
const std::string & getURL() const override
Definition: LocalFile.cc:267
void write(const void *buffer, size_t num) override
Definition: LocalFile.cc:114
size_t getSize() override
Definition: LocalFile.cc:212
std::unique_ptr< FILE, FClose > FILE_t
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
size_t size(std::string_view utf8)