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 "systemfuncs.hh"
11 #include <cstdio>
12 #include <memory>
13 
14 namespace openmsx {
15 
16 class PreCacheFile;
17 
18 class LocalFile final : public FileBase
19 {
20 public:
21  LocalFile(std::string_view filename, File::OpenMode mode);
22  LocalFile(std::string_view filename, const char* mode);
23  ~LocalFile() override;
24  void read (void* buffer, size_t num) override;
25  void write(const void* buffer, size_t num) override;
26 #if HAVE_MMAP || defined _WIN32
27  span<uint8_t> mmap() override;
28  void munmap() override;
29 #endif
30  size_t getSize() override;
31  void seek(size_t pos) override;
32  size_t getPos() override;
33 #if HAVE_FTRUNCATE
34  void truncate(size_t size) override;
35 #endif
36  void flush() override;
37  std::string getURL() const override;
38  std::string getLocalReference() override;
39  bool isReadOnly() const override;
40  time_t getModificationDate() override;
41 
42  void preCacheFile();
43 
44 private:
45  std::string filename;
47 #if HAVE_MMAP
48  uint8_t* mmem;
49 #endif
50 #if defined _WIN32
51  uint8_t* mmem;
52  HANDLE hMmap;
53 #endif
54  std::unique_ptr<PreCacheFile> cache;
55  bool readOnly;
56 };
57 
58 } // namespace openmsx
59 
60 #endif
Definition: span.hh:34
void flush() override
Definition: LocalFile.cc:266
std::string getURL() const override
Definition: LocalFile.cc:271
size_t getPos() override
Definition: LocalFile.cc:251
size_t size(std::string_view utf8)
void truncate(size_t size) override
Definition: LocalFile.cc:257
void read(void *buffer, size_t num) override
Definition: LocalFile.cc:106
void munmap() override
Definition: LocalFile.cc:202
LocalFile(std::string_view filename, File::OpenMode mode)
Definition: LocalFile.cc:25
time_t getModificationDate() override
Definition: LocalFile.cc:286
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
size_t getSize() override
Definition: LocalFile.cc:216
bool isReadOnly() const override
Definition: LocalFile.cc:281
void write(const void *buffer, size_t num) override
Definition: LocalFile.cc:118
~LocalFile() override
Definition: LocalFile.cc:95
void seek(size_t pos) override
Definition: LocalFile.cc:239
span< uint8_t > mmap() override
Definition: LocalFile.cc:183
std::unique_ptr< FILE, FClose > FILE_t
std::string getLocalReference() override
Definition: LocalFile.cc:276