Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2016-02-28 22:33:38 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:49:24 +0300
commit4a3989ff23d90c112b50f690e7a2c2329aa54389 (patch)
tree6c4476e3d423686acbf55f180c39abb55561b929 /platform
parent78fb143a7901288395d5cc70b0aa4e0b9ff707fc (diff)
Platform::GetReader returns unique_ptr. Fix leaks.
Diffstat (limited to 'platform')
-rw-r--r--platform/local_country_file_utils.cpp2
-rw-r--r--platform/local_country_file_utils.hpp3
-rw-r--r--platform/platform.hpp7
-rw-r--r--platform/platform_android.cpp14
-rw-r--r--platform/platform_ios.mm6
-rw-r--r--platform/platform_qt.cpp6
-rw-r--r--platform/settings.cpp2
7 files changed, 21 insertions, 19 deletions
diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp
index 18b4a3de75..dd538a5cec 100644
--- a/platform/local_country_file_utils.cpp
+++ b/platform/local_country_file_utils.cpp
@@ -346,7 +346,7 @@ string GetFileDownloadPath(int64_t version, string const & dataDir,
return my::JoinFoldersToPath({dir, strings::to_string(version)}, readyFile);
}
-ModelReader * GetCountryReader(platform::LocalCountryFile const & file, MapOptions options)
+unique_ptr<ModelReader> GetCountryReader(platform::LocalCountryFile const & file, MapOptions options)
{
Platform & platform = GetPlatform();
// See LocalCountryFile comment for explanation.
diff --git a/platform/local_country_file_utils.hpp b/platform/local_country_file_utils.hpp
index aabcd19b2d..3d53918300 100644
--- a/platform/local_country_file_utils.hpp
+++ b/platform/local_country_file_utils.hpp
@@ -5,6 +5,7 @@
#include "std/function.hpp"
#include "std/shared_ptr.hpp"
+#include "std/unique_ptr.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
@@ -81,7 +82,7 @@ string GetFileDownloadPath(int64_t version, CountryFile const & countryFile, Map
string GetFileDownloadPath(int64_t version, string const & dataDir,
CountryFile const & countryFile, MapOptions file);
-ModelReader * GetCountryReader(LocalCountryFile const & file, MapOptions options);
+unique_ptr<ModelReader> GetCountryReader(LocalCountryFile const & file, MapOptions options);
// An API for managing country indexes.
class CountryIndexes
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 7557f19856..a7575035de 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -133,10 +133,11 @@ public:
/// @return reader for file decriptor.
/// @throws FileAbsentException
- /// @param[in] file name or full path which we want to read, don't forget to free memory or wrap it to ReaderPtr
+ /// @param[in] file name or full path which we want to read
/// @param[in] searchScope looks for file in dirs in given order: \n
- /// [w]ritable, [r]esources, [s]ettings, by [f]ull path, [e]xternal resources,
- ModelReader * GetReader(string const & file, string const & searchScope = string()) const;
+ /// [w]ritable, [r]esources, [s]ettings, by [f]ull path, [e]xternal resources,
+ unique_ptr<ModelReader>
+ GetReader(string const & file, string const & searchScope = string()) const;
/// @name File operations
//@{
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index d0cf6843cd..01fd0980c2 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -91,7 +91,7 @@ public:
}
-ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
+unique_ptr<ModelReader> Platform::GetReader(string const & file, string const & searchScope) const
{
string const ext = my::GetFileExtension(file);
ASSERT(!ext.empty(), ());
@@ -138,7 +138,7 @@ ModelReader * Platform::GetReader(string const & file, string const & searchScop
{
try
{
- return new ZipFileReader(m_extResFiles[j], file, logPageSize, logPageCount);
+ return make_unique<ZipFileReader>(m_extResFiles[j], file, logPageSize, logPageCount);
}
catch (Reader::OpenException const &)
{
@@ -150,7 +150,7 @@ ModelReader * Platform::GetReader(string const & file, string const & searchScop
{
string const path = m_writableDir + file;
if (IsFileExistsByFullPath(path))
- return new FileReader(path, logPageSize, logPageCount);
+ return make_unique<FileReader>(path, logPageSize, logPageCount);
break;
}
@@ -158,20 +158,20 @@ ModelReader * Platform::GetReader(string const & file, string const & searchScop
{
string const path = m_settingsDir + file;
if (IsFileExistsByFullPath(path))
- return new FileReader(path, logPageSize, logPageCount);
+ return make_unique<FileReader>(path, logPageSize, logPageCount);
break;
}
case FULL_PATH:
if (IsFileExistsByFullPath(file))
- return new FileReader(file, logPageSize, logPageCount);
+ return make_unique<FileReader>(file, logPageSize, logPageCount);
break;
case RESOURCE:
ASSERT_EQUAL(file.find("assets/"), string::npos, ());
try
{
- return new ZipFileReader(m_resourcesDir, "assets/" + file, logPageSize, logPageCount);
+ return make_unique<ZipFileReader>(m_resourcesDir, "assets/" + file, logPageSize, logPageCount);
}
catch (Reader::OpenException const &)
{
@@ -186,7 +186,7 @@ ModelReader * Platform::GetReader(string const & file, string const & searchScop
LOG(LWARNING, ("Can't get reader for:", file));
MYTHROW(FileAbsentException, ("File not found", file));
- return 0;
+ return nullptr;
}
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)
diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm
index d479637f04..ec0b8058e1 100644
--- a/platform/platform_ios.mm
+++ b/platform/platform_ios.mm
@@ -134,10 +134,10 @@ bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
}
}
-ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
+unique_ptr<ModelReader> Platform::GetReader(string const & file, string const & searchScope) const
{
- return new FileReader(ReadPathForFile(file, searchScope),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ return make_unique<FileReader>(ReadPathForFile(file, searchScope),
+ READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
}
int Platform::VideoMemoryLimit() const
diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp
index da784a4bf1..527426a485 100644
--- a/platform/platform_qt.cpp
+++ b/platform/platform_qt.cpp
@@ -17,10 +17,10 @@
#include <QtCore/QFileInfo>
#include <QtCore/QLocale>
-ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
+unique_ptr<ModelReader> Platform::GetReader(string const & file, string const & searchScope) const
{
- return new FileReader(ReadPathForFile(file, searchScope),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ return make_unique<FileReader>(ReadPathForFile(file, searchScope),
+ READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
}
bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
diff --git a/platform/settings.cpp b/platform/settings.cpp
index 86da785031..5accfbe3b3 100644
--- a/platform/settings.cpp
+++ b/platform/settings.cpp
@@ -32,7 +32,7 @@ namespace Settings
{
string settingsPath = GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME);
LOG(LINFO, ("Settings path:", settingsPath));
- ReaderStreamBuf buffer(new FileReader(settingsPath));
+ ReaderStreamBuf buffer(make_unique<FileReader>(settingsPath));
istream stream(&buffer);
string line;