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
FileException.hh
openmsx::MemoryBufferFile::seek
void seek(size_t newPos) override
Definition: MemoryBufferFile.cc:28
openmsx::MemoryBufferFile::write
void write(const void *src, size_t num) override
Definition: MemoryBufferFile.cc:18
span< const uint8_t >
openmsx::MemoryBufferFile::getSize
size_t getSize() override
Definition: MemoryBufferFile.cc:23
openmsx::MemoryBufferFile::flush
void flush() override
Definition: MemoryBufferFile.cc:38
span::data
constexpr pointer data() const noexcept
Definition: span.hh:323
openmsx::MemoryBufferFile::getURL
std::string getURL() const override
Definition: MemoryBufferFile.cc:43
openmsx::MemoryBufferFile::getPos
size_t getPos() override
Definition: MemoryBufferFile.cc:33
File.hh
openmsx::FileException
Definition: FileException.hh:9
MemoryBufferFile.hh
span::size
constexpr index_type size() const noexcept
Definition: span.hh:296
openmsx::File
Definition: File.hh:16
openmsx::MemoryBufferFile::getModificationDate
time_t getModificationDate() override
Definition: MemoryBufferFile.cc:53
openmsx::memory_buffer_file
File memory_buffer_file(span< const uint8_t > buffer)
Definition: MemoryBufferFile.cc:59
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MemoryBufferFile::isReadOnly
bool isReadOnly() const override
Definition: MemoryBufferFile.cc:48
openmsx::MemoryBufferFile::read
void read(void *dst, size_t num) override
Definition: MemoryBufferFile.cc:9