Fix unity build error by removing using namespace std;

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-07-26 21:46:13 +02:00
committed by Konstantin Pastbin
parent b5b333c832
commit 215c19dcc7
17 changed files with 184 additions and 197 deletions

View File

@@ -10,30 +10,28 @@
#include "base/logging.hpp" #include "base/logging.hpp"
#include "base/macros.hpp" #include "base/macros.hpp"
using namespace std;
namespace downloader namespace downloader
{ {
ChunksDownloadStrategy::ChunksDownloadStrategy(vector<string> const & urls) ChunksDownloadStrategy::ChunksDownloadStrategy(std::vector<std::string> const & urls)
{ {
// init servers list // init servers list
for (size_t i = 0; i < urls.size(); ++i) for (size_t i = 0; i < urls.size(); ++i)
m_servers.push_back(ServerT(urls[i], SERVER_READY)); m_servers.push_back(ServerT(urls[i], SERVER_READY));
} }
pair<ChunksDownloadStrategy::ChunkT *, int> ChunksDownloadStrategy::GetChunk(RangeT const & range) std::pair<ChunksDownloadStrategy::ChunkT *, int> ChunksDownloadStrategy::GetChunk(RangeT const & range)
{ {
vector<ChunkT>::iterator i = lower_bound(m_chunks.begin(), m_chunks.end(), range.first, LessChunks()); std::vector<ChunkT>::iterator i = lower_bound(m_chunks.begin(), m_chunks.end(), range.first, LessChunks());
if (i != m_chunks.end() && i->m_pos == range.first) if (i != m_chunks.end() && i->m_pos == range.first)
{ {
ASSERT_EQUAL((i + 1)->m_pos, range.second + 1, ()); ASSERT_EQUAL((i + 1)->m_pos, range.second + 1, ());
return pair<ChunkT *, int>(&(*i), distance(m_chunks.begin(), i)); return std::pair<ChunkT *, int>(&(*i), std::distance(m_chunks.begin(), i));
} }
else else
{ {
LOG(LERROR, ("Downloader error. Invalid chunk range: ", range)); LOG(LERROR, ("Downloader error. Invalid chunk range: ", range));
return pair<ChunkT *, int>(static_cast<ChunkT *>(0), -1); return std::pair<ChunkT *, int>(static_cast<ChunkT *>(0), -1);
} }
} }
@@ -87,7 +85,7 @@ void ChunksDownloadStrategy::AddChunk(RangeT const & range, ChunkStatusT status)
m_chunks.push_back(ChunkT(range.second + 1, CHUNK_AUX)); m_chunks.push_back(ChunkT(range.second + 1, CHUNK_AUX));
} }
void ChunksDownloadStrategy::SaveChunks(int64_t fileSize, string const & fName) void ChunksDownloadStrategy::SaveChunks(int64_t fileSize, std::string const & fName)
{ {
if (!m_chunks.empty()) if (!m_chunks.empty())
{ {
@@ -109,7 +107,7 @@ void ChunksDownloadStrategy::SaveChunks(int64_t fileSize, string const & fName)
UNUSED_VALUE(Platform::RemoveFileIfExists(fName)); UNUSED_VALUE(Platform::RemoveFileIfExists(fName));
} }
int64_t ChunksDownloadStrategy::LoadOrInitChunks(string const & fName, int64_t fileSize, int64_t chunkSize) int64_t ChunksDownloadStrategy::LoadOrInitChunks(std::string const & fName, int64_t fileSize, int64_t chunkSize)
{ {
ASSERT(fileSize > 0, ()); ASSERT(fileSize > 0, ());
@@ -161,10 +159,10 @@ int64_t ChunksDownloadStrategy::LoadOrInitChunks(string const & fName, int64_t f
return 0; return 0;
} }
string ChunksDownloadStrategy::ChunkFinished(bool success, RangeT const & range) std::string ChunksDownloadStrategy::ChunkFinished(bool success, RangeT const & range)
{ {
pair<ChunkT *, int> res = GetChunk(range); std::pair<ChunkT *, int> res = GetChunk(range);
string url; std::string url;
// find server which was downloading this chunk // find server which was downloading this chunk
if (res.first) if (res.first)
{ {
@@ -194,7 +192,7 @@ string ChunksDownloadStrategy::ChunkFinished(bool success, RangeT const & range)
return url; return url;
} }
ChunksDownloadStrategy::ResultT ChunksDownloadStrategy::NextChunk(string & outUrl, RangeT & range) ChunksDownloadStrategy::ResultT ChunksDownloadStrategy::NextChunk(std::string & outUrl, RangeT & range)
{ {
// If no servers at all. // If no servers at all.
if (m_servers.empty()) if (m_servers.empty())

View File

@@ -8,9 +8,7 @@
namespace platform namespace platform
{ {
using namespace std; std::string GetFileName(std::string const & countryName, MapFileType type)
string GetFileName(string const & countryName, MapFileType type)
{ {
ASSERT(!countryName.empty(), ()); ASSERT(!countryName.empty(), ());
@@ -34,9 +32,9 @@ CountryFile::CountryFile(std::string name, MwmSize size, std::string sha1)
, m_sha1(std::move(sha1)) , m_sha1(std::move(sha1))
{} {}
string DebugPrint(CountryFile const & file) std::string DebugPrint(CountryFile const & file)
{ {
ostringstream os; std::ostringstream os;
os << "CountryFile [" << file.m_name << "]"; os << "CountryFile [" << file.m_name << "]";
return os.str(); return os.str();
} }

View File

@@ -11,7 +11,7 @@
namespace platform namespace platform
{ {
using namespace std; using std::string;
namespace namespace
{ {

View File

@@ -6,10 +6,10 @@
#include <sstream> #include <sstream>
using namespace std;
namespace platform namespace platform
{ {
using std::string;
HttpClient::HttpClient(string const & url) : m_urlRequested(url) {} HttpClient::HttpClient(string const & url) : m_urlRequested(url) {}
bool HttpClient::RunHttpRequest(string & response, SuccessChecker checker /* = nullptr */) bool HttpClient::RunHttpRequest(string & response, SuccessChecker checker /* = nullptr */)
@@ -164,7 +164,7 @@ HttpClient::Headers const & HttpClient::GetHeaders() const
// static // static
string HttpClient::NormalizeServerCookies(string && cookies) string HttpClient::NormalizeServerCookies(string && cookies)
{ {
istringstream is(cookies); std::istringstream is(cookies);
string str, result; string str, result;
// Split by ", ". Can have invalid tokens here, expires= can also contain a comma. // Split by ", ". Can have invalid tokens here, expires= can also contain a comma.
@@ -195,7 +195,7 @@ string HttpClient::NormalizeServerCookies(string && cookies)
string DebugPrint(HttpClient const & request) string DebugPrint(HttpClient const & request)
{ {
ostringstream ostr; std::ostringstream ostr;
ostr << "HTTP " << request.ErrorCode() << " url [" << request.UrlRequested() << "]"; ostr << "HTTP " << request.ErrorCode() << " url [" << request.UrlRequested() << "]";
if (request.WasRedirected()) if (request.WasRedirected())
ostr << " was redirected to [" << request.UrlReceived() << "]"; ostr << " was redirected to [" << request.UrlReceived() << "]";

View File

@@ -19,12 +19,12 @@
#include "defines.hpp" #include "defines.hpp"
using namespace std;
class HttpThread; class HttpThread;
namespace downloader namespace downloader
{ {
using std::string;
namespace non_http_error_code namespace non_http_error_code
{ {
string DebugPrint(long errorCode) string DebugPrint(long errorCode)
@@ -37,7 +37,7 @@ string DebugPrint(long errorCode)
case kNonHttpResponse: return "Non-http response"; case kNonHttpResponse: return "Non-http response";
case kInvalidURL: return "Invalid URL"; case kInvalidURL: return "Invalid URL";
case kCancelled: return "Cancelled"; case kCancelled: return "Cancelled";
default: return to_string(errorCode); default: return std::to_string(errorCode);
} }
} }
} // namespace non_http_error_code } // namespace non_http_error_code
@@ -117,12 +117,12 @@ class FileHttpRequest
, public IHttpThreadCallback , public IHttpThreadCallback
{ {
ChunksDownloadStrategy m_strategy; ChunksDownloadStrategy m_strategy;
typedef pair<HttpThread *, int64_t> ThreadHandleT; typedef std::pair<HttpThread *, int64_t> ThreadHandleT;
typedef list<ThreadHandleT> ThreadsContainerT; typedef std::list<ThreadHandleT> ThreadsContainerT;
ThreadsContainerT m_threads; ThreadsContainerT m_threads;
string m_filePath; std::string m_filePath;
unique_ptr<FileWriter> m_writer; std::unique_ptr<FileWriter> m_writer;
bool m_doCleanProgressFiles; bool m_doCleanProgressFiles;
@@ -130,13 +130,13 @@ class FileHttpRequest
ChunksDownloadStrategy::ResultT StartThreads() ChunksDownloadStrategy::ResultT StartThreads()
{ {
string url; string url;
pair<int64_t, int64_t> range; std::pair<int64_t, int64_t> range;
ChunksDownloadStrategy::ResultT result; ChunksDownloadStrategy::ResultT result;
while ((result = m_strategy.NextChunk(url, range)) == ChunksDownloadStrategy::ENextChunk) while ((result = m_strategy.NextChunk(url, range)) == ChunksDownloadStrategy::ENextChunk)
{ {
HttpThread * p = CreateNativeHttpThread(url, *this, range.first, range.second, m_progress.m_bytesTotal); HttpThread * p = CreateNativeHttpThread(url, *this, range.first, range.second, m_progress.m_bytesTotal);
ASSERT(p, ()); ASSERT(p, ());
m_threads.push_back(make_pair(p, range.first)); m_threads.push_back(std::make_pair(p, range.first));
} }
return result; return result;
} }
@@ -208,7 +208,7 @@ class FileHttpRequest
#endif #endif
bool const isChunkOk = (httpOrErrorCode == 200); bool const isChunkOk = (httpOrErrorCode == 200);
string const urlError = m_strategy.ChunkFinished(isChunkOk, make_pair(begRange, endRange)); string const urlError = m_strategy.ChunkFinished(isChunkOk, std::make_pair(begRange, endRange));
// remove completed chunk from the list, beg is the key // remove completed chunk from the list, beg is the key
RemoveHttpThreadByKey(begRange); RemoveHttpThreadByKey(begRange);
@@ -275,8 +275,8 @@ class FileHttpRequest
} }
public: public:
FileHttpRequest(vector<string> const & urls, string const & filePath, int64_t fileSize, Callback && onFinish, FileHttpRequest(std::vector<std::string> const & urls, std::string const & filePath, int64_t fileSize,
Callback && onProgress, int64_t chunkSize, bool doCleanProgressFiles) Callback && onFinish, Callback && onProgress, int64_t chunkSize, bool doCleanProgressFiles)
: HttpRequest(std::move(onFinish), std::move(onProgress)) : HttpRequest(std::move(onFinish), std::move(onProgress))
, m_strategy(urls) , m_strategy(urls)
, m_filePath(filePath) , m_filePath(filePath)
@@ -303,7 +303,7 @@ public:
} }
// Create file and reserve needed size. // Create file and reserve needed size.
unique_ptr<FileWriter> writer(new FileWriter(filePath + DOWNLOADING_FILE_EXTENSION, openMode)); std::unique_ptr<FileWriter> writer(new FileWriter(filePath + DOWNLOADING_FILE_EXTENSION, openMode));
// Assign here, because previous functions can throw an exception. // Assign here, because previous functions can throw an exception.
m_writer.swap(writer); m_writer.swap(writer);
@@ -359,7 +359,7 @@ HttpRequest * HttpRequest::PostJson(string const & url, string const & postData,
return new MemoryHttpRequest(url, postData, std::move(onFinish), std::move(onProgress)); return new MemoryHttpRequest(url, postData, std::move(onFinish), std::move(onProgress));
} }
HttpRequest * HttpRequest::GetFile(vector<string> const & urls, string const & filePath, int64_t fileSize, HttpRequest * HttpRequest::GetFile(std::vector<string> const & urls, string const & filePath, int64_t fileSize,
Callback && onFinish, Callback && onProgress, int64_t chunkSize, Callback && onFinish, Callback && onProgress, int64_t chunkSize,
bool doCleanOnCancel) bool doCleanOnCancel)
{ {

View File

@@ -11,10 +11,8 @@
#include <QSslError> #include <QSslError>
#include <QUrl> #include <QUrl>
using namespace std; HttpThread::HttpThread(std::string const & url, downloader::IHttpThreadCallback & cb, int64_t beg, int64_t end,
int64_t size, std::string const & pb)
HttpThread::HttpThread(string const & url, downloader::IHttpThreadCallback & cb, int64_t beg, int64_t end, int64_t size,
string const & pb)
: m_callback(cb) : m_callback(cb)
, m_begRange(beg) , m_begRange(beg)
, m_endRange(end) , m_endRange(end)
@@ -145,8 +143,8 @@ void HttpThread::OnDownloadFinished()
namespace downloader namespace downloader
{ {
HttpThread * CreateNativeHttpThread(string const & url, downloader::IHttpThreadCallback & cb, int64_t beg, int64_t end, HttpThread * CreateNativeHttpThread(std::string const & url, downloader::IHttpThreadCallback & cb, int64_t beg,
int64_t size, string const & pb) int64_t end, int64_t size, std::string const & pb)
{ {
return new HttpThread(url, cb, beg, end, size, pb); return new HttpThread(url, cb, beg, end, size, pb);
} }

View File

@@ -16,11 +16,10 @@
namespace platform namespace platform
{ {
using namespace std;
LocalCountryFile::LocalCountryFile() : m_version(0) {} LocalCountryFile::LocalCountryFile() : m_version(0) {}
LocalCountryFile::LocalCountryFile(string directory, CountryFile countryFile, int64_t version) LocalCountryFile::LocalCountryFile(std::string directory, CountryFile countryFile, int64_t version)
: m_directory(std::move(directory)) : m_directory(std::move(directory))
, m_countryFile(std::move(countryFile)) , m_countryFile(std::move(countryFile))
, m_version(version) , m_version(version)
@@ -58,7 +57,7 @@ void LocalCountryFile::DeleteFromDisk(MapFileType type) const
LOG(LERROR, (type, "from", *this, "wasn't deleted from disk.")); LOG(LERROR, (type, "from", *this, "wasn't deleted from disk."));
} }
string LocalCountryFile::GetPath(MapFileType type) const std::string LocalCountryFile::GetPath(MapFileType type) const
{ {
return base::JoinPath(m_directory, GetFileName(type)); return base::JoinPath(m_directory, GetFileName(type));
} }
@@ -114,7 +113,7 @@ bool LocalCountryFile::ValidateIntegrity() const
} }
// static // static
LocalCountryFile LocalCountryFile::MakeForTesting(string countryFileName, int64_t version) LocalCountryFile LocalCountryFile::MakeForTesting(std::string countryFileName, int64_t version)
{ {
LocalCountryFile localFile(GetPlatform().WritableDir(), CountryFile(std::move(countryFileName)), version); LocalCountryFile localFile(GetPlatform().WritableDir(), CountryFile(std::move(countryFileName)), version);
localFile.SyncWithDisk(); localFile.SyncWithDisk();
@@ -122,18 +121,18 @@ LocalCountryFile LocalCountryFile::MakeForTesting(string countryFileName, int64_
} }
// static // static
LocalCountryFile LocalCountryFile::MakeTemporary(string const & fullPath) LocalCountryFile LocalCountryFile::MakeTemporary(std::string const & fullPath)
{ {
string name = fullPath; auto name = fullPath;
base::GetNameFromFullPath(name); base::GetNameFromFullPath(name);
base::GetNameWithoutExt(name); base::GetNameWithoutExt(name);
return LocalCountryFile(base::GetDirectory(fullPath), CountryFile(std::move(name)), 0 /* version */); return LocalCountryFile(base::GetDirectory(fullPath), CountryFile(std::move(name)), 0 /* version */);
} }
string DebugPrint(LocalCountryFile const & file) std::string DebugPrint(LocalCountryFile const & file)
{ {
ostringstream os; std::ostringstream os;
os << "LocalCountryFile [" << file.m_directory << ", " << DebugPrint(file.m_countryFile) << ", " << file.m_version os << "LocalCountryFile [" << file.m_directory << ", " << DebugPrint(file.m_countryFile) << ", " << file.m_version
<< ", ["; << ", [";

View File

@@ -25,7 +25,7 @@
namespace platform namespace platform
{ {
using namespace std; using std::string;
namespace namespace
{ {
@@ -42,8 +42,8 @@ bool IsSpecialName(string const & name) { return name == "." || name == ".."; }
*/ */
bool IsDownloaderFile(string const & name) bool IsDownloaderFile(string const & name)
{ {
static regex const filter(".*\\.(downloading|resume|ready)[0-9]?$"); static std::regex const filter(".*\\.(downloading|resume|ready)[0-9]?$");
return regex_match(name.begin(), name.end(), filter); return std::regex_match(name.begin(), name.end(), filter);
} }
bool IsDiffFile(string const & name) bool IsDiffFile(string const & name)
@@ -80,7 +80,7 @@ inline string GetDataDirFullPath(string const & dataDir)
return dataDir.empty() ? platform.WritableDir() : base::JoinPath(platform.WritableDir(), dataDir); return dataDir.empty() ? platform.WritableDir() : base::JoinPath(platform.WritableDir(), dataDir);
} }
void FindAllDiffsInDirectory(string const & dir, vector<LocalCountryFile> & diffs) void FindAllDiffsInDirectory(string const & dir, std::vector<LocalCountryFile> & diffs)
{ {
Platform & platform = GetPlatform(); Platform & platform = GetPlatform();
@@ -139,7 +139,7 @@ void DeleteDownloaderFilesForCountry(int64_t version, string const & dataDir, Co
} }
size_t FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t version, int64_t latestVersion, size_t FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t version, int64_t latestVersion,
vector<LocalCountryFile> & localFiles) std::vector<LocalCountryFile> & localFiles)
{ {
Platform & platform = GetPlatform(); Platform & platform = GetPlatform();
size_t const szBefore = localFiles.size(); size_t const szBefore = localFiles.size();
@@ -192,7 +192,7 @@ size_t FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t v
*/ */
} }
void FindAllDiffs(string const & dataDir, vector<LocalCountryFile> & diffs) void FindAllDiffs(std::string const & dataDir, std::vector<LocalCountryFile> & diffs)
{ {
string const dir = GetDataDirFullPath(dataDir); string const dir = GetDataDirFullPath(dataDir);
FindAllDiffsInDirectory(dir, diffs); FindAllDiffsInDirectory(dir, diffs);
@@ -204,12 +204,13 @@ void FindAllDiffs(string const & dataDir, vector<LocalCountryFile> & diffs)
FindAllDiffsInDirectory(base::JoinPath(dir, fwt.first /* subdir */), diffs); FindAllDiffsInDirectory(base::JoinPath(dir, fwt.first /* subdir */), diffs);
} }
void FindAllLocalMapsAndCleanup(int64_t latestVersion, vector<LocalCountryFile> & localFiles) void FindAllLocalMapsAndCleanup(int64_t latestVersion, std::vector<LocalCountryFile> & localFiles)
{ {
FindAllLocalMapsAndCleanup(latestVersion, string(), localFiles); FindAllLocalMapsAndCleanup(latestVersion, string(), localFiles);
} }
void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir, vector<LocalCountryFile> & localFiles) void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir,
std::vector<LocalCountryFile> & localFiles)
{ {
string const dir = GetDataDirFullPath(dataDir); string const dir = GetDataDirFullPath(dataDir);
@@ -275,7 +276,7 @@ void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir, v
void CleanupMapsDirectory(int64_t latestVersion) void CleanupMapsDirectory(int64_t latestVersion)
{ {
vector<LocalCountryFile> localFiles; std::vector<LocalCountryFile> localFiles;
FindAllLocalMapsAndCleanup(latestVersion, localFiles); FindAllLocalMapsAndCleanup(latestVersion, localFiles);
} }
@@ -296,13 +297,13 @@ bool ParseVersion(string const & s, int64_t & version)
return true; return true;
} }
shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(int64_t version, CountryFile const & countryFile) std::shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(int64_t version, CountryFile const & countryFile)
{ {
return PreparePlaceForCountryFiles(version, string(), countryFile); return PreparePlaceForCountryFiles(version, string(), countryFile);
} }
shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(int64_t version, string const & dataDir, std::shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(int64_t version, string const & dataDir,
CountryFile const & countryFile) CountryFile const & countryFile)
{ {
string const dir = PrepareDirToDownloadCountry(version, dataDir); string const dir = PrepareDirToDownloadCountry(version, dataDir);
return (!dir.empty() ? make_shared<LocalCountryFile>(dir, countryFile, version) : nullptr); return (!dir.empty() ? make_shared<LocalCountryFile>(dir, countryFile, version) : nullptr);
@@ -322,7 +323,7 @@ string GetFileDownloadPath(int64_t version, string const & dataDir, string const
return GetFilePath(version, dataDir, countryName, type) + READY_FILE_EXTENSION; return GetFilePath(version, dataDir, countryName, type) + READY_FILE_EXTENSION;
} }
unique_ptr<ModelReader> GetCountryReader(LocalCountryFile const & file, MapFileType type) std::unique_ptr<ModelReader> GetCountryReader(LocalCountryFile const & file, MapFileType type)
{ {
Platform & platform = GetPlatform(); Platform & platform = GetPlatform();
if (file.IsInBundle()) if (file.IsInBundle())
@@ -378,7 +379,7 @@ string CountryIndexes::GetPath(LocalCountryFile const & localFile, Index index)
} }
// static // static
void CountryIndexes::GetIndexesExts(vector<string> & exts) void CountryIndexes::GetIndexesExts(std::vector<string> & exts)
{ {
exts.push_back(kBitsExt); exts.push_back(kBitsExt);
exts.push_back(kNodesExt); exts.push_back(kNodesExt);

View File

@@ -18,8 +18,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> // for sysconf #include <unistd.h> // for sysconf
using namespace std;
Platform::Platform() Platform::Platform()
{ {
/// @see initialization routine in android/sdk/src/main/cpp/com/.../Platform.hpp /// @see initialization routine in android/sdk/src/main/cpp/com/.../Platform.hpp
@@ -31,22 +29,22 @@ namespace
class DbgLogger class DbgLogger
{ {
public: public:
explicit DbgLogger(string const & file) : m_file(file) {} explicit DbgLogger(std::string const & file) : m_file(file) {}
~DbgLogger() { LOG(LDEBUG, ("Source for file", m_file, "is", m_src)); } ~DbgLogger() { LOG(LDEBUG, ("Source for file", m_file, "is", m_src)); }
void SetSource(char src) { m_src = src; } void SetSource(char src) { m_src = src; }
private: private:
string const & m_file; std::string const & m_file;
char m_src; char m_src;
}; };
} // namespace } // namespace
#endif #endif
unique_ptr<ModelReader> Platform::GetReader(string const & file, string searchScope) const std::unique_ptr<ModelReader> Platform::GetReader(std::string const & file, std::string searchScope) const
{ {
string ext = base::GetFileExtension(file); std::string ext = base::GetFileExtension(file);
strings::AsciiToLower(ext); strings::AsciiToLower(ext);
ASSERT(!ext.empty(), ()); ASSERT(!ext.empty(), ());
@@ -87,17 +85,17 @@ unique_ptr<ModelReader> Platform::GetReader(string const & file, string searchSc
{ {
case 'w': case 'w':
{ {
string const path = base::JoinPath(m_writableDir, file); auto const path = base::JoinPath(m_writableDir, file);
if (IsFileExistsByFullPath(path)) if (IsFileExistsByFullPath(path))
return make_unique<FileReader>(path, logPageSize, logPageCount); return std::make_unique<FileReader>(path, logPageSize, logPageCount);
break; break;
} }
case 's': case 's':
{ {
string const path = base::JoinPath(m_settingsDir, file); auto const path = base::JoinPath(m_settingsDir, file);
if (IsFileExistsByFullPath(path)) if (IsFileExistsByFullPath(path))
return make_unique<FileReader>(path, logPageSize, logPageCount); return std::make_unique<FileReader>(path, logPageSize, logPageCount);
break; break;
} }
@@ -107,7 +105,7 @@ unique_ptr<ModelReader> Platform::GetReader(string const & file, string searchSc
break; break;
case 'r': case 'r':
ASSERT_EQUAL(file.find("assets/"), string::npos, ()); ASSERT_EQUAL(file.find("assets/"), std::string::npos, ());
try try
{ {
return make_unique<ZipFileReader>(m_resourcesDir, "assets/" + file, logPageSize, logPageCount); return make_unique<ZipFileReader>(m_resourcesDir, "assets/" + file, logPageSize, logPageCount);
@@ -127,7 +125,7 @@ unique_ptr<ModelReader> Platform::GetReader(string const & file, string searchSc
return nullptr; return nullptr;
} }
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res) void Platform::GetFilesByRegExp(std::string const & directory, std::string const & regexp, FilesList & res)
{ {
if (ZipFileReader::IsZip(directory)) if (ZipFileReader::IsZip(directory))
{ {
@@ -136,12 +134,12 @@ void Platform::GetFilesByRegExp(string const & directory, string const & regexp,
FilesT fList; FilesT fList;
ZipFileReader::FilesList(directory, fList); ZipFileReader::FilesList(directory, fList);
regex exp(regexp); std::regex exp(regexp);
for (FilesT::iterator it = fList.begin(); it != fList.end(); ++it) for (FilesT::iterator it = fList.begin(); it != fList.end(); ++it)
{ {
string & name = it->first; std::string & name = it->first;
if (regex_search(name.begin(), name.end(), exp)) if (std::regex_search(name.begin(), name.end(), exp))
{ {
// Remove assets/ prefix - clean files are needed for fonts white/blacklisting logic // Remove assets/ prefix - clean files are needed for fonts white/blacklisting logic
size_t const ASSETS_LENGTH = 7; size_t const ASSETS_LENGTH = 7;
@@ -166,7 +164,7 @@ int Platform::PreCachingDepth() const
return 3; return 3;
} }
bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const bool Platform::GetFileSizeByName(std::string const & fileName, uint64_t & size) const
{ {
try try
{ {
@@ -181,7 +179,7 @@ bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
} }
// static // static
Platform::EError Platform::MkDir(string const & dirName) Platform::EError Platform::MkDir(std::string const & dirName)
{ {
if (0 != mkdir(dirName.c_str(), 0755)) if (0 != mkdir(dirName.c_str(), 0755))
return ErrnoToError(); return ErrnoToError();
@@ -202,16 +200,16 @@ void Platform::GetSystemFontNames(FilesList & res) const
{ {
bool wasRoboto = false; bool wasRoboto = false;
string const path = "/system/fonts/"; std::string const path = "/system/fonts/";
pl::EnumerateFiles(path, [&](char const * entry) pl::EnumerateFiles(path, [&](char const * entry)
{ {
string name(entry); std::string name(entry);
if (name != "Roboto-Medium.ttf" && name != "Roboto-Regular.ttf") if (name != "Roboto-Medium.ttf" && name != "Roboto-Regular.ttf")
{ {
if (!name.starts_with("NotoNaskh") && !name.starts_with("NotoSans")) if (!name.starts_with("NotoNaskh") && !name.starts_with("NotoSans"))
return; return;
if (name.find("-Regular") == string::npos) if (name.find("-Regular") == std::string::npos)
return; return;
} }
else else
@@ -222,7 +220,7 @@ void Platform::GetSystemFontNames(FilesList & res) const
if (!wasRoboto) if (!wasRoboto)
{ {
string droidSans = path + "DroidSans.ttf"; std::string droidSans = path + "DroidSans.ttf";
if (IsFileExistsByFullPath(droidSans)) if (IsFileExistsByFullPath(droidSans))
res.push_back(std::move(droidSans)); res.push_back(std::move(droidSans));
} }

View File

@@ -7,8 +7,6 @@
#include <string> #include <string>
using namespace std;
namespace platform namespace platform
{ {
UNIT_TEST(CountryFile_Smoke) UNIT_TEST(CountryFile_Smoke)
@@ -16,7 +14,7 @@ UNIT_TEST(CountryFile_Smoke)
{ {
CountryFile cf("One"); CountryFile cf("One");
TEST_EQUAL("One", cf.GetName(), ()); TEST_EQUAL("One", cf.GetName(), ());
string const mapFileName = cf.GetFileName(MapFileType::Map); auto const mapFileName = cf.GetFileName(MapFileType::Map);
TEST_EQUAL("One" DATA_FILE_EXTENSION, mapFileName, ()); TEST_EQUAL("One" DATA_FILE_EXTENSION, mapFileName, ());
TEST_EQUAL(0, cf.GetRemoteSize(), ()); TEST_EQUAL(0, cf.GetRemoteSize(), ());
@@ -25,7 +23,7 @@ UNIT_TEST(CountryFile_Smoke)
{ {
CountryFile cf("Three", 666, "xxxSHAxxx"); CountryFile cf("Three", 666, "xxxSHAxxx");
TEST_EQUAL("Three", cf.GetName(), ()); TEST_EQUAL("Three", cf.GetName(), ());
string const mapFileName = cf.GetFileName(MapFileType::Map); auto const mapFileName = cf.GetFileName(MapFileType::Map);
TEST_EQUAL("Three" DATA_FILE_EXTENSION, mapFileName, ()); TEST_EQUAL("Three" DATA_FILE_EXTENSION, mapFileName, ());
TEST_EQUAL(666, cf.GetRemoteSize(), ()); TEST_EQUAL(666, cf.GetRemoteSize(), ());

View File

@@ -23,7 +23,7 @@ namespace downloader_test
{ {
using namespace downloader; using namespace downloader;
using namespace std::placeholders; using namespace std::placeholders;
using namespace std; using std::bind, std::string, std::vector;
char constexpr kTestUrl1[] = "http://localhost:34568/unit_tests/1.txt"; char constexpr kTestUrl1[] = "http://localhost:34568/unit_tests/1.txt";
char constexpr kTestUrl404[] = "http://localhost:34568/unit_tests/notexisting_unittest"; char constexpr kTestUrl404[] = "http://localhost:34568/unit_tests/notexisting_unittest";
@@ -125,7 +125,7 @@ struct DeleteOnFinish
UNIT_TEST(DownloaderSimpleGet) UNIT_TEST(DownloaderSimpleGet)
{ {
DownloadObserver observer; DownloadObserver observer;
auto const MakeRequest = [&observer](std::string const & url) auto const MakeRequest = [&observer](string const & url)
{ {
return HttpRequest::Get(url, bind(&DownloadObserver::OnDownloadFinish, &observer, _1), return HttpRequest::Get(url, bind(&DownloadObserver::OnDownloadFinish, &observer, _1),
bind(&DownloadObserver::OnDownloadProgress, &observer, _1)); bind(&DownloadObserver::OnDownloadProgress, &observer, _1));
@@ -133,7 +133,7 @@ UNIT_TEST(DownloaderSimpleGet)
{ {
// simple success case // simple success case
unique_ptr<HttpRequest> const request{MakeRequest(kTestUrl1)}; std::unique_ptr<HttpRequest> const request{MakeRequest(kTestUrl1)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestOk(); observer.TestOk();
@@ -143,7 +143,7 @@ UNIT_TEST(DownloaderSimpleGet)
observer.Reset(); observer.Reset();
{ {
// We DO NOT SUPPORT redirects to avoid data corruption when downloading mwm files // We DO NOT SUPPORT redirects to avoid data corruption when downloading mwm files
unique_ptr<HttpRequest> const request{MakeRequest("http://localhost:34568/unit_tests/permanent")}; std::unique_ptr<HttpRequest> const request{MakeRequest("http://localhost:34568/unit_tests/permanent")};
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestFailed(); observer.TestFailed();
TEST_EQUAL(request->GetData().size(), 0, (request->GetData())); TEST_EQUAL(request->GetData().size(), 0, (request->GetData()));
@@ -152,7 +152,7 @@ UNIT_TEST(DownloaderSimpleGet)
observer.Reset(); observer.Reset();
{ {
// fail case 404 // fail case 404
unique_ptr<HttpRequest> const request{MakeRequest(kTestUrl404)}; std::unique_ptr<HttpRequest> const request{MakeRequest(kTestUrl404)};
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestFileNotFound(); observer.TestFileNotFound();
TEST_EQUAL(request->GetData().size(), 0, (request->GetData())); TEST_EQUAL(request->GetData().size(), 0, (request->GetData()));
@@ -161,7 +161,7 @@ UNIT_TEST(DownloaderSimpleGet)
observer.Reset(); observer.Reset();
{ {
// fail case not existing host // fail case not existing host
unique_ptr<HttpRequest> const request{MakeRequest("http://not-valid-host123532.ath.cx")}; std::unique_ptr<HttpRequest> const request{MakeRequest("http://not-valid-host123532.ath.cx")};
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestFailed(); observer.TestFailed();
TEST_EQUAL(request->GetData().size(), 0, (request->GetData())); TEST_EQUAL(request->GetData().size(), 0, (request->GetData()));
@@ -179,7 +179,7 @@ UNIT_TEST(DownloaderSimpleGet)
observer.Reset(); observer.Reset();
{ {
// https success case // https success case
unique_ptr<HttpRequest> const request{MakeRequest("https://github.com")}; std::unique_ptr<HttpRequest> const request{MakeRequest("https://github.com")};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestOk(); observer.TestOk();
@@ -203,7 +203,7 @@ UNIT_TEST(DownloaderSimplePost)
// simple success case // simple success case
string const postData = "{\"jsonKey\":\"jsonValue\"}"; string const postData = "{\"jsonKey\":\"jsonValue\"}";
DownloadObserver observer; DownloadObserver observer;
unique_ptr<HttpRequest> const request{HttpRequest::PostJson( std::unique_ptr<HttpRequest> const request{HttpRequest::PostJson(
"http://localhost:34568/unit_tests/post.php", postData, bind(&DownloadObserver::OnDownloadFinish, &observer, _1), "http://localhost:34568/unit_tests/post.php", postData, bind(&DownloadObserver::OnDownloadFinish, &observer, _1),
bind(&DownloadObserver::OnDownloadProgress, &observer, _1))}; bind(&DownloadObserver::OnDownloadProgress, &observer, _1))};
// wait until download is finished // wait until download is finished
@@ -217,7 +217,7 @@ UNIT_TEST(ChunksDownloadStrategy)
{ {
vector<string> const servers = {"UrlOfServer1", "UrlOfServer2", "UrlOfServer3"}; vector<string> const servers = {"UrlOfServer1", "UrlOfServer2", "UrlOfServer3"};
typedef pair<int64_t, int64_t> RangeT; typedef std::pair<int64_t, int64_t> RangeT;
RangeT const R1{0, 249}, R2{250, 499}, R3{500, 749}, R4{750, 800}; RangeT const R1{0, 249}, R2{250, 499}, R3{500, 749}, R4{750, 800};
int64_t constexpr kFileSize = 800; int64_t constexpr kFileSize = 800;
@@ -291,7 +291,7 @@ UNIT_TEST(ChunksDownloadStrategyFAIL)
{ {
vector<string> const servers = {"UrlOfServer1", "UrlOfServer2"}; vector<string> const servers = {"UrlOfServer1", "UrlOfServer2"};
typedef pair<int64_t, int64_t> RangeT; typedef std::pair<int64_t, int64_t> RangeT;
int64_t constexpr kFileSize = 800; int64_t constexpr kFileSize = 800;
int64_t constexpr kChunkSize = 250; int64_t constexpr kChunkSize = 250;
@@ -367,7 +367,7 @@ string ReadFileAsString(string const & file)
catch (FileReader::Exception const &) catch (FileReader::Exception const &)
{ {
TEST(false, ("File ", file, " should exist")); TEST(false, ("File ", file, " should exist"));
return string(); return {};
} }
} // namespace } // namespace
@@ -423,7 +423,7 @@ UNIT_TEST(DownloadChunks)
{ {
// should use only one thread // should use only one thread
unique_ptr<HttpRequest> const request{MakeRequest(512 * 1024)}; std::unique_ptr<HttpRequest> const request{MakeRequest(512 * 1024)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestOk(); observer.TestOk();
@@ -437,7 +437,7 @@ UNIT_TEST(DownloadChunks)
fileSize = 5; fileSize = 5;
{ {
// 3 threads - fail, because of invalid size // 3 threads - fail, because of invalid size
[[maybe_unused]] unique_ptr<HttpRequest> const request{MakeRequest(2048)}; [[maybe_unused]] std::unique_ptr<HttpRequest> const request{MakeRequest(2048)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestFailed(); observer.TestFailed();
@@ -449,7 +449,7 @@ UNIT_TEST(DownloadChunks)
fileSize = kBigFileSize; fileSize = kBigFileSize;
{ {
// 3 threads - succeeded // 3 threads - succeeded
[[maybe_unused]] unique_ptr<HttpRequest> const request{MakeRequest(2048)}; [[maybe_unused]] std::unique_ptr<HttpRequest> const request{MakeRequest(2048)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestOk(); observer.TestOk();
@@ -461,7 +461,7 @@ UNIT_TEST(DownloadChunks)
fileSize = kBigFileSize; fileSize = kBigFileSize;
{ {
// 3 threads with only one valid url - succeeded // 3 threads with only one valid url - succeeded
[[maybe_unused]] unique_ptr<HttpRequest> const request{MakeRequest(2048)}; [[maybe_unused]] std::unique_ptr<HttpRequest> const request{MakeRequest(2048)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestOk(); observer.TestOk();
@@ -473,7 +473,7 @@ UNIT_TEST(DownloadChunks)
fileSize = 12345; fileSize = 12345;
{ {
// 2 threads and all points to file with invalid size - fail // 2 threads and all points to file with invalid size - fail
[[maybe_unused]] unique_ptr<HttpRequest> const request{MakeRequest(2048)}; [[maybe_unused]] std::unique_ptr<HttpRequest> const request{MakeRequest(2048)};
// wait until download is finished // wait until download is finished
QCoreApplication::exec(); QCoreApplication::exec();
observer.TestFailed(); observer.TestFailed();
@@ -532,7 +532,7 @@ UNIT_TEST(DownloadResumeChunks)
{ {
DownloadObserver observer; DownloadObserver observer;
unique_ptr<HttpRequest> const request( std::unique_ptr<HttpRequest> const request(
HttpRequest::GetFile(urls, FILENAME, kBigFileSize, bind(&DownloadObserver::OnDownloadFinish, &observer, _1), HttpRequest::GetFile(urls, FILENAME, kBigFileSize, bind(&DownloadObserver::OnDownloadFinish, &observer, _1),
bind(&DownloadObserver::OnDownloadProgress, &observer, _1))); bind(&DownloadObserver::OnDownloadProgress, &observer, _1)));
@@ -559,10 +559,10 @@ UNIT_TEST(DownloadResumeChunks)
f.Write(b2, ARRAY_SIZE(b2)); f.Write(b2, ARRAY_SIZE(b2));
ChunksDownloadStrategy strategy((vector<string>())); ChunksDownloadStrategy strategy((vector<string>()));
strategy.AddChunk(make_pair(int64_t(0), beg1 - 1), ChunksDownloadStrategy::CHUNK_COMPLETE); strategy.AddChunk(std::make_pair(int64_t(0), beg1 - 1), ChunksDownloadStrategy::CHUNK_COMPLETE);
strategy.AddChunk(make_pair(beg1, end1), ChunksDownloadStrategy::CHUNK_FREE); strategy.AddChunk(std::make_pair(beg1, end1), ChunksDownloadStrategy::CHUNK_FREE);
strategy.AddChunk(make_pair(end1 + 1, beg2 - 1), ChunksDownloadStrategy::CHUNK_COMPLETE); strategy.AddChunk(std::make_pair(end1 + 1, beg2 - 1), ChunksDownloadStrategy::CHUNK_COMPLETE);
strategy.AddChunk(make_pair(beg2, end2), ChunksDownloadStrategy::CHUNK_FREE); strategy.AddChunk(std::make_pair(beg2, end2), ChunksDownloadStrategy::CHUNK_FREE);
strategy.SaveChunks(kBigFileSize, RESUME_FILENAME); strategy.SaveChunks(kBigFileSize, RESUME_FILENAME);
} }
@@ -570,9 +570,9 @@ UNIT_TEST(DownloadResumeChunks)
// 3rd step - check that resume works // 3rd step - check that resume works
{ {
ResumeChecker checker; ResumeChecker checker;
unique_ptr<HttpRequest> const request(HttpRequest::GetFile(urls, FILENAME, kBigFileSize, std::unique_ptr<HttpRequest> const request(HttpRequest::GetFile(urls, FILENAME, kBigFileSize,
bind(&ResumeChecker::OnFinish, &checker, _1), bind(&ResumeChecker::OnFinish, &checker, _1),
bind(&ResumeChecker::OnProgress, &checker, _1))); bind(&ResumeChecker::OnProgress, &checker, _1)));
QCoreApplication::exec(); QCoreApplication::exec();
FinishDownloadSuccess(FILENAME); FinishDownloadSuccess(FILENAME);
@@ -598,7 +598,7 @@ UNIT_TEST(DownloadResumeChunksWithCancel)
if (arrCancelChunks[i] > 0) if (arrCancelChunks[i] > 0)
observer.CancelDownloadOnGivenChunk(arrCancelChunks[i]); observer.CancelDownloadOnGivenChunk(arrCancelChunks[i]);
unique_ptr<HttpRequest> const request( std::unique_ptr<HttpRequest> const request(
HttpRequest::GetFile(urls, FILENAME, kBigFileSize, bind(&DownloadObserver::OnDownloadFinish, &observer, _1), HttpRequest::GetFile(urls, FILENAME, kBigFileSize, bind(&DownloadObserver::OnDownloadFinish, &observer, _1),
bind(&DownloadObserver::OnDownloadProgress, &observer, _1), 1024, false)); bind(&DownloadObserver::OnDownloadProgress, &observer, _1), 1024, false));

View File

@@ -4,12 +4,9 @@
#include <string> #include <string>
using namespace platform;
using namespace std;
UNIT_TEST(GetTextByIdEnglishTest) UNIT_TEST(GetTextByIdEnglishTest)
{ {
string const shortJson = std::string const shortJson =
"\ "\
{\ {\
\"make_a_slight_right_turn\":\"Make a slight right turn.\",\ \"make_a_slight_right_turn\":\"Make a slight right turn.\",\
@@ -32,7 +29,7 @@ UNIT_TEST(GetTextByIdEnglishTest)
UNIT_TEST(GetTextByIdRussianTest) UNIT_TEST(GetTextByIdRussianTest)
{ {
string const shortJson = std::string const shortJson =
"\ "\
{\ {\
\"in_800_meters\":\"Через восемьсот метров.\",\ \"in_800_meters\":\"Через восемьсот метров.\",\
@@ -55,7 +52,7 @@ UNIT_TEST(GetTextByIdRussianTest)
UNIT_TEST(GetTextByIdKoreanTest) UNIT_TEST(GetTextByIdKoreanTest)
{ {
string const shortJson = std::string const shortJson =
"\ "\
{\ {\
\"in_700_meters\":\"700 미터 앞\",\ \"in_700_meters\":\"700 미터 앞\",\
@@ -78,7 +75,7 @@ UNIT_TEST(GetTextByIdKoreanTest)
UNIT_TEST(GetTextByIdArabicTest) UNIT_TEST(GetTextByIdArabicTest)
{ {
string const shortJson = std::string const shortJson =
"\ "\
{\ {\
\"in_1_kilometer\":\"بعد كيلو متر واحدٍ\",\ \"in_1_kilometer\":\"بعد كيلو متر واحدٍ\",\
@@ -101,7 +98,7 @@ UNIT_TEST(GetTextByIdArabicTest)
UNIT_TEST(GetTextByIdFrenchTest) UNIT_TEST(GetTextByIdFrenchTest)
{ {
string const shortJson = std::string const shortJson =
"\ "\
{\ {\
\"in_1_5_kilometers\":\"Dans un virgule cinq kilomètre.\",\ \"in_1_5_kilometers\":\"Dans un virgule cinq kilomètre.\",\

View File

@@ -25,14 +25,17 @@
namespace local_country_file_tests namespace local_country_file_tests
{ {
using namespace platform; using platform::CountryFile;
using namespace platform::tests_support; using platform::LocalCountryFile;
using namespace std; using platform::tests_support::ScopedDir;
using platform::tests_support::ScopedFile;
// Checks that all unsigned numbers less than 10 ^ 18 can be parsed as // Checks that all unsigned numbers less than 10 ^ 18 can be parsed as
// a timestamp. // a timestamp.
UNIT_TEST(LocalCountryFile_ParseVersion) UNIT_TEST(LocalCountryFile_ParseVersion)
{ {
using namespace platform;
int64_t version = 0; int64_t version = 0;
TEST(ParseVersion("1", version), ()); TEST(ParseVersion("1", version), ());
TEST_EQUAL(version, 1, ()); TEST_EQUAL(version, 1, ());
@@ -88,8 +91,8 @@ UNIT_TEST(LocalCountryFile_DiskFiles)
TEST(!localFile.OnDisk(MapFileType::Map), ()); TEST(!localFile.OnDisk(MapFileType::Map), ());
TEST(!localFile.OnDisk(MapFileType::Diff), ()); TEST(!localFile.OnDisk(MapFileType::Diff), ());
string const mapFileName = countryFile.GetFileName(MapFileType::Map); std::string const mapFileName = countryFile.GetFileName(MapFileType::Map);
string const mapFileContents("map"); std::string const mapFileContents("map");
ScopedFile testMapFile(mapFileName, mapFileContents); ScopedFile testMapFile(mapFileName, mapFileContents);
localFile.SyncWithDisk(); localFile.SyncWithDisk();
@@ -110,7 +113,7 @@ UNIT_TEST(LocalCountryFile_DiskFiles)
UNIT_TEST(LocalCountryFile_CleanupMapFiles) UNIT_TEST(LocalCountryFile_CleanupMapFiles)
{ {
Platform & platform = GetPlatform(); Platform & platform = GetPlatform();
string const mapsDir = platform.WritableDir(); std::string const mapsDir = platform.WritableDir();
// Two fake directories for test country files and indexes. // Two fake directories for test country files and indexes.
ScopedDir dir3("3"); ScopedDir dir3("3");
@@ -125,7 +128,7 @@ UNIT_TEST(LocalCountryFile_CleanupMapFiles)
ScopedFile irelandMapFile(dir4, irelandFile, MapFileType::Map); ScopedFile irelandMapFile(dir4, irelandFile, MapFileType::Map);
// Check FindAllLocalMaps() // Check FindAllLocalMaps()
vector<LocalCountryFile> localFiles; std::vector<LocalCountryFile> localFiles;
FindAllLocalMapsAndCleanup(4 /* latestVersion */, localFiles); FindAllLocalMapsAndCleanup(4 /* latestVersion */, localFiles);
TEST(base::IsExist(localFiles, irelandLocalFile), (irelandLocalFile, localFiles)); TEST(base::IsExist(localFiles, irelandLocalFile), (irelandLocalFile, localFiles));
@@ -168,7 +171,7 @@ UNIT_TEST(LocalCountryFile_CleanupPartiallyDownloadedFiles)
{DataFilePath("Spain.mwm.routing"), ScopedFile::Mode::Create}, {DataFilePath("Spain.mwm.routing"), ScopedFile::Mode::Create},
{base::JoinPath(latestDir.GetRelativePath(), "Russia_Southern.mwm.downloading"), ScopedFile::Mode::Create}}; {base::JoinPath(latestDir.GetRelativePath(), "Russia_Southern.mwm.downloading"), ScopedFile::Mode::Create}};
CleanupMapsDirectory(101010 /* latestVersion */); platform::CleanupMapsDirectory(101010 /* latestVersion */);
for (ScopedFile & file : toBeDeleted) for (ScopedFile & file : toBeDeleted)
{ {
@@ -202,10 +205,10 @@ UNIT_TEST(LocalCountryFile_DirectoryLookup)
ScopedFile testIrelandMapFile(testDir, irelandFile, MapFileType::Map); ScopedFile testIrelandMapFile(testDir, irelandFile, MapFileType::Map);
ScopedFile testNetherlandsMapFile(testDir, netherlandsFile, MapFileType::Map); ScopedFile testNetherlandsMapFile(testDir, netherlandsFile, MapFileType::Map);
vector<LocalCountryFile> localFiles; std::vector<LocalCountryFile> localFiles;
FindAllLocalMapsInDirectoryAndCleanup(testDir.GetFullPath(), 150309 /* version */, -1 /* latestVersion */, FindAllLocalMapsInDirectoryAndCleanup(testDir.GetFullPath(), 150309 /* version */, -1 /* latestVersion */,
localFiles); localFiles);
sort(localFiles.begin(), localFiles.end()); std::sort(localFiles.begin(), localFiles.end());
for (LocalCountryFile & localFile : localFiles) for (LocalCountryFile & localFile : localFiles)
localFile.SyncWithDisk(); localFile.SyncWithDisk();
@@ -215,8 +218,8 @@ UNIT_TEST(LocalCountryFile_DirectoryLookup)
LocalCountryFile expectedNetherlandsFile(testDir.GetFullPath(), netherlandsFile, 150309); LocalCountryFile expectedNetherlandsFile(testDir.GetFullPath(), netherlandsFile, 150309);
expectedNetherlandsFile.SyncWithDisk(); expectedNetherlandsFile.SyncWithDisk();
vector<LocalCountryFile> expectedLocalFiles = {expectedIrelandFile, expectedNetherlandsFile}; std::vector expectedLocalFiles = {expectedIrelandFile, expectedNetherlandsFile};
sort(expectedLocalFiles.begin(), expectedLocalFiles.end()); std::sort(expectedLocalFiles.begin(), expectedLocalFiles.end());
TEST_EQUAL(expectedLocalFiles, localFiles, ()); TEST_EQUAL(expectedLocalFiles, localFiles, ());
} }
@@ -234,9 +237,9 @@ UNIT_TEST(LocalCountryFile_AllLocalFilesLookup)
ScopedFile testItalyMapFile(testDir, italyFile, MapFileType::Map); ScopedFile testItalyMapFile(testDir, italyFile, MapFileType::Map);
vector<LocalCountryFile> localFiles; std::vector<LocalCountryFile> localFiles;
FindAllLocalMapsAndCleanup(10101 /* latestVersion */, localFiles); FindAllLocalMapsAndCleanup(10101 /* latestVersion */, localFiles);
multiset<LocalCountryFile> localFilesSet(localFiles.begin(), localFiles.end()); std::multiset<LocalCountryFile> localFilesSet(localFiles.begin(), localFiles.end());
bool worldFound = false; bool worldFound = false;
bool worldCoastsFound = false; bool worldCoastsFound = false;
@@ -267,7 +270,7 @@ UNIT_TEST(LocalCountryFile_PreparePlaceForCountryFiles)
CountryFile italyFile("Italy"); CountryFile italyFile("Italy");
LocalCountryFile expectedItalyFile(platform.WritableDir(), italyFile, 0 /* version */); LocalCountryFile expectedItalyFile(platform.WritableDir(), italyFile, 0 /* version */);
shared_ptr<LocalCountryFile> italyLocalFile = PreparePlaceForCountryFiles(0 /* version */, italyFile); auto italyLocalFile = PreparePlaceForCountryFiles(0 /* version */, italyFile);
TEST(italyLocalFile.get(), ()); TEST(italyLocalFile.get(), ());
TEST_EQUAL(expectedItalyFile, *italyLocalFile, ()); TEST_EQUAL(expectedItalyFile, *italyLocalFile, ());
@@ -275,19 +278,21 @@ UNIT_TEST(LocalCountryFile_PreparePlaceForCountryFiles)
CountryFile germanyFile("Germany"); CountryFile germanyFile("Germany");
LocalCountryFile expectedGermanyFile(directoryForV1.GetFullPath(), germanyFile, 1 /* version */); LocalCountryFile expectedGermanyFile(directoryForV1.GetFullPath(), germanyFile, 1 /* version */);
shared_ptr<LocalCountryFile> germanyLocalFile = PreparePlaceForCountryFiles(1 /* version */, germanyFile); auto germanyLocalFile = PreparePlaceForCountryFiles(1 /* version */, germanyFile);
TEST(germanyLocalFile.get(), ()); TEST(germanyLocalFile.get(), ());
TEST_EQUAL(expectedGermanyFile, *germanyLocalFile, ()); TEST_EQUAL(expectedGermanyFile, *germanyLocalFile, ());
CountryFile franceFile("France"); CountryFile franceFile("France");
LocalCountryFile expectedFranceFile(directoryForV1.GetFullPath(), franceFile, 1 /* version */); LocalCountryFile expectedFranceFile(directoryForV1.GetFullPath(), franceFile, 1 /* version */);
shared_ptr<LocalCountryFile> franceLocalFile = PreparePlaceForCountryFiles(1 /* version */, franceFile); auto franceLocalFile = PreparePlaceForCountryFiles(1 /* version */, franceFile);
TEST(franceLocalFile.get(), ()); TEST(franceLocalFile.get(), ());
TEST_EQUAL(expectedFranceFile, *franceLocalFile, ()); TEST_EQUAL(expectedFranceFile, *franceLocalFile, ());
} }
UNIT_TEST(LocalCountryFile_CountryIndexes) UNIT_TEST(LocalCountryFile_CountryIndexes)
{ {
using platform::CountryIndexes;
ScopedDir testDir("101010"); ScopedDir testDir("101010");
CountryFile germanyFile("Germany"); CountryFile germanyFile("Germany");
@@ -296,11 +301,11 @@ UNIT_TEST(LocalCountryFile_CountryIndexes)
CountryIndexes::IndexesDir(germanyLocalFile), ()); CountryIndexes::IndexesDir(germanyLocalFile), ());
CountryIndexes::PreparePlaceOnDisk(germanyLocalFile); CountryIndexes::PreparePlaceOnDisk(germanyLocalFile);
string const bitsPath = CountryIndexes::GetPath(germanyLocalFile, CountryIndexes::Index::Bits); auto const bitsPath = CountryIndexes::GetPath(germanyLocalFile, CountryIndexes::Index::Bits);
TEST(!Platform::IsFileExistsByFullPath(bitsPath), (bitsPath)); TEST(!Platform::IsFileExistsByFullPath(bitsPath), (bitsPath));
{ {
FileWriter writer(bitsPath); FileWriter writer(bitsPath);
string const contents = "bits index"; std::string const contents = "bits index";
writer.Write(contents.data(), contents.size()); writer.Write(contents.data(), contents.size());
} }
TEST(Platform::IsFileExistsByFullPath(bitsPath), (bitsPath)); TEST(Platform::IsFileExistsByFullPath(bitsPath), (bitsPath));
@@ -312,6 +317,8 @@ UNIT_TEST(LocalCountryFile_CountryIndexes)
UNIT_TEST(LocalCountryFile_DoNotDeleteUserFiles) UNIT_TEST(LocalCountryFile_DoNotDeleteUserFiles)
{ {
using platform::CountryIndexes;
base::ScopedLogLevelChanger const criticalLogLevel(LCRITICAL); base::ScopedLogLevelChanger const criticalLogLevel(LCRITICAL);
ScopedDir testDir("101010"); ScopedDir testDir("101010");
@@ -320,10 +327,10 @@ UNIT_TEST(LocalCountryFile_DoNotDeleteUserFiles)
LocalCountryFile germanyLocalFile(testDir.GetFullPath(), germanyFile, 101010 /* version */); LocalCountryFile germanyLocalFile(testDir.GetFullPath(), germanyFile, 101010 /* version */);
CountryIndexes::PreparePlaceOnDisk(germanyLocalFile); CountryIndexes::PreparePlaceOnDisk(germanyLocalFile);
string const userFilePath = base::JoinPath(CountryIndexes::IndexesDir(germanyLocalFile), "user-data.txt"); auto const userFilePath = base::JoinPath(CountryIndexes::IndexesDir(germanyLocalFile), "user-data.txt");
{ {
FileWriter writer(userFilePath); FileWriter writer(userFilePath);
string const data = "user data"; std::string const data = "user data";
writer.Write(data.data(), data.size()); writer.Write(data.data(), data.size());
} }
TEST(!CountryIndexes::DeleteFromDisk(germanyLocalFile), ("Indexes dir should not be deleted for:", germanyLocalFile)); TEST(!CountryIndexes::DeleteFromDisk(germanyLocalFile), ("Indexes dir should not be deleted for:", germanyLocalFile));
@@ -334,7 +341,7 @@ UNIT_TEST(LocalCountryFile_DoNotDeleteUserFiles)
UNIT_TEST(LocalCountryFile_MakeTemporary) UNIT_TEST(LocalCountryFile_MakeTemporary)
{ {
string const path = GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION); auto const path = GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION);
LocalCountryFile file = LocalCountryFile::MakeTemporary(path); LocalCountryFile file = LocalCountryFile::MakeTemporary(path);
TEST_EQUAL(file.GetPath(MapFileType::Map), path, ()); TEST_EQUAL(file.GetPath(MapFileType::Map), path, ());
} }

View File

@@ -5,9 +5,6 @@
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
using namespace std;
using namespace std::chrono;
namespace platform namespace platform
{ {
namespace tests_support namespace tests_support
@@ -17,7 +14,7 @@ TestSocket::~TestSocket()
m_isConnected = false; m_isConnected = false;
} }
bool TestSocket::Open(string const & host, uint16_t port) bool TestSocket::Open(std::string const & host, uint16_t port)
{ {
if (m_isConnected) if (m_isConnected)
return false; return false;
@@ -36,13 +33,13 @@ bool TestSocket::Read(uint8_t * data, uint32_t count)
if (!m_isConnected) if (!m_isConnected)
return false; return false;
unique_lock<mutex> lock(m_inputMutex); std::unique_lock<std::mutex> lock(m_inputMutex);
m_inputCondition.wait_for(lock, milliseconds(m_timeoutMs), [this]() { return !m_input.empty(); }); m_inputCondition.wait_for(lock, std::chrono::milliseconds(m_timeoutMs), [this]() { return !m_input.empty(); });
if (m_input.size() < count) if (m_input.size() < count)
return false; return false;
copy(m_input.begin(), m_input.end(), data); std::copy(m_input.begin(), m_input.end(), data);
m_input.erase(m_input.begin(), m_input.begin() + count); m_input.erase(m_input.begin(), m_input.begin() + count);
return true; return true;
} }
@@ -53,7 +50,7 @@ bool TestSocket::Write(uint8_t const * data, uint32_t count)
return false; return false;
{ {
lock_guard<mutex> lg(m_outputMutex); std::lock_guard lg(m_outputMutex);
m_output.insert(m_output.end(), data, data + count); m_output.insert(m_output.end(), data, data + count);
} }
m_outputCondition.notify_one(); m_outputCondition.notify_one();
@@ -64,10 +61,10 @@ void TestSocket::SetTimeout(uint32_t milliseconds)
{ {
m_timeoutMs = milliseconds; m_timeoutMs = milliseconds;
} }
size_t TestSocket::ReadServer(vector<uint8_t> & destination) size_t TestSocket::ReadServer(std::vector<uint8_t> & destination)
{ {
unique_lock<mutex> lock(m_outputMutex); std::unique_lock lock(m_outputMutex);
m_outputCondition.wait_for(lock, milliseconds(m_timeoutMs), [this]() { return !m_output.empty(); }); m_outputCondition.wait_for(lock, std::chrono::milliseconds(m_timeoutMs), [this]() { return !m_output.empty(); });
size_t const outputSize = m_output.size(); size_t const outputSize = m_output.size();
destination.insert(destination.end(), m_output.begin(), m_output.end()); destination.insert(destination.end(), m_output.begin(), m_output.end());

View File

@@ -21,8 +21,6 @@
#include <sys/vfs.h> #include <sys/vfs.h>
#endif #endif
using namespace std;
namespace namespace
{ {
struct CloseDir struct CloseDir
@@ -36,7 +34,7 @@ struct CloseDir
} // namespace } // namespace
// static // static
Platform::EError Platform::RmDir(string const & dirName) Platform::EError Platform::RmDir(std::string const & dirName)
{ {
if (rmdir(dirName.c_str()) != 0) if (rmdir(dirName.c_str()) != 0)
return ErrnoToError(); return ErrnoToError();
@@ -44,7 +42,7 @@ Platform::EError Platform::RmDir(string const & dirName)
} }
// static // static
Platform::EError Platform::GetFileType(string const & path, EFileType & type) Platform::EError Platform::GetFileType(std::string const & path, EFileType & type)
{ {
struct stat stats; struct stat stats;
if (stat(path.c_str(), &stats) != 0) if (stat(path.c_str(), &stats) != 0)
@@ -59,7 +57,7 @@ Platform::EError Platform::GetFileType(string const & path, EFileType & type)
} }
// static // static
bool Platform::IsFileExistsByFullPath(string const & filePath) bool Platform::IsFileExistsByFullPath(std::string const & filePath)
{ {
struct stat s; struct stat s;
return stat(filePath.c_str(), &s) == 0; return stat(filePath.c_str(), &s) == 0;
@@ -67,11 +65,11 @@ bool Platform::IsFileExistsByFullPath(string const & filePath)
#if !defined(OMIM_OS_IPHONE) #if !defined(OMIM_OS_IPHONE)
// static // static
void Platform::DisableBackupForFile(string const & /*filePath*/) {} void Platform::DisableBackupForFile(std::string const & /*filePath*/) {}
#endif #endif
// static // static
string Platform::GetCurrentWorkingDirectory() noexcept std::string Platform::GetCurrentWorkingDirectory() noexcept
{ {
char path[PATH_MAX]; char path[PATH_MAX];
char const * const dir = getcwd(path, PATH_MAX); char const * const dir = getcwd(path, PATH_MAX);
@@ -80,9 +78,9 @@ string Platform::GetCurrentWorkingDirectory() noexcept
return dir; return dir;
} }
bool Platform::IsDirectoryEmpty(string const & directory) bool Platform::IsDirectoryEmpty(std::string const & directory)
{ {
unique_ptr<DIR, CloseDir> dir(opendir(directory.c_str())); std::unique_ptr<DIR, CloseDir> dir(opendir(directory.c_str()));
if (!dir) if (!dir)
return true; return true;
@@ -98,7 +96,7 @@ bool Platform::IsDirectoryEmpty(string const & directory)
return true; return true;
} }
bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size) bool Platform::GetFileSizeByFullPath(std::string const & filePath, uint64_t & size)
{ {
struct stat s; struct stat s;
if (stat(filePath.c_str(), &s) == 0) if (stat(filePath.c_str(), &s) == 0)
@@ -134,9 +132,9 @@ Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize)
namespace pl namespace pl
{ {
void EnumerateFiles(string const & directory, function<void(char const *)> const & fn) void EnumerateFiles(std::string const & directory, std::function<void(char const *)> const & fn)
{ {
unique_ptr<DIR, CloseDir> dir(opendir(directory.c_str())); std::unique_ptr<DIR, CloseDir> dir(opendir(directory.c_str()));
if (!dir) if (!dir)
return; return;
@@ -145,13 +143,13 @@ void EnumerateFiles(string const & directory, function<void(char const *)> const
fn(entry->d_name); fn(entry->d_name);
} }
void EnumerateFilesByRegExp(string const & directory, string const & regexp, vector<string> & res) void EnumerateFilesByRegExp(std::string const & directory, std::string const & regexp, std::vector<std::string> & res)
{ {
regex exp(regexp); std::regex exp(regexp);
EnumerateFiles(directory, [&](char const * entry) EnumerateFiles(directory, [&](char const * entry)
{ {
string const name(entry); std::string const name(entry);
if (regex_search(name.begin(), name.end(), exp)) if (std::regex_search(name.begin(), name.end(), exp))
res.push_back(name); res.push_back(name);
}); });
} }

View File

@@ -17,9 +17,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
using namespace std; static bool GetUserWritableDir(std::string & outDir)
static bool GetUserWritableDir(string & outDir)
{ {
char pathBuf[MAX_PATH] = {0}; char pathBuf[MAX_PATH] = {0};
if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf))) if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf)))
@@ -34,7 +32,7 @@ static bool GetUserWritableDir(string & outDir)
} }
/// @return Full path to the executable file /// @return Full path to the executable file
static bool GetPathToBinary(string & outPath) static bool GetPathToBinary(std::string & outPath)
{ {
// get path to executable // get path to executable
char pathBuf[MAX_PATH] = {0}; char pathBuf[MAX_PATH] = {0};
@@ -56,7 +54,7 @@ std::unique_ptr<Socket> CreateSocket()
Platform::Platform() Platform::Platform()
{ {
string path; std::string path;
CHECK(GetPathToBinary(path), ("Can't get path to binary")); CHECK(GetPathToBinary(path), ("Can't get path to binary"));
// resources path: // resources path:
@@ -80,7 +78,7 @@ Platform::Platform()
// writable path: // writable path:
// 1. the same as resources if we have write access to this folder // 1. the same as resources if we have write access to this folder
// 2. otherwise, use system-specific folder // 2. otherwise, use system-specific folder
string const tmpFilePath = base::JoinPath(m_resourcesDir, "mapswithmetmptestfile"); auto const tmpFilePath = base::JoinPath(m_resourcesDir, "mapswithmetmptestfile");
try try
{ {
FileWriter tmpfile(tmpFilePath); FileWriter tmpfile(tmpFilePath);
@@ -106,16 +104,16 @@ Platform::Platform()
LOG(LINFO, ("Settings Directory:", m_settingsDir)); LOG(LINFO, ("Settings Directory:", m_settingsDir));
} }
bool Platform::IsFileExistsByFullPath(string const & filePath) bool Platform::IsFileExistsByFullPath(std::string const & filePath)
{ {
return ::GetFileAttributesA(filePath.c_str()) != INVALID_FILE_ATTRIBUTES; return ::GetFileAttributesA(filePath.c_str()) != INVALID_FILE_ATTRIBUTES;
} }
// static // static
void Platform::DisableBackupForFile(string const & filePath) {} void Platform::DisableBackupForFile(std::string const & filePath) {}
// static // static
string Platform::GetCurrentWorkingDirectory() noexcept std::string Platform::GetCurrentWorkingDirectory() noexcept
{ {
char path[MAX_PATH]; char path[MAX_PATH];
char const * const dir = getcwd(path, MAX_PATH); char const * const dir = getcwd(path, MAX_PATH);
@@ -125,7 +123,7 @@ string Platform::GetCurrentWorkingDirectory() noexcept
} }
// static // static
Platform::EError Platform::RmDir(string const & dirName) Platform::EError Platform::RmDir(std::string const & dirName)
{ {
if (_rmdir(dirName.c_str()) != 0) if (_rmdir(dirName.c_str()) != 0)
return ErrnoToError(); return ErrnoToError();
@@ -133,7 +131,7 @@ Platform::EError Platform::RmDir(string const & dirName)
} }
// static // static
Platform::EError Platform::GetFileType(string const & path, EFileType & type) Platform::EError Platform::GetFileType(std::string const & path, EFileType & type)
{ {
struct _stat32 stats; struct _stat32 stats;
if (_stat32(path.c_str(), &stats) != 0) if (_stat32(path.c_str(), &stats) != 0)
@@ -147,12 +145,12 @@ Platform::EError Platform::GetFileType(string const & path, EFileType & type)
return ERR_OK; return ERR_OK;
} }
string Platform::DeviceName() const std::string Platform::DeviceName() const
{ {
return OMIM_OS_NAME; return OMIM_OS_NAME;
} }
string Platform::DeviceModel() const std::string Platform::DeviceModel() const
{ {
return {}; return {};
} }
@@ -189,12 +187,12 @@ Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize)
return STORAGE_OK; return STORAGE_OK;
} }
bool Platform::IsDirectoryEmpty(string const & directory) bool Platform::IsDirectoryEmpty(std::string const & directory)
{ {
return PathIsDirectoryEmptyA(directory.c_str()); return PathIsDirectoryEmptyA(directory.c_str());
} }
bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size) bool Platform::GetFileSizeByFullPath(std::string const & filePath, uint64_t & size)
{ {
HANDLE hFile = HANDLE hFile =
CreateFileA(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); CreateFileA(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

View File

@@ -18,7 +18,7 @@
namespace settings namespace settings
{ {
using namespace std; using std::string;
std::string_view kMeasurementUnits = "Units"; std::string_view kMeasurementUnits = "Units";
std::string_view kMapLanguageCode = "MapLanguageCode"; std::string_view kMapLanguageCode = "MapLanguageCode";
@@ -54,7 +54,7 @@ namespace impl
template <class T, size_t N> template <class T, size_t N>
bool FromStringArray(string const & s, T (&arr)[N]) bool FromStringArray(string const & s, T (&arr)[N])
{ {
istringstream in(s); std::istringstream in(s);
size_t count = 0; size_t count = 0;
while (count < N && in >> arr[count]) while (count < N && in >> arr[count])
{ {
@@ -70,7 +70,7 @@ bool FromStringArray(string const & s, T (&arr)[N])
template <> template <>
string ToString<m2::AnyRectD>(m2::AnyRectD const & rect) string ToString<m2::AnyRectD>(m2::AnyRectD const & rect)
{ {
ostringstream out; std::ostringstream out;
out.precision(12); out.precision(12);
m2::PointD glbZero(rect.GlobalZero()); m2::PointD glbZero(rect.GlobalZero());
out << glbZero.x << " " << glbZero.y << " "; out << glbZero.x << " " << glbZero.y << " ";
@@ -99,7 +99,7 @@ bool FromString<m2::AnyRectD>(string const & str, m2::AnyRectD & rect)
template <> template <>
string ToString<m2::RectD>(m2::RectD const & rect) string ToString<m2::RectD>(m2::RectD const & rect)
{ {
ostringstream stream; std::ostringstream stream;
stream.precision(12); stream.precision(12);
stream << rect.minX() << " " << rect.minY() << " " << rect.maxX() << " " << rect.maxY(); stream << rect.minX() << " " << rect.minY() << " " << rect.maxX() << " " << rect.maxY();
return stream.str(); return stream.str();
@@ -139,7 +139,7 @@ namespace impl
template <typename T> template <typename T>
string ToStringScalar(T const & v) string ToStringScalar(T const & v)
{ {
ostringstream stream; std::ostringstream stream;
stream.precision(12); stream.precision(12);
stream << v; stream << v;
return stream.str(); return stream.str();
@@ -148,7 +148,7 @@ string ToStringScalar(T const & v)
template <typename T> template <typename T>
bool FromStringScalar(string const & str, T & v) bool FromStringScalar(string const & str, T & v)
{ {
istringstream stream(str); std::istringstream stream(str);
if (stream) if (stream)
{ {
stream >> v; stream >> v;
@@ -224,7 +224,7 @@ namespace impl
template <class TPair> template <class TPair>
string ToStringPair(TPair const & value) string ToStringPair(TPair const & value)
{ {
ostringstream stream; std::ostringstream stream;
stream.precision(12); stream.precision(12);
stream << value.first << " " << value.second; stream << value.first << " " << value.second;
return stream.str(); return stream.str();
@@ -233,7 +233,7 @@ string ToStringPair(TPair const & value)
template <class TPair> template <class TPair>
bool FromStringPair(string const & str, TPair & value) bool FromStringPair(string const & str, TPair & value)
{ {
istringstream stream(str); std::istringstream stream(str);
if (stream) if (stream)
{ {
stream >> value.first; stream >> value.first;
@@ -247,8 +247,8 @@ bool FromStringPair(string const & str, TPair & value)
} }
} // namespace impl } // namespace impl
typedef pair<int, int> IPairT; typedef std::pair<int, int> IPairT;
typedef pair<double, double> DPairT; typedef std::pair<double, double> DPairT;
template <> template <>
string ToString<IPairT>(IPairT const & v) string ToString<IPairT>(IPairT const & v)