openMSX
MemoryBufferFile.cc
Go to the documentation of this file.
1#include "MemoryBufferFile.hh"
2#include "File.hh"
3#include "FileException.hh"
4#include "ranges.hh"
5#include <memory>
6
7namespace openmsx {
8
9void MemoryBufferFile::read(std::span<uint8_t> dst)
10{
11 if (getSize() < (getPos() + dst.size())) {
12 throw FileException("Read beyond end of file");
13 }
14 ranges::copy(buffer.subspan(pos, dst.size()), dst);
15 pos += dst.size();
16}
17
18void MemoryBufferFile::write(std::span<const uint8_t> /*src*/)
19{
20 throw FileException("Writing to MemoryBufferFile not supported");
21}
22
24{
25 return buffer.size();
26}
27
28void MemoryBufferFile::seek(size_t newPos)
29{
30 pos = newPos;
31}
32
34{
35 return pos;
36}
37
39{
40 // nothing
41}
42
43const 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
60File memory_buffer_file(std::span<const uint8_t> buffer)
61{
62 return File(std::make_unique<MemoryBufferFile>(buffer));
63}
64
65} // namespace openmsx
const std::string & getURL() const override
void write(std::span< const uint8_t > src) override
time_t getModificationDate() override
bool isReadOnly() const override
void read(std::span< uint8_t > dst) override
void seek(size_t newPos) override
This file implemented 3 utility functions:
Definition Autofire.cc:11
File memory_buffer_file(std::span< const uint8_t > buffer)
auto copy(InputRange &&range, OutputIter out)
Definition ranges.hh:250