diff options
| author | Zach Hilman <zachhilman@gmail.com> | 2018-09-19 21:58:33 -0400 |
|---|---|---|
| committer | Zach Hilman <zachhilman@gmail.com> | 2018-09-21 19:53:05 -0400 |
| commit | b52343a428b76ef0fa74c6a939aef7eab33feedb (patch) | |
| tree | 9cbbc5df26915a7213705644dd39c2cf48512afe /src/core/file_sys/vfs_vector.h | |
| parent | c65d4d119fceac4b08530e372d0a6e4ca24f121a (diff) | |
vfs_vector: Add VectorVfsFile
Maps a vector into the VFS interface.
Diffstat (limited to 'src/core/file_sys/vfs_vector.h')
| -rw-r--r-- | src/core/file_sys/vfs_vector.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h index cba44a7a6..c84e137a9 100644 --- a/src/core/file_sys/vfs_vector.h +++ b/src/core/file_sys/vfs_vector.h @@ -8,6 +8,30 @@ namespace FileSys { +// An implementation of VfsFile that is backed by a vector optionally supplied upon construction +class VectorVfsFile : public VfsFile { +public: + explicit VectorVfsFile(std::vector<u8> initial_data = {}, std::string name = "", + VirtualDir parent = nullptr); + + std::string GetName() const override; + size_t GetSize() const override; + bool Resize(size_t new_size) override; + std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; + bool IsWritable() const override; + bool IsReadable() const override; + size_t Read(u8* data, size_t length, size_t offset) const override; + size_t Write(const u8* data, size_t length, size_t offset) override; + bool Rename(std::string_view name) override; + + virtual void Assign(std::vector<u8> new_data); + +private: + std::vector<u8> data; + VirtualDir parent; + std::string name; +}; + // An implementation of VfsDirectory that maintains two vectors for subdirectories and files. // Vector data is supplied upon construction. class VectorVfsDirectory : public VfsDirectory { |
