diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-11-16 04:33:52 +0100 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-11-16 04:33:52 +0100 |
commit | 34cd56980f3014abdac7003092dd38684454cb13 (patch) | |
tree | ae534864bc42b44fe7bcced0e1cf094b1462d260 | |
parent | Merge pull request #1660 from Tinob/master (diff) | |
download | yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.gz yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.bz2 yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.lz yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.xz yuzu-34cd56980f3014abdac7003092dd38684454cb13.tar.zst yuzu-34cd56980f3014abdac7003092dd38684454cb13.zip |
-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 @@ namespace FileSys { +// An implementation of VfsFile that is backed by a statically-sized array +template <std::size_t size> +class ArrayVfsFile : public VfsFile { +public: + ArrayVfsFile(std::array<u8, size> data, std::string name = "", VirtualDir parent = nullptr) + : data(std::move(data)), name(std::move(name)), parent(std::move(parent)) {} + + std::string GetName() const override { + return name; + } + + std::size_t GetSize() const override { + return size; + } + + bool Resize(std::size_t new_size) override { + return false; + } + + std::shared_ptr<VfsDirectory> GetContainingDirectory() const override { + return parent; + } + + bool IsWritable() const override { + return false; + } + + bool IsReadable() const override { + return true; + } + + std::size_t Read(u8* data_, std::size_t length, std::size_t offset) const override { + const auto read = std::min(length, size - offset); + std::memcpy(data_, data.data() + offset, read); + return read; + } + + std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override { + return 0; + } + + bool Rename(std::string_view name) override { + this->name = name; + return true; + } + +private: + std::array<u8, size> data; + std::string name; + VirtualDir parent; +}; + // An implementation of VfsFile that is backed by a vector optionally supplied upon construction class VectorVfsFile : public VfsFile { public: |