archive: Make use of std::pair for OpenFileFromArchive (#5399)
* archive: Make use of std::pair for OpenFileFromArchive The tuple only makes use of two elements, so we can use a pair to simplify the number of underlying template instantiations that need to be done, while also simplifying the surrounding code. * archive: Simplify MakeResult calls MakeResult can deduce the contained result type based off the type of the variable being passed to it, so explicitly specifying it is a little verbose.
This commit is contained in:
parent
1504018a56
commit
f7aaa37bf2
@ -54,7 +54,7 @@ ResultVal<ArchiveHandle> ArchiveManager::OpenArchive(ArchiveIdCode id_code,
|
|||||||
++next_handle;
|
++next_handle;
|
||||||
}
|
}
|
||||||
handle_map.emplace(next_handle, std::move(res));
|
handle_map.emplace(next_handle, std::move(res));
|
||||||
return MakeResult<ArchiveHandle>(next_handle++);
|
return MakeResult(next_handle++);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveManager::CloseArchive(ArchiveHandle handle) {
|
ResultCode ArchiveManager::CloseArchive(ArchiveHandle handle) {
|
||||||
@ -79,21 +79,22 @@ ResultCode ArchiveManager::RegisterArchiveType(std::unique_ptr<FileSys::ArchiveF
|
|||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds>
|
std::pair<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds>
|
||||||
ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
|
ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
|
||||||
const FileSys::Mode mode) {
|
const FileSys::Mode mode) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr) {
|
||||||
return std::make_tuple(FileSys::ERR_INVALID_ARCHIVE_HANDLE,
|
return std::make_pair(FileSys::ERR_INVALID_ARCHIVE_HANDLE, std::chrono::nanoseconds{0});
|
||||||
static_cast<std::chrono::nanoseconds>(0));
|
}
|
||||||
|
|
||||||
std::chrono::nanoseconds open_timeout_ns{archive->GetOpenDelayNs()};
|
const std::chrono::nanoseconds open_timeout_ns{archive->GetOpenDelayNs()};
|
||||||
auto backend = archive->OpenFile(path, mode);
|
auto backend = archive->OpenFile(path, mode);
|
||||||
if (backend.Failed())
|
if (backend.Failed()) {
|
||||||
return std::make_tuple(backend.Code(), open_timeout_ns);
|
return std::make_pair(backend.Code(), open_timeout_ns);
|
||||||
|
}
|
||||||
|
|
||||||
auto file = std::make_shared<File>(system.Kernel(), std::move(backend).Unwrap(), path);
|
auto file = std::make_shared<File>(system.Kernel(), std::move(backend).Unwrap(), path);
|
||||||
return std::make_tuple(MakeResult<std::shared_ptr<File>>(std::move(file)), open_timeout_ns);
|
return std::make_pair(MakeResult(std::move(file)), open_timeout_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveManager::DeleteFileFromArchive(ArchiveHandle archive_handle,
|
ResultCode ArchiveManager::DeleteFileFromArchive(ArchiveHandle archive_handle,
|
||||||
@ -178,22 +179,25 @@ ResultCode ArchiveManager::RenameDirectoryBetweenArchives(ArchiveHandle src_arch
|
|||||||
ResultVal<std::shared_ptr<Directory>> ArchiveManager::OpenDirectoryFromArchive(
|
ResultVal<std::shared_ptr<Directory>> ArchiveManager::OpenDirectoryFromArchive(
|
||||||
ArchiveHandle archive_handle, const FileSys::Path& path) {
|
ArchiveHandle archive_handle, const FileSys::Path& path) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr) {
|
||||||
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
|
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
auto backend = archive->OpenDirectory(path);
|
auto backend = archive->OpenDirectory(path);
|
||||||
if (backend.Failed())
|
if (backend.Failed()) {
|
||||||
return backend.Code();
|
return backend.Code();
|
||||||
|
}
|
||||||
|
|
||||||
auto directory = std::make_shared<Directory>(std::move(backend).Unwrap(), path);
|
auto directory = std::make_shared<Directory>(std::move(backend).Unwrap(), path);
|
||||||
return MakeResult<std::shared_ptr<Directory>>(std::move(directory));
|
return MakeResult(std::move(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<u64> ArchiveManager::GetFreeBytesInArchive(ArchiveHandle archive_handle) {
|
ResultVal<u64> ArchiveManager::GetFreeBytesInArchive(ArchiveHandle archive_handle) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
const ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr) {
|
||||||
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
|
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
|
||||||
return MakeResult<u64>(archive->GetFreeBytes());
|
}
|
||||||
|
return MakeResult(archive->GetFreeBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveManager::FormatArchive(ArchiveIdCode id_code,
|
ResultCode ArchiveManager::FormatArchive(ArchiveIdCode id_code,
|
||||||
|
@ -86,10 +86,10 @@ public:
|
|||||||
* @param archive_handle Handle to an open Archive object
|
* @param archive_handle Handle to an open Archive object
|
||||||
* @param path Path to the File inside of the Archive
|
* @param path Path to the File inside of the Archive
|
||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return Tuple of the opened File object and the open delay
|
* @return Pair containing the opened File object and the open delay
|
||||||
*/
|
*/
|
||||||
std::tuple<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds> OpenFileFromArchive(
|
std::pair<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds> OpenFileFromArchive(
|
||||||
ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
|
ArchiveHandle archive_handle, const FileSys::Path& path, FileSys::Mode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a File from an Archive
|
* Delete a File from an Archive
|
||||||
|
Loading…
Reference in New Issue
Block a user