lr: Cleanup lr_redirection

This commit is contained in:
Adubbz 2019-08-13 23:38:24 +10:00
parent 20a4d9203c
commit cfabec986c
2 changed files with 44 additions and 37 deletions

View File

@ -18,54 +18,75 @@
namespace sts::lr::impl { namespace sts::lr::impl {
class LocationRedirection : public util::IntrusiveListBaseNode<LocationRedirection> {
NON_COPYABLE(LocationRedirection);
NON_MOVEABLE(LocationRedirection);
private:
ncm::TitleId title_id;
Path path;
u32 flags;
public:
LocationRedirection(ncm::TitleId title_id, const Path& path, u32 flags) :
title_id(title_id), path(path), flags(flags) { /* ... */ }
ncm::TitleId GetTitleId() const {
return this->title_id;
}
void GetPath(Path *out) const {
*out = this->path;
}
u32 GetFlags() const {
return this->flags;
}
void SetFlags(u32 flags) {
this->flags = flags;
}
};
bool LocationRedirector::FindRedirection(Path *out, ncm::TitleId title_id) { bool LocationRedirector::FindRedirection(Path *out, ncm::TitleId title_id) {
if (this->redirection_list.empty()) { if (this->redirection_list.empty()) {
return false; return false;
} }
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { for (const auto &redirection : this->redirection_list) {
if (it->title_id == title_id) { if (redirection.GetTitleId() == title_id) {
*out = it->path; redirection.GetPath(out);
return true; return true;
} }
} }
return false; return false;
} }
void LocationRedirector::SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags) { void LocationRedirector::SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags) {
this->EraseRedirection(title_id); this->EraseRedirection(title_id);
auto redirection = new LocationRedirection(title_id, path, flags); this->redirection_list.push_back(*(new LocationRedirection(title_id, path, flags)));
this->redirection_list.push_back(*redirection);
} }
void LocationRedirector::SetRedirectionFlags(ncm::TitleId title_id, u32 flags) { void LocationRedirector::SetRedirectionFlags(ncm::TitleId title_id, u32 flags) {
if (!this->redirection_list.empty()) { for (auto &redirection : this->redirection_list) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { if (redirection.GetTitleId() == title_id) {
if (it->title_id == title_id) { redirection.SetFlags(flags);
it->flags = flags;
break; break;
} }
} }
} }
}
void LocationRedirector::EraseRedirection(ncm::TitleId title_id) { void LocationRedirector::EraseRedirection(ncm::TitleId title_id) {
if (!this->redirection_list.empty()) { for (auto &redirection : this->redirection_list) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { if (redirection.GetTitleId() == title_id) {
if (it->title_id == title_id) { this->redirection_list.erase(this->redirection_list.iterator_to(redirection));
auto old = it; delete &redirection;
this->redirection_list.erase(old);
delete &(*old);
break; break;
} }
} }
} }
}
void LocationRedirector::ClearRedirections(u32 flags) { void LocationRedirector::ClearRedirections(u32 flags) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) { for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) {
if ((it->flags & flags) == flags) { if ((it->GetFlags() & flags) == flags) {
auto old = it; auto old = it;
it = this->redirection_list.erase(it); it = this->redirection_list.erase(it);
delete &(*old); delete &(*old);
@ -75,6 +96,4 @@ namespace sts::lr::impl {
} }
} }
} }

View File

@ -27,19 +27,7 @@ namespace sts::lr::impl {
RedirectionFlags_Application = (1 << 0), RedirectionFlags_Application = (1 << 0),
}; };
class LocationRedirection : public util::IntrusiveListBaseNode<LocationRedirection> { class LocationRedirection;
NON_COPYABLE(LocationRedirection);
NON_MOVEABLE(LocationRedirection);
public:
ncm::TitleId title_id;
Path path;
u32 flags;
LocationRedirection(ncm::TitleId title_id, const Path& path, u32 flags) :
title_id(title_id), path(path), flags(flags) {
}
};
class LocationRedirector { class LocationRedirector {
NON_COPYABLE(LocationRedirector); NON_COPYABLE(LocationRedirector);
@ -47,7 +35,7 @@ namespace sts::lr::impl {
private: private:
sts::util::IntrusiveListBaseTraits<LocationRedirection>::ListType redirection_list; sts::util::IntrusiveListBaseTraits<LocationRedirection>::ListType redirection_list;
public: public:
LocationRedirector() {} LocationRedirector() { /* ... */ }
bool FindRedirection(Path *out, ncm::TitleId title_id); bool FindRedirection(Path *out, ncm::TitleId title_id);
void SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags = RedirectionFlags_None); void SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags = RedirectionFlags_None);