diff --git a/generator/update_generator.cpp b/generator/update_generator.cpp index b1dec2f718..c3a9a5d984 100644 --- a/generator/update_generator.cpp +++ b/generator/update_generator.cpp @@ -66,7 +66,7 @@ namespace update LOG_SHORT(LINFO, ("Files count included in update file:", files.size())); } - TCommonFiles commonFiles; + CommonFilesT commonFiles; for (Platform::FilesList::iterator it = files.begin(); it != files.end(); ++it) { @@ -77,7 +77,7 @@ namespace update commonFiles.push_back(make_pair(*it, static_cast(size))); } - SaveTiles(dataDir + DATA_UPDATE_FILE, commonFiles); + SaveFiles(dataDir + DATA_UPDATE_FILE, commonFiles); LOG_SHORT(LINFO, ("Created update file with ", commonFiles.size(), " files")); diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index fa04a22df6..b462652540 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -273,7 +273,7 @@ namespace qt { QColor rowColor; QString statusString; - TLocalAndRemoteSize size(0, 0); + LocalAndRemoteSizeT size(0, 0); switch (m_storage.CountryStatus(index)) { case ENotDownloaded: diff --git a/storage/country.cpp b/storage/country.cpp index dcc49c9702..c76c8c86a8 100644 --- a/storage/country.cpp +++ b/storage/country.cpp @@ -22,10 +22,10 @@ namespace storage { /// Simple check - compare url size with real file size on disk - bool IsTileDownloaded(TTile const & tile) + bool IsFileDownloaded(CountryFile const & file) { uint64_t size = 0; - if (!GetPlatform().GetFileSize(GetPlatform().WritablePathForFile(tile.first), size)) + if (!GetPlatform().GetFileSize(GetPlatform().WritablePathForFile(file.first), size)) return false; return true;//tile.second == size; } @@ -34,10 +34,10 @@ namespace storage { m2::RectD & m_bounds; CountryBoundsCalculator(m2::RectD & bounds) : m_bounds(bounds) {} - void operator()(TTile const & tile) + void operator()(CountryFile const & file) { feature::DataHeader header; - FilesContainerR reader(GetPlatform().WritablePathForFile(tile.first)); + FilesContainerR reader(GetPlatform().WritablePathForFile(file.first)); header.Load(reader.GetReader(HEADER_FILE_TAG)); m_bounds.Add(header.GetBounds()); } @@ -46,7 +46,7 @@ namespace storage m2::RectD Country::Bounds() const { m2::RectD bounds; - std::for_each(m_tiles.begin(), m_tiles.end(), CountryBoundsCalculator(bounds)); + std::for_each(m_files.begin(), m_files.end(), CountryBoundsCalculator(bounds)); return bounds; } @@ -56,30 +56,30 @@ namespace storage uint64_t & m_remoteSize; SizeCalculator(uint64_t & localSize, uint64_t & remoteSize) : m_localSize(localSize), m_remoteSize(remoteSize) {} - void operator()(TTile const & tile) + void operator()(CountryFile const & file) { - if (IsTileDownloaded(tile)) - m_localSize += tile.second; - m_remoteSize += tile.second; + if (IsFileDownloaded(file)) + m_localSize += file.second; + m_remoteSize += file.second; } }; - TLocalAndRemoteSize Country::Size() const + LocalAndRemoteSizeT Country::Size() const { uint64_t localSize = 0; uint64_t remoteSize = 0; - std::for_each(m_tiles.begin(), m_tiles.end(), SizeCalculator(localSize, remoteSize)); - return TLocalAndRemoteSize(localSize, remoteSize); + std::for_each(m_files.begin(), m_files.end(), SizeCalculator(localSize, remoteSize)); + return LocalAndRemoteSizeT(localSize, remoteSize); } - void Country::AddTile(TTile const & tile) + void Country::AddFile(CountryFile const & file) { - m_tiles.push_back(tile); + m_files.push_back(file); } //////////////////////////////////////////////////////////////////////// - bool LoadCountries(file_t const & file, TTilesContainer const & sortedTiles, + bool LoadCountries(file_t const & file, FilesContainerT const & sortedFiles, TCountriesContainer & countries) { countries.Clear(); @@ -131,13 +131,13 @@ namespace storage ++tokIt; while (tokIt) { - TTilesContainer::const_iterator const first = sortedTiles.begin(); - TTilesContainer::const_iterator const last = sortedTiles.end(); + FilesContainerT::const_iterator const first = sortedFiles.begin(); + FilesContainerT::const_iterator const last = sortedFiles.end(); string const nameWithExt = *tokIt + DATA_FILE_EXTENSION; - TTilesContainer::const_iterator const found = lower_bound( - first, last, TTile(nameWithExt, 0)); + FilesContainerT::const_iterator const found = lower_bound( + first, last, CountryFile(nameWithExt, 0)); if (found != last && !(nameWithExt < found->first)) - currentCountry->AddTile(*found); + currentCountry->AddFile(*found); ++tokIt; } } @@ -149,7 +149,7 @@ namespace storage return countries.SiblingsCount() > 0; } - void SaveTiles(string const & file, TCommonFiles const & commonFiles) + void SaveFiles(string const & file, CommonFilesT const & commonFiles) { FileWriter writer(file); stream::SinkWriterStream wStream(writer); @@ -159,26 +159,26 @@ namespace storage wStream << commonFiles; } - bool LoadTiles(file_t const & file, TTilesContainer & tiles, uint32_t & dataVersion) + bool LoadFiles(file_t const & file, FilesContainerT & files, uint32_t & dataVersion) { - tiles.clear(); + files.clear(); try { ReaderSource source(file); stream::SinkReaderStream > stream(source); - TCommonFiles commonFiles; + CommonFilesT commonFiles; stream >> dataVersion; stream >> commonFiles; - tiles.reserve(commonFiles.size()); + files.reserve(commonFiles.size()); - for (TCommonFiles::iterator it = commonFiles.begin(); it != commonFiles.end(); ++it) - tiles.push_back(TTile(it->first, it->second)); + for (CommonFilesT::iterator it = commonFiles.begin(); it != commonFiles.end(); ++it) + files.push_back(CountryFile(it->first, it->second)); - sort(tiles.begin(), tiles.end()); + sort(files.begin(), files.end()); } catch (RootException const & e) { diff --git a/storage/country.hpp b/storage/country.hpp index 67f991bf47..6400b93234 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -2,6 +2,8 @@ #include "simple_tree.hpp" +#include "../base/buffer_vector.hpp" + #include "../geometry/rect2d.hpp" #include "../std/string.hpp" @@ -14,14 +16,14 @@ class Writer; namespace storage { /// holds file name for tile and it's total size - typedef pair TTile; - typedef vector TTilesContainer; - typedef pair TLocalAndRemoteSize; + typedef pair CountryFile; + typedef buffer_vector FilesContainerT; + typedef pair LocalAndRemoteSizeT; /// Intermediate container for data transfer - typedef vector > TCommonFiles; + typedef vector > CommonFilesT; - bool IsTileDownloaded(TTile const & tile); + bool IsFileDownloaded(CountryFile const & file); /// Serves as a proxy between GUI and downloaded files class Country @@ -31,7 +33,7 @@ namespace storage /// Flag to display string m_flag; /// stores squares with world pieces which are part of the country - TTilesContainer m_tiles; + FilesContainerT m_files; public: Country() {} @@ -40,15 +42,15 @@ namespace storage bool operator<(Country const & other) const { return Name() < other.Name(); } - void AddTile(TTile const & tile); - TTilesContainer const & Tiles() const { return m_tiles; } + void AddFile(CountryFile const & file); + FilesContainerT const & Files() const { return m_files; } string const & Name() const { return m_name; } string const & Flag() const { return m_flag; } /// @return bounds for downloaded parts of the country or empty rect m2::RectD Bounds() const; - TLocalAndRemoteSize Size() const; + LocalAndRemoteSizeT Size() const; }; typedef SimpleTree TCountriesContainer; @@ -56,9 +58,8 @@ namespace storage /// @param tiles contains files and their sizes /// @return false if new application version should be downloaded typedef ReaderPtr file_t; - bool LoadCountries(file_t const & file, TTilesContainer const & sortedTiles, + bool LoadCountries(file_t const & file, FilesContainerT const & sortedTiles, TCountriesContainer & countries); - void SaveTiles(string const & file, TCommonFiles const & commonFiles); - bool LoadTiles(file_t const & file, TTilesContainer & tiles, uint32_t & dataVersion); - //void SaveCountries(TCountriesContainer const & countries, Writer & writer); + void SaveFiles(string const & file, CommonFilesT const & commonFiles); + bool LoadFiles(file_t const & file, FilesContainerT & files, uint32_t & dataVersion); } diff --git a/storage/storage.cpp b/storage/storage.cpp index 66c48fd13b..5b2fb52aab 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -100,7 +100,7 @@ namespace storage return NodeFromIndex(m_countries, index).Value().Flag(); } - TLocalAndRemoteSize Storage::CountrySizeInBytes(TIndex const & index) const + LocalAndRemoteSizeT Storage::CountrySizeInBytes(TIndex const & index) const { return CountryByIndex(index).Size(); } @@ -121,7 +121,7 @@ namespace storage if (m_failedCountries.find(index) != m_failedCountries.end()) return EDownloadFailed; - TLocalAndRemoteSize size = CountryByIndex(index).Size(); + LocalAndRemoteSizeT size = CountryByIndex(index).Size(); if (size.first == size.second) { if (size.second == 0) @@ -149,7 +149,7 @@ namespace storage if (m_queue.size() == 1) { // reset total country's download progress - TLocalAndRemoteSize const size = CountryByIndex(index).Size(); + LocalAndRemoteSizeT const size = CountryByIndex(index).Size(); m_countryProgress.m_current = 0; m_countryProgress.m_total = size.second; @@ -172,7 +172,7 @@ namespace storage { m_workingDir = GetPlatform().WritableDir(); } - void operator()(TTile const & tile) + void operator()(CountryFile const & tile) { m_removeFn(tile.first); } @@ -183,10 +183,10 @@ namespace storage while (!m_queue.empty()) { TIndex index = m_queue.front(); - TTilesContainer const & tiles = CountryByIndex(index).Tiles(); - for (TTilesContainer::const_iterator it = tiles.begin(); it != tiles.end(); ++it) + FilesContainerT const & tiles = CountryByIndex(index).Files(); + for (FilesContainerT::const_iterator it = tiles.begin(); it != tiles.end(); ++it) { - if (!IsTileDownloaded(*it)) + if (!IsFileDownloaded(*it)) { HttpStartParams params; params.m_url = UpdateBaseUrl() + UrlEncode(it->first); @@ -219,7 +219,7 @@ namespace storage { string const m_baseUrl; CancelDownloading(string const & baseUrl) : m_baseUrl(baseUrl) {} - void operator()(TTile const & tile) + void operator()(CountryFile const & tile) { GetDownloadManager().CancelDownload((m_baseUrl + UrlEncode(tile.first)).c_str()); } @@ -234,7 +234,7 @@ namespace storage m_workingDir = GetPlatform().WritableDir(); } /// @TODO do not delete other countries cells - void operator()(TTile const & tile) + void operator()(CountryFile const & tile) { FileWriter::DeleteFileX(m_workingDir + tile.first); } @@ -244,9 +244,9 @@ namespace storage void DeactivateAndDeleteCountry(Country const & country, TRemoveFunc removeFunc) { // deactivate from multiindex - for_each(country.Tiles().begin(), country.Tiles().end(), DeactivateMap(removeFunc)); + for_each(country.Files().begin(), country.Files().end(), DeactivateMap(removeFunc)); // delete from disk - for_each(country.Tiles().begin(), country.Tiles().end(), DeleteMap()); + for_each(country.Files().begin(), country.Files().end(), DeleteMap()); } m2::RectD Storage::CountryBounds(TIndex const & index) const @@ -267,7 +267,7 @@ namespace storage { if (found == m_queue.begin()) { // stop download - for_each(country.Tiles().begin(), country.Tiles().end(), CancelDownloading(UpdateBaseUrl())); + for_each(country.Files().begin(), country.Files().end(), CancelDownloading(UpdateBaseUrl())); // remove from the queue m_queue.erase(found); // start another download if the queue is not empty @@ -300,8 +300,8 @@ namespace storage if (m_countries.SiblingsCount() == 0) { Platform & pl = GetPlatform(); - TTilesContainer tiles; - if (LoadTiles(pl.GetReader(DATA_UPDATE_FILE), tiles, m_currentVersion)) + FilesContainerT tiles; + if (LoadFiles(pl.GetReader(DATA_UPDATE_FILE), tiles, m_currentVersion)) { if (!LoadCountries(pl.GetReader(COUNTRIES_FILE), tiles, m_countries)) { @@ -352,7 +352,7 @@ namespace storage } else { - TLocalAndRemoteSize size = CountryByIndex(m_queue.front()).Size(); + LocalAndRemoteSizeT size = CountryByIndex(m_queue.front()).Size(); if (size.second != 0) m_countryProgress.m_current = size.first; diff --git a/storage/storage.hpp b/storage/storage.hpp index 9cd19b779b..f5546bc6fc 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -132,7 +132,7 @@ namespace storage size_t CountriesCount(TIndex const & index) const; string const & CountryName(TIndex const & index) const; string const & CountryFlag(TIndex const & index) const; - TLocalAndRemoteSize CountrySizeInBytes(TIndex const & index) const; + LocalAndRemoteSizeT CountrySizeInBytes(TIndex const & index) const; TStatus CountryStatus(TIndex const & index) const; m2::RectD CountryBounds(TIndex const & index) const; diff --git a/storage/storage_tests/country_test.cpp b/storage/storage_tests/country_test.cpp index b3a1f6e4b7..264eb800c9 100644 --- a/storage/storage_tests/country_test.cpp +++ b/storage/storage_tests/country_test.cpp @@ -7,33 +7,30 @@ #include "../../coding/file_writer.hpp" #include "../../coding/file_reader.hpp" -#include "../../base/start_mem_debug.hpp" - using namespace storage; - -UNIT_TEST(TilesSerialization) +UNIT_TEST(FilesSerialization) { static string const FILE = "tiles_serialization_test"; - TCommonFiles::value_type const vv1("str2", 456); - TCommonFiles::value_type const vv2("str1", 123); + CommonFilesT::value_type const vv1("str2", 456); + CommonFilesT::value_type const vv2("str1", 123); { - TCommonFiles commonFiles; + CommonFilesT commonFiles; commonFiles.push_back(vv1); commonFiles.push_back(vv2); - SaveTiles(FILE, commonFiles); + SaveFiles(FILE, commonFiles); } { uint32_t version; - TTilesContainer tiles; - TEST(LoadTiles(ReaderPtr(new FileReader(FILE)), tiles, version), ()); + FilesContainerT files; + TEST(LoadFiles(ReaderPtr(new FileReader(FILE)), files, version), ()); - TEST_EQUAL( tiles.size(), 2, ()); - TEST_EQUAL( tiles[0], TTilesContainer::value_type("str1", 123), ()); - TEST_EQUAL( tiles[1], TTilesContainer::value_type("str2", 456), ()); + TEST_EQUAL( files.size(), 2, ()); + TEST_EQUAL( files[0], FilesContainerT::value_type("str1", 123), ()); + TEST_EQUAL( files[1], FilesContainerT::value_type("str2", 456), ()); } FileWriter::DeleteFileX(FILE);