openMSX
CompressedFileAdapter.hh
Go to the documentation of this file.
1 #ifndef COMPRESSEDFILEADAPTER_HH
2 #define COMPRESSEDFILEADAPTER_HH
3 
4 #include "FileBase.hh"
5 #include "MemBuffer.hh"
6 #include <memory>
7 
8 namespace openmsx {
9 
11 {
12 public:
13  struct Decompressed {
15  size_t size;
16  std::string originalName;
17  std::string cachedURL;
19  };
20 
21  void read(void* buffer, size_t num) final override;
22  void write(const void* buffer, size_t num) final override;
23  span<uint8_t> mmap() final override;
24  void munmap() final override;
25  size_t getSize() final override;
26  void seek(size_t pos) final override;
27  size_t getPos() final override;
28  void truncate(size_t size) final override;
29  void flush() final override;
30  std::string getURL() const final override;
31  std::string getOriginalName() final override;
32  bool isReadOnly() const final override;
33  time_t getModificationDate() final override;
34 
35 protected:
36  explicit CompressedFileAdapter(std::unique_ptr<FileBase> file);
37  ~CompressedFileAdapter() override;
38  virtual void decompress(FileBase& file, Decompressed& decompressed) = 0;
39 
40 private:
41  void decompress();
42 
43  std::unique_ptr<FileBase> file;
44  std::shared_ptr<Decompressed> decompressed;
45  size_t pos;
46 };
47 
48 } // namespace openmsx
49 
50 #endif
openmsx::CompressedFileAdapter::Decompressed::size
size_t size
Definition: CompressedFileAdapter.hh:15
openmsx::CompressedFileAdapter::Decompressed::originalName
std::string originalName
Definition: CompressedFileAdapter.hh:16
openmsx::CompressedFileAdapter::Decompressed::cachedURL
std::string cachedURL
Definition: CompressedFileAdapter.hh:17
openmsx::CompressedFileAdapter::seek
void seek(size_t pos) final override
Definition: CompressedFileAdapter.cc:87
openmsx::CompressedFileAdapter::isReadOnly
bool isReadOnly() const final override
Definition: CompressedFileAdapter.cc:118
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::CompressedFileAdapter::mmap
span< uint8_t > mmap() final override
Definition: CompressedFileAdapter.cc:70
FileBase.hh
openmsx::CompressedFileAdapter::Decompressed::buf
MemBuffer< uint8_t > buf
Definition: CompressedFileAdapter.hh:14
span
Definition: span.hh:126
openmsx::CompressedFileAdapter::getPos
size_t getPos() final override
Definition: CompressedFileAdapter.cc:92
openmsx::MemBuffer< uint8_t >
openmsx::CompressedFileAdapter::truncate
void truncate(size_t size) final override
Definition: CompressedFileAdapter.cc:97
openmsx::CompressedFileAdapter::Decompressed
Definition: CompressedFileAdapter.hh:13
openmsx::CompressedFileAdapter::Decompressed::cachedModificationDate
time_t cachedModificationDate
Definition: CompressedFileAdapter.hh:18
openmsx::CompressedFileAdapter
Definition: CompressedFileAdapter.hh:11
MemBuffer.hh
openmsx::CompressedFileAdapter::getSize
size_t getSize() final override
Definition: CompressedFileAdapter.cc:81
openmsx::CompressedFileAdapter::munmap
void munmap() final override
Definition: CompressedFileAdapter.cc:76
openmsx::CompressedFileAdapter::write
void write(const void *buffer, size_t num) final override
Definition: CompressedFileAdapter.cc:65
openmsx::CompressedFileAdapter::getOriginalName
std::string getOriginalName() final override
Definition: CompressedFileAdapter.cc:112
openmsx::FileBase
Definition: FileBase.hh:12
openmsx::CompressedFileAdapter::getURL
std::string getURL() const final override
Definition: CompressedFileAdapter.cc:107
openmsx::CompressedFileAdapter::getModificationDate
time_t getModificationDate() final override
Definition: CompressedFileAdapter.cc:123
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::CompressedFileAdapter::read
void read(void *buffer, size_t num) final override
Definition: CompressedFileAdapter.cc:54
openmsx::CompressedFileAdapter::flush
void flush() final override
Definition: CompressedFileAdapter.cc:102