From 7a5eda59146306dedaf3e6f07f97a8c6898543dd Mon Sep 17 00:00:00 2001 From: Frederic L Date: Tue, 30 Oct 2018 05:03:25 +0100 Subject: global: Use std::optional instead of boost::optional (#1578) * get rid of boost::optional * Remove optional references * Use std::reference_wrapper for optional references * Fix clang format * Fix clang format part 2 * Adressed feedback * Fix clang format and MacOS build --- src/core/file_sys/registered_cache.cpp | 62 +++++++++++++++------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'src/core/file_sys/registered_cache.cpp') diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 29b100414..96302a241 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -159,28 +159,28 @@ VirtualFile RegisteredCache::GetFileAtID(NcaID id) const { return file; } -static boost::optional CheckMapForContentRecord( +static std::optional CheckMapForContentRecord( const boost::container::flat_map& map, u64 title_id, ContentRecordType type) { if (map.find(title_id) == map.end()) - return boost::none; + return {}; const auto& cnmt = map.at(title_id); const auto iter = std::find_if(cnmt.GetContentRecords().begin(), cnmt.GetContentRecords().end(), [type](const ContentRecord& rec) { return rec.type == type; }); if (iter == cnmt.GetContentRecords().end()) - return boost::none; + return {}; - return boost::make_optional(iter->nca_id); + return std::make_optional(iter->nca_id); } -boost::optional RegisteredCache::GetNcaIDFromMetadata(u64 title_id, - ContentRecordType type) const { +std::optional RegisteredCache::GetNcaIDFromMetadata(u64 title_id, + ContentRecordType type) const { if (type == ContentRecordType::Meta && meta_id.find(title_id) != meta_id.end()) return meta_id.at(title_id); const auto res1 = CheckMapForContentRecord(yuzu_meta, title_id, type); - if (res1 != boost::none) + if (res1) return res1; return CheckMapForContentRecord(meta, title_id, type); } @@ -283,17 +283,14 @@ bool RegisteredCache::HasEntry(RegisteredCacheEntry entry) const { VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType type) const { const auto id = GetNcaIDFromMetadata(title_id, type); - if (id == boost::none) - return nullptr; - - return GetFileAtID(id.get()); + return id ? GetFileAtID(*id) : nullptr; } VirtualFile RegisteredCache::GetEntryUnparsed(RegisteredCacheEntry entry) const { return GetEntryUnparsed(entry.title_id, entry.type); } -boost::optional RegisteredCache::GetEntryVersion(u64 title_id) const { +std::optional RegisteredCache::GetEntryVersion(u64 title_id) const { const auto meta_iter = meta.find(title_id); if (meta_iter != meta.end()) return meta_iter->second.GetTitleVersion(); @@ -302,15 +299,12 @@ boost::optional RegisteredCache::GetEntryVersion(u64 title_id) const { if (yuzu_meta_iter != yuzu_meta.end()) return yuzu_meta_iter->second.GetTitleVersion(); - return boost::none; + return {}; } VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) const { const auto id = GetNcaIDFromMetadata(title_id, type); - if (id == boost::none) - return nullptr; - - return parser(GetFileAtID(id.get()), id.get()); + return id ? parser(GetFileAtID(*id), *id) : nullptr; } VirtualFile RegisteredCache::GetEntryRaw(RegisteredCacheEntry entry) const { @@ -364,8 +358,8 @@ std::vector RegisteredCache::ListEntries() const { } std::vector RegisteredCache::ListEntriesFilter( - boost::optional title_type, boost::optional record_type, - boost::optional title_id) const { + std::optional title_type, std::optional record_type, + std::optional title_id) const { std::vector out; IterateAllMetadata( out, @@ -373,11 +367,11 @@ std::vector RegisteredCache::ListEntriesFilter( return RegisteredCacheEntry{c.GetTitleID(), r.type}; }, [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) { - if (title_type != boost::none && title_type.get() != c.GetType()) + if (title_type && *title_type != c.GetType()) return false; - if (record_type != boost::none && record_type.get() != r.type) + if (record_type && *record_type != r.type) return false; - if (title_id != boost::none && title_id.get() != c.GetTitleID()) + if (title_id && *title_id != c.GetTitleID()) return false; return true; }); @@ -459,7 +453,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr nca, TitleType InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr nca, const VfsCopyFunction& copy, bool overwrite_if_exists, - boost::optional override_id) { + std::optional override_id) { const auto in = nca->GetBaseFile(); Core::Crypto::SHA256Hash hash{}; @@ -468,12 +462,12 @@ InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr nca, const Vfs // game is massive), we're going to cheat and only hash the first MB of the NCA. // Also, for XCIs the NcaID matters, so if the override id isn't none, use that. NcaID id{}; - if (override_id == boost::none) { + if (override_id) { + id = *override_id; + } else { const auto& data = in->ReadBytes(0x100000); mbedtls_sha256(data.data(), data.size(), hash.data(), 0); memcpy(id.data(), hash.data(), 16); - } else { - id = override_id.get(); } std::string path = GetRelativePathFromNcaID(id, false, true); @@ -543,14 +537,14 @@ bool RegisteredCacheUnion::HasEntry(RegisteredCacheEntry entry) const { return HasEntry(entry.title_id, entry.type); } -boost::optional RegisteredCacheUnion::GetEntryVersion(u64 title_id) const { +std::optional RegisteredCacheUnion::GetEntryVersion(u64 title_id) const { for (const auto& c : caches) { const auto res = c->GetEntryVersion(title_id); - if (res != boost::none) + if (res) return res; } - return boost::none; + return {}; } VirtualFile RegisteredCacheUnion::GetEntryUnparsed(u64 title_id, ContentRecordType type) const { @@ -609,8 +603,8 @@ std::vector RegisteredCacheUnion::ListEntries() const { } std::vector RegisteredCacheUnion::ListEntriesFilter( - boost::optional title_type, boost::optional record_type, - boost::optional title_id) const { + std::optional title_type, std::optional record_type, + std::optional title_id) const { std::vector out; for (const auto& c : caches) { c->IterateAllMetadata( @@ -619,11 +613,11 @@ std::vector RegisteredCacheUnion::ListEntriesFilter( return RegisteredCacheEntry{c.GetTitleID(), r.type}; }, [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) { - if (title_type != boost::none && title_type.get() != c.GetType()) + if (title_type && *title_type != c.GetType()) return false; - if (record_type != boost::none && record_type.get() != r.type) + if (record_type && *record_type != r.type) return false; - if (title_id != boost::none && title_id.get() != c.GetTitleID()) + if (title_id && *title_id != c.GetTitleID()) return false; return true; }); -- cgit v1.2.3