openMSX
IPSPatch.hh
Go to the documentation of this file.
1 #ifndef IPSPATCH_HH
2 #define IPSPATCH_HH
3 
4 #include "PatchInterface.hh"
5 #include "Filename.hh"
6 #include <vector>
7 #include <memory>
8 
9 namespace openmsx {
10 
11 class IPSPatch final : public PatchInterface
12 {
13 public:
14  IPSPatch(Filename filename,
15  std::unique_ptr<const PatchInterface> parent);
16 
17  void copyBlock(size_t src, byte* dst, size_t num) const override;
18  [[nodiscard]] size_t getSize() const override { return size; }
19  [[nodiscard]] std::vector<Filename> getFilenames() const override;
20 
21 private:
22  struct Chunk {
23  size_t startAddress;
24  std::vector<byte> content;
25 
26  [[nodiscard]] size_t size() const { return content.size(); }
27  [[nodiscard]] const byte* data() const { return content.data(); }
28  [[nodiscard]] size_t stopAddress() const { return startAddress + size(); }
29  };
30 
31  const Filename filename;
32  const std::unique_ptr<const PatchInterface> parent;
33  const std::vector<Chunk> chunks; // sorted on startAddress
34  const size_t size;
35 
36 private:
37  // Helper functions called from constructor
38  [[nodiscard]] std::vector<Chunk> parseChunks() const;
39  [[nodiscard]] size_t calcSize() const;
40 };
41 
42 } // namespace openmsx
43 
44 #endif
This class represents a filename.
Definition: Filename.hh:18
IPSPatch(Filename filename, std::unique_ptr< const PatchInterface > parent)
Definition: IPSPatch.cc:78
size_t getSize() const override
Definition: IPSPatch.hh:18
std::vector< Filename > getFilenames() const override
Definition: IPSPatch.cc:128
void copyBlock(size_t src, byte *dst, size_t num) const override
Definition: IPSPatch.cc:87
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
size_t size(std::string_view utf8)