From cfabec986c83f96a01aa3997748dc62807389827 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Tue, 13 Aug 2019 23:38:24 +1000 Subject: [PATCH] lr: Cleanup lr_redirection --- .../ncm/source/impl/lr_redirection.cpp | 65 ++++++++++++------- .../ncm/source/impl/lr_redirection.hpp | 16 +---- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/stratosphere/ncm/source/impl/lr_redirection.cpp b/stratosphere/ncm/source/impl/lr_redirection.cpp index 9af961411..e69e09ba3 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.cpp +++ b/stratosphere/ncm/source/impl/lr_redirection.cpp @@ -18,54 +18,75 @@ namespace sts::lr::impl { + class LocationRedirection : public util::IntrusiveListBaseNode { + 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) { if (this->redirection_list.empty()) { return false; } - for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { - if (it->title_id == title_id) { - *out = it->path; + for (const auto &redirection : this->redirection_list) { + if (redirection.GetTitleId() == title_id) { + redirection.GetPath(out); return true; } } - return false; } void LocationRedirector::SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags) { this->EraseRedirection(title_id); - auto redirection = new LocationRedirection(title_id, path, flags); - this->redirection_list.push_back(*redirection); + this->redirection_list.push_back(*(new LocationRedirection(title_id, path, flags))); } void LocationRedirector::SetRedirectionFlags(ncm::TitleId title_id, u32 flags) { - if (!this->redirection_list.empty()) { - for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { - if (it->title_id == title_id) { - it->flags = flags; - break; - } + for (auto &redirection : this->redirection_list) { + if (redirection.GetTitleId() == title_id) { + redirection.SetFlags(flags); + break; } } } void LocationRedirector::EraseRedirection(ncm::TitleId title_id) { - if (!this->redirection_list.empty()) { - for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) { - if (it->title_id == title_id) { - auto old = it; - this->redirection_list.erase(old); - delete &(*old); - break; - } + for (auto &redirection : this->redirection_list) { + if (redirection.GetTitleId() == title_id) { + this->redirection_list.erase(this->redirection_list.iterator_to(redirection)); + delete &redirection; + break; } } } void LocationRedirector::ClearRedirections(u32 flags) { 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; it = this->redirection_list.erase(it); delete &(*old); @@ -75,6 +96,4 @@ namespace sts::lr::impl { } } - - } \ No newline at end of file diff --git a/stratosphere/ncm/source/impl/lr_redirection.hpp b/stratosphere/ncm/source/impl/lr_redirection.hpp index fccd85c0d..2d182137d 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.hpp +++ b/stratosphere/ncm/source/impl/lr_redirection.hpp @@ -27,19 +27,7 @@ namespace sts::lr::impl { RedirectionFlags_Application = (1 << 0), }; - class LocationRedirection : public util::IntrusiveListBaseNode { - 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 LocationRedirection; class LocationRedirector { NON_COPYABLE(LocationRedirector); @@ -47,7 +35,7 @@ namespace sts::lr::impl { private: sts::util::IntrusiveListBaseTraits::ListType redirection_list; public: - LocationRedirector() {} + LocationRedirector() { /* ... */ } bool FindRedirection(Path *out, ncm::TitleId title_id); void SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags = RedirectionFlags_None);