diff options
| author | 2018-11-15 22:33:52 -0500 | |
|---|---|---|
| committer | 2018-11-15 22:33:52 -0500 | |
| commit | 34cd56980f3014abdac7003092dd38684454cb13 (patch) | |
| tree | ae534864bc42b44fe7bcced0e1cf094b1462d260 /src | |
| parent | Merge pull request #1660 from Tinob/master (diff) | |
| download | yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.gz yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.xz yuzu-34cd56980f3014abdac7003092dd38684454cb13.zip | |
vfs_vector: Add VFS backend for std::array
Allows using constexpr/static const data with VFS.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/vfs_vector.h | 52 |
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 | ||
| 9 | namespace FileSys { | 9 | namespace FileSys { |
| 10 | 10 | ||
| 11 | // An implementation of VfsFile that is backed by a statically-sized array | ||
| 12 | template <std::size_t size> | ||
| 13 | class ArrayVfsFile : public VfsFile { | ||
| 14 | public: | ||
| 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 | |||
| 57 | private: | ||
| 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 |
| 12 | class VectorVfsFile : public VfsFile { | 64 | class VectorVfsFile : public VfsFile { |
| 13 | public: | 65 | public: |