Loaders: Refactor chaining to avoid dup code.

This commit is contained in:
Unknown W. Brackets committed 2018-12-27 10:32:47 -08:00
1 parent 359afb2d6b
commit 7f84c87931
9 files changed
+62 -107

No files matched your search

+5 -15
View File
@@ -28,7 +28,7 @@
// Takes ownership of backend.
RamCachingFileLoader::RamCachingFileLoader(FileLoader *backend)
: backend_(backend) {
: ProxiedFileLoader(backend) {
filesize_ = backend->FileSize();
if (filesize_ > 0) {
InitCache();
@@ -39,27 +39,25 @@ RamCachingFileLoader::~RamCachingFileLoader() {
if (filesize_ > 0) {
ShutdownCache();
}
// Takes ownership.
delete backend_;
}
bool RamCachingFileLoader::Exists() {
if (exists_ == -1) {
exists_ = backend_->Exists() ? 1 : 0;
exists_ = ProxiedFileLoader::Exists() ? 1 : 0;
}
return exists_ == 1;
}
bool RamCachingFileLoader::ExistsFast() {
if (exists_ == -1) {
return backend_->ExistsFast();
return ProxiedFileLoader::ExistsFast();
}
return exists_ == 1;
}
bool RamCachingFileLoader::IsDirectory() {
if (isDirectory_ == -1) {
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
isDirectory_ = ProxiedFileLoader::IsDirectory() ? 1 : 0;
}
return isDirectory_ == 1;
}
@@ -68,10 +66,6 @@ s64 RamCachingFileLoader::FileSize() {
return filesize_;
}
std::string RamCachingFileLoader::Path() const {
return backend_->Path();
}
size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
size_t readSize = 0;
if (cache_ == nullptr || (flags & Flags::HINT_UNCACHED) != 0) {
@@ -129,7 +123,7 @@ void RamCachingFileLoader::Cancel() {
aheadCancel_ = true;
}
backend_->Cancel();
ProxiedFileLoader::Cancel();
}
size_t RamCachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
@@ -270,7 +264,3 @@ u32 RamCachingFileLoader::NextAheadBlock() {
return 0xFFFFFFFF;
}
bool RamCachingFileLoader::IsRemote() {
return backend_->IsRemote();
}