diff options
| author | Lioncash <mathew1800@gmail.com> | 2015-12-06 23:15:51 -0500 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2015-12-07 05:57:37 -0500 |
| commit | edbbf493f807ed94b9b32cfb7463f9b7f8f27852 (patch) | |
| tree | 1babef3faeba508560effc1db476cbb722a9a709 /Source/Core/DolphinWX/MainAndroid.cpp | |
| parent | a0ac2b867368aa6f82ee3c471fea2cf1a450b37c (diff) | |
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.
Diffstat (limited to 'Source/Core/DolphinWX/MainAndroid.cpp')
| -rw-r--r-- | Source/Core/DolphinWX/MainAndroid.cpp | 52 |
1 files changed, 22 insertions, 30 deletions
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 <cstdio> #include <cstdlib> #include <jni.h> +#include <memory> #include <android/log.h> #include <android/native_window_jni.h> #include <EGL/egl.h> @@ -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<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename)); - if (pVolume != nullptr) + if (volume != nullptr) { - std::map <DiscIO::IVolume::ELanguage, std::string> descriptions = pVolume->GetDescriptions(); + std::map<DiscIO::IVolume::ELanguage, std::string> 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<DiscIO::IVolume> 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<DiscIO::IVolume> 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<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename)); + if (volume == nullptr) + return -1; - return -1; + return volume->GetSize(); } static std::string GetJString(JNIEnv *env, jstring jstr) |
