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
8namespace openmsx {
9
11{
12public:
13 struct Decompressed {
15 std::string originalName;
16 std::string cachedURL;
18 unsigned useCount = 0;
19 };
20
21 void read(std::span<uint8_t> buffer) final;
22 void write(std::span<const uint8_t> buffer) final;
23 [[nodiscard]] std::span<const uint8_t> mmap() final;
24 void munmap() final;
25 [[nodiscard]] size_t getSize() final;
26 void seek(size_t pos) final;
27 [[nodiscard]] size_t getPos() final;
28 void truncate(size_t size) final;
29 void flush() final;
30 [[nodiscard]] const std::string& getURL() const final;
31 [[nodiscard]] std::string_view getOriginalName() final;
32 [[nodiscard]] bool isReadOnly() const final;
33 [[nodiscard]] time_t getModificationDate() final;
34
35protected:
36 explicit CompressedFileAdapter(std::unique_ptr<FileBase> file);
37 ~CompressedFileAdapter() override;
38 virtual void decompress(FileBase& file, Decompressed& decompressed) = 0;
39
40private:
41 void decompress();
42
43private:
44 // invariant: exactly one of 'file' and 'decompressed' is '!= nullptr'
45 std::unique_ptr<FileBase> file;
46 const Decompressed* decompressed = nullptr;
47 size_t pos = 0;
48};
49
50} // namespace openmsx
51
52#endif
void read(std::span< uint8_t > buffer) final
std::string_view getOriginalName() final
std::span< const uint8_t > mmap() final
void write(std::span< const uint8_t > buffer) final
const std::string & getURL() const final
This class manages the lifetime of a block of memory.
Definition MemBuffer.hh:32
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.