summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/file_sys/vfs_vector.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h
index 3e3f790c3..7ed5123d2 100644
--- a/src/core/file_sys/vfs_vector.h
+++ b/src/core/file_sys/vfs_vector.h
@@ -8,6 +8,58 @@
8 8
9namespace FileSys { 9namespace FileSys {
10 10
11// An implementation of VfsFile that is backed by a statically-sized array
12template <std::size_t size>
13class ArrayVfsFile : public VfsFile {
14public:
15 ArrayVfsFile(std::array<u8, size> data, std::string name = "", VirtualDir parent = nullptr)
16 : data(std::move(data)), name(std::move(name)), parent(std::move(parent)) {}
17
18 std::string GetName() const override {
19 return name;
20 }
21
22 std::size_t GetSize() const override {
23 return size;
24 }
25
26 bool Resize(std::size_t new_size) override {
27 return false;
28 }
29
30 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override {
31 return parent;
32 }
33
34 bool IsWritable() const override {
35 return false;
36 }
37
38 bool IsReadable() const override {
39 return true;
40 }
41
42 std::size_t Read(u8* data_, std::size_t length, std::size_t offset) const override {
43 const auto read = std::min(length, size - offset);
44 std::memcpy(data_, data.data() + offset, read);
45 return read;
46 }
47
48 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override {
49 return 0;
50 }
51
52 bool Rename(std::string_view name) override {
53 this->name = name;
54 return true;
55 }
56
57private:
58 std::array<u8, size> data;
59 std::string name;
60 VirtualDir parent;
61};
62
11// An implementation of VfsFile that is backed by a vector optionally supplied upon construction 63// An implementation of VfsFile that is backed by a vector optionally supplied upon construction
12class VectorVfsFile : public VfsFile { 64class VectorVfsFile : public VfsFile {
13public: 65public: