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 const std::string& MemoryBufferFile::getURL() const
44 {
45  static const std::string EMPTY;
46  return EMPTY;
47 }
48 
50 {
51  return true;
52 }
53 
55 {
56  return 0;
57 }
58 
59 
61 {
62  return File(std::make_unique<MemoryBufferFile>(buffer));
63 }
64 
65 } // namespace openmsx
const std::string & getURL() const override
time_t getModificationDate() override
bool isReadOnly() const override
void write(const void *src, size_t num) override
void read(void *dst, size_t num) override
void seek(size_t newPos) override
constexpr pointer data() const noexcept
Definition: span.hh:323
constexpr index_type size() const noexcept
Definition: span.hh:296
This file implemented 3 utility functions:
Definition: Autofire.cc:9
File memory_buffer_file(span< const uint8_t > buffer)