DiscIO: Use std::optional in Volume and Blob

This commit is contained in:
JosJuice
2017-06-04 10:33:14 +02:00
parent e23cfc2965
commit c3fa0d6edf
23 changed files with 232 additions and 237 deletions

View File

@ -5,6 +5,7 @@
#include <cstddef>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -57,20 +58,14 @@ std::string CVolumeGC::GetGameID(const Partition& partition) const
Region CVolumeGC::GetRegion() const
{
u8 country_code;
if (!ReadSwapped(3, &country_code, PARTITION_NONE))
return Region::UNKNOWN_REGION;
return RegionSwitchGC(country_code);
const std::optional<u8> country_code = ReadSwapped<u8>(3, PARTITION_NONE);
return country_code ? RegionSwitchGC(*country_code) : Region::UNKNOWN_REGION;
}
Country CVolumeGC::GetCountry(const Partition& partition) const
{
u8 country_code;
if (!ReadSwapped(3, &country_code, partition))
return Country::COUNTRY_UNKNOWN;
return CountrySwitch(country_code);
const std::optional<u8> country_code = ReadSwapped<u8>(3, partition);
return country_code ? CountrySwitch(*country_code) : Country::COUNTRY_UNKNOWN;
}
std::string CVolumeGC::GetMakerID(const Partition& partition) const
@ -82,13 +77,10 @@ std::string CVolumeGC::GetMakerID(const Partition& partition) const
return DecodeString(makerID);
}
u16 CVolumeGC::GetRevision(const Partition& partition) const
std::optional<u16> CVolumeGC::GetRevision(const Partition& partition) const
{
u8 revision;
if (!ReadSwapped(7, &revision, partition))
return 0;
return revision;
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
return revision ? *revision : std::optional<u16>();
}
std::string CVolumeGC::GetInternalName(const Partition& partition) const
@ -162,11 +154,9 @@ u64 CVolumeGC::GetRawSize() const
return m_pReader->GetRawSize();
}
u8 CVolumeGC::GetDiscNumber(const Partition& partition) const
std::optional<u8> CVolumeGC::GetDiscNumber(const Partition& partition) const
{
u8 disc_number = 0;
ReadSwapped(6, &disc_number, partition);
return disc_number;
return ReadSwapped<u8>(6, partition);
}
Platform CVolumeGC::GetVolumeType() const