From edbbf493f807ed94b9b32cfb7463f9b7f8f27852 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 6 Dec 2015 23:15:51 -0500 Subject: DiscIO: Make factory methods return unique_ptrs Rather than rely on the developer to do the right thing, just make the default behavior safely deallocate resources. If shared semantics are ever needed in the future, the constructor that takes a unique_ptr for shared_ptr can be used. --- Source/Core/DolphinWX/MainAndroid.cpp | 52 +++++++++++++++-------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'Source/Core/DolphinWX/MainAndroid.cpp') diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index 1f6edfe6b3..42f3c93256 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -261,11 +262,11 @@ static std::string GetDescription(std::string filename) { __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Description for file: %s", filename.c_str()); - DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); + std::unique_ptr volume(DiscIO::CreateVolumeFromFilename(filename)); - if (pVolume != nullptr) + if (volume != nullptr) { - std::map descriptions = pVolume->GetDescriptions(); + std::map descriptions = volume->GetDescriptions(); /* bool is_wii_title = pVolume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC; @@ -289,53 +290,44 @@ static std::string GetDescription(std::string filename) return descriptions.cbegin()->second; } - return std::string (""); + return std::string(); } static std::string GetGameId(std::string filename) { __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting ID for file: %s", filename.c_str()); - DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); - if (pVolume != nullptr) - { - std::string id = pVolume->GetUniqueID(); - __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str()); + std::unique_ptr volume(DiscIO::CreateVolumeFromFilename(filename)); + if (volume == nullptr) + return std::string(); - return id; - } - return std::string (""); + std::string id = volume->GetUniqueID(); + __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str()); + return id; } static std::string GetCompany(std::string filename) { __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s", filename.c_str()); - DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); - if (pVolume != nullptr) - { - std::string company = DiscIO::GetCompanyFromID(pVolume->GetMakerID()); - __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str()); - return company; - } - return std::string (""); + std::unique_ptr volume(DiscIO::CreateVolumeFromFilename(filename)); + if (volume == nullptr) + return std::string(); + + std::string company = DiscIO::GetCompanyFromID(volume->GetMakerID()); + __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str()); + return company; } static u64 GetFileSize(std::string filename) { __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting size of file: %s", filename.c_str()); - DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); - if (pVolume != nullptr) - { - u64 size = pVolume->GetSize(); - // Causes a warning because size is u64, not 'long unsigned' - //__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Size: %lu", size); - - return size; - } + std::unique_ptr volume(DiscIO::CreateVolumeFromFilename(filename)); + if (volume == nullptr) + return -1; - return -1; + return volume->GetSize(); } static std::string GetJString(JNIEnv *env, jstring jstr) -- cgit v1.2.3