diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-07-28 00:14:03 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-07-28 00:14:03 +0200 |
commit | 906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f (patch) | |
tree | beff5b868534a8bfb4eea7992553fa5fb5db5287 /src/core/file_sys/vfs_vector.cpp | |
parent | Merge pull request #845 from lioncash/nfc (diff) | |
download | yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar.gz yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar.bz2 yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar.lz yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar.xz yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.tar.zst yuzu-906d785c73cb3644e8984fbfcbf5fcb8a1ebbc6f.zip |
Diffstat (limited to 'src/core/file_sys/vfs_vector.cpp')
-rw-r--r-- | src/core/file_sys/vfs_vector.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp new file mode 100644 index 000000000..4c6337e3a --- /dev/null +++ b/src/core/file_sys/vfs_vector.cpp @@ -0,0 +1,83 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <algorithm> +#include "core/file_sys/vfs_vector.h" + +namespace FileSys { +VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_, + std::vector<VirtualDir> dirs_, VirtualDir parent_, + std::string name_) + : files(std::move(files_)), dirs(std::move(dirs_)), parent(std::move(parent_)), + name(std::move(name_)) {} + +std::vector<std::shared_ptr<VfsFile>> VectorVfsDirectory::GetFiles() const { + return files; +} + +std::vector<std::shared_ptr<VfsDirectory>> VectorVfsDirectory::GetSubdirectories() const { + return dirs; +} + +bool VectorVfsDirectory::IsWritable() const { + return false; +} + +bool VectorVfsDirectory::IsReadable() const { + return true; +} + +std::string VectorVfsDirectory::GetName() const { + return name; +} +std::shared_ptr<VfsDirectory> VectorVfsDirectory::GetParentDirectory() const { + return parent; +} + +template <typename T> +static bool FindAndRemoveVectorElement(std::vector<T>& vec, std::string_view name) { + auto iter = std::find_if(vec.begin(), vec.end(), [name](T e) { return e->GetName() == name; }); + if (iter == vec.end()) + return false; + auto old_size = vec.size(); + vec.erase(iter); + return true; +} + +bool VectorVfsDirectory::DeleteSubdirectory(std::string_view name) { + return FindAndRemoveVectorElement(dirs, name); +} + +bool VectorVfsDirectory::DeleteFile(std::string_view name) { + return FindAndRemoveVectorElement(files, name); +} + +bool VectorVfsDirectory::Rename(std::string_view name_) { + name = name_; + return true; +} + +std::shared_ptr<VfsDirectory> VectorVfsDirectory::CreateSubdirectory(std::string_view name) { + return nullptr; +} + +std::shared_ptr<VfsFile> VectorVfsDirectory::CreateFile(std::string_view name) { + return nullptr; +} + +void VectorVfsDirectory::AddFile(VirtualFile file) { + files.push_back(std::move(file)); +} + +void VectorVfsDirectory::AddDirectory(VirtualDir dir) { + dirs.push_back(std::move(dir)); +} + +bool VectorVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { + if (!DeleteFile(file->GetName())) + return false; + dirs.emplace_back(dir); + return true; +} +} // namespace FileSys |