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
openmsx::LocalFile::write
void write(const void *buffer, size_t num) override
Definition: LocalFile.cc:118
openmsx::FileOperations::FILE_t
std::unique_ptr< FILE, FClose > FILE_t
Definition: FileOperations.hh:16
openmsx::LocalFile::getPos
size_t getPos() override
Definition: LocalFile.cc:251
openmsx::LocalFile::truncate
void truncate(size_t size) override
Definition: LocalFile.cc:257
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::LocalFile::seek
void seek(size_t pos) override
Definition: LocalFile.cc:239
FileBase.hh
openmsx::LocalFile::getURL
std::string getURL() const override
Definition: LocalFile.cc:271
openmsx::LocalFile::isReadOnly
bool isReadOnly() const override
Definition: LocalFile.cc:281
systemfuncs.hh
span
Definition: span.hh:126
openmsx::LocalFile::flush
void flush() override
Definition: LocalFile.cc:266
File.hh
openmsx::LocalFile
Definition: LocalFile.hh:19
openmsx::LocalFile::LocalFile
LocalFile(std::string_view filename, File::OpenMode mode)
Definition: LocalFile.cc:26
openmsx::LocalFile::mmap
span< uint8_t > mmap() override
Definition: LocalFile.cc:183
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::LocalFile::getSize
size_t getSize() override
Definition: LocalFile.cc:216
openmsx::LocalFile::~LocalFile
~LocalFile() override
Definition: LocalFile.cc:95
openmsx::LocalFile::read
void read(void *buffer, size_t num) override
Definition: LocalFile.cc:106
openmsx::LocalFile::munmap
void munmap() override
Definition: LocalFile.cc:202
FileOperations.hh
openmsx::LocalFile::getModificationDate
time_t getModificationDate() override
Definition: LocalFile.cc:286
openmsx::LocalFile::getLocalReference
std::string getLocalReference() override
Definition: LocalFile.cc:276
openmsx::File::OpenMode
OpenMode
Definition: File.hh:18
openmsx::FileBase
Definition: FileBase.hh:12
openmsx::LocalFile::preCacheFile
void preCacheFile()
Definition: LocalFile.cc:100
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5