openMSX
MemoryBufferFile.cc
Go to the documentation of this file.
1 #include "MemoryBufferFile.hh"
2 #include "File.hh"
3 #include "FileException.hh"
4 #include <cstring>
5 #include <memory>
6 
7 namespace openmsx {
8 
9 void MemoryBufferFile::read(void* dst, size_t num)
10 {
11  if (getSize() < (getPos() + num)) {
12  throw FileException("Read beyond end of file");
13  }
14  memcpy(dst, buffer.data() + pos, num);
15  pos += num;
16 }
17 
18 void MemoryBufferFile::write(const void* /*src*/, size_t /*num*/)
19 {
20  throw FileException("Writing to MemoryBufferFile not supported");
21 }
22 
24 {
25  return buffer.size();
26 }
27 
28 void MemoryBufferFile::seek(size_t newPos)
29 {
30  pos = newPos;
31 }
32 
34 {
35  return pos;
36 }
37 
39 {
40  // nothing
41 }
42 
43 std::string MemoryBufferFile::getURL() const
44 {
45  return "";
46 }
47 
49 {
50  return true;
51 }
52 
54 {
55  return 0;
56 }
57 
58 
60 {
61  return File(std::make_unique<MemoryBufferFile>(buffer));
62 }
63 
64 } // namespace openmsx
bool isReadOnly() const override
void seek(size_t newPos) override
std::string getURL() const override
void read(void *dst, size_t num) override
void write(const void *src, size_t num) override
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
File memory_buffer_file(span< const uint8_t > buffer)
time_t getModificationDate() override