diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-10-03 17:27:36 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:29:16 +0300 |
commit | 160753d1ba978769bbe063dcff630c229e3a7d22 (patch) | |
tree | 07043e3669e1d983e3eeab778c2ab2fd76996922 /storage | |
parent | 7ab2f762c4372d22576e7d645be84310b1515b3a (diff) |
[core] storage and framework changed for routing suppport
Diffstat (limited to 'storage')
-rw-r--r-- | storage/country.hpp | 2 | ||||
-rw-r--r-- | storage/storage.cpp | 109 | ||||
-rw-r--r-- | storage/storage.hpp | 27 | ||||
-rw-r--r-- | storage/storage.pro | 1 | ||||
-rw-r--r-- | storage/storage_defines.hpp | 45 |
5 files changed, 80 insertions, 104 deletions
diff --git a/storage/country.hpp b/storage/country.hpp index 7073c883ec..1faa970995 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -1,5 +1,6 @@ #pragma once +#include "storage_defines.hpp" #include "simple_tree.hpp" #include "country_decl.hpp" @@ -34,7 +35,6 @@ namespace storage }; typedef buffer_vector<CountryFile, 1> FilesContainerT; - typedef pair<uint64_t, uint64_t> LocalAndRemoteSizeT; /// Serves as a proxy between GUI and downloaded files class Country diff --git a/storage/storage.cpp b/storage/storage.cpp index e43632a776..9d605ca37a 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -68,8 +68,6 @@ namespace storage for (size_t j = 0; j < files.size(); ++j) FileWriter::DeleteFileX(dir + files[j]); } - - UpdateDownloadedCountriesState(); } //////////////////////////////////////////////////////////////////////////// @@ -93,73 +91,6 @@ namespace storage } } - TIndex const & Storage::GetDownloadedCountryAt(size_t const & i) const - { - return m_downloadedCountries[i]; - } - - TIndex const & Storage::GetOutOfDateCountryAt(size_t const & i) const - { - return m_outOfDateCountries[i]; - } - - void Storage::UpdateDownloadedCountriesState(TIndex const index) - { - size_t const count = CountriesCount(index); - for (size_t i = 0; i < count; ++i) - { - TIndex indexCopy = index; - if (index.m_group == TIndex::INVALID) - indexCopy.m_group = i; - else if (index.m_country == TIndex::INVALID) - indexCopy.m_country = i; - else - indexCopy.m_region = i; - - UpdateDownloadedCountriesState(indexCopy); - - TStatus const status = CountryStatusEx(indexCopy); - if (status != EUnknown && status != ENotDownloaded) - { - m_downloadedCountries.push_back(indexCopy); - if (status == EOnDiskOutOfDate) - m_outOfDateCountries.push_back(indexCopy); - } - } - } - - void Storage::UpdateDownloadedCountriesState() - { - m_downloadedCountries.clear(); - m_outOfDateCountries.clear(); - - UpdateDownloadedCountriesState(TIndex()); - - auto predicate = [this](TIndex const & l, TIndex const & r) - { - return CountryFileName(l) == CountryFileName(r); - }; - unique(m_downloadedCountries.begin(), m_downloadedCountries.end(), predicate); - unique(m_outOfDateCountries.begin(), m_outOfDateCountries.end(), predicate); - - auto comparator = [this](TIndex const & l, TIndex const & r) - { - return CountryName(l) < CountryName(r); - }; - sort(m_downloadedCountries.begin(), m_downloadedCountries.end(), comparator); - sort(m_outOfDateCountries.begin(), m_outOfDateCountries.end(), comparator); - } - - size_t Storage::GetDownloadedCountriesCount() const - { - return m_downloadedCountries.size(); - } - - size_t Storage::GetOutOfDateCountriesCount() const - { - return m_outOfDateCountries.size(); - } - Country const & Storage::CountryByIndex(TIndex const & index) const { return NodeFromIndex(m_countries, index).Value(); @@ -197,6 +128,12 @@ namespace storage return CountryByIndex(index).Size(); } + LocalAndRemoteSizeT Storage::CountrySizeInBytesEx(const TIndex & index, const TMapOptions & options) const + { + ///@TODO for vng + return CountryByIndex(index).Size(); + } + TStatus Storage::CountryStatus(TIndex const & index) const { // first, check if we already downloading this country or have in in the queue @@ -204,33 +141,33 @@ namespace storage if (found != m_queue.end()) { if (found == m_queue.begin()) - return EDownloading; + return TStatus::EDownloading; else - return EInQueue; + return TStatus::EInQueue; } // second, check if this country has failed while downloading if (m_failedCountries.count(index) > 0) - return EDownloadFailed; + return TStatus::EDownloadFailed; - return EUnknown; + return TStatus::EUnknown; } TStatus Storage::CountryStatusEx(TIndex const & index) const { TStatus res = CountryStatus(index); - if (res == EUnknown) + if (res == TStatus::EUnknown) { Country const & c = CountryByIndex(index); LocalAndRemoteSizeT const size = c.Size(); if (size.first == 0) - return ENotDownloaded; + return TStatus::ENotDownloaded; if (size.second == 0) - return EUnknown; + return TStatus::EUnknown; - res = EOnDisk; + res = TStatus::EOnDisk; if (size.first != size.second) { /// @todo Do better version check, not just size comparison. @@ -242,15 +179,26 @@ namespace storage uint64_t sz = 0; if (!pl.GetFileSizeByFullPath(fName, sz) || sz != size.second) - res = EOnDiskOutOfDate; + res = TStatus::EOnDiskOutOfDate; } } return res; } - void Storage::DownloadCountry(TIndex const & index) + void Storage::CountryStatusEx(TIndex const & index, TStatus & status, TMapOptions & options) const + { + ///@TODO for vng + status = CountryStatusEx(index); + } + + void Storage::DownloadCountry(TIndex const & index, TMapOptions const & options) { +#ifdef DEBUG + if (options & TMapOptions::EMapWithCarRouting) + ASSERT(options & TMapOptions::EMapOnly, ()); +#endif + ///@TODO for vng. Process options // check if we already downloading this country TQueue::const_iterator found = find(m_queue.begin(), m_queue.end(), index); if (found != m_queue.end()) @@ -280,7 +228,6 @@ namespace storage void Storage::NotifyStatusChanged(TIndex const & index) { - UpdateDownloadedCountriesState(); for (list<CountryObservers>::const_iterator it = m_observers.begin(); it != m_observers.end(); ++it) it->m_changeCountryFn(index); } @@ -518,7 +465,7 @@ namespace storage IsNotOutdatedFilter(Storage const & storage) : m_storage(storage) {} bool operator() (string const & file) const { - return (m_storage.CountryStatusEx(m_storage.FindIndexByFile(file)) != EOnDiskOutOfDate); + return (m_storage.CountryStatusEx(m_storage.FindIndexByFile(file)) != TStatus::EOnDiskOutOfDate); } }; } diff --git a/storage/storage.hpp b/storage/storage.hpp index 1167a2335f..388d8fd13b 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -1,5 +1,6 @@ #pragma once +#include "storage_defines.hpp" #include "country.hpp" #include "index.hpp" #include "guides.hpp" @@ -16,18 +17,6 @@ namespace storage { - /// Used in GUI - enum TStatus - { - EOnDisk = 0, - ENotDownloaded, - EDownloadFailed, - EDownloading, - EInQueue, - EUnknown, - EOnDiskOutOfDate - }; - /// Can be used to store local maps and/or maps available for download class Storage { @@ -57,7 +46,7 @@ namespace storage /// @name Communicate with GUI //@{ typedef function<void (TIndex const &)> TChangeCountryFunction; - typedef function<void (TIndex const &, pair<int64_t, int64_t> const &)> TProgressFunction; + typedef function<void (TIndex const &, LocalAndRemoteSizeT const &)> TProgressFunction; int m_currentSlotId; @@ -106,27 +95,24 @@ namespace storage //@} Country const & CountryByIndex(TIndex const & index) const; - TIndex const & GetDownloadedCountryAt(size_t const & i) const; - TIndex const & GetOutOfDateCountryAt(size_t const & i) const; - TIndex FindIndexByFile(string const & name) const; void GetGroupAndCountry(TIndex const & index, string & group, string & country) const; size_t CountriesCount(TIndex const & index) const; - size_t GetDownloadedCountriesCount() const; - size_t GetOutOfDateCountriesCount() const; string const & CountryName(TIndex const & index) const; string const & CountryFlag(TIndex const & index) const; /// @return Country file name without extension. string const & CountryFileName(TIndex const & index) const; LocalAndRemoteSizeT CountrySizeInBytes(TIndex const & index) const; + LocalAndRemoteSizeT CountrySizeInBytesEx(TIndex const & index, TMapOptions const & options) const; /// Fast version, doesn't check if country is out of date TStatus CountryStatus(TIndex const & index) const; /// Slow version, but checks if country is out of date TStatus CountryStatusEx(TIndex const & index) const; + void CountryStatusEx(TIndex const & index, TStatus & status, TMapOptions & options) const; //m2::RectD CountryBounds(TIndex const & index) const; - void DownloadCountry(TIndex const & index); + void DownloadCountry(TIndex const & index, TMapOptions const & options); bool DeleteFromDownloader(TIndex const & index); bool IsDownloadInProgress() const; @@ -143,9 +129,6 @@ namespace storage private: guides::GuidesManager m_guideManager; - void UpdateDownloadedCountriesState(); - void UpdateDownloadedCountriesState(TIndex const index); - public: guides::GuidesManager const & GetGuideManager() const { return m_guideManager; } guides::GuidesManager & GetGuideManager() { return m_guideManager; } diff --git a/storage/storage.pro b/storage/storage.pro index c3cb3a2009..68bfca9d88 100644 --- a/storage/storage.pro +++ b/storage/storage.pro @@ -19,6 +19,7 @@ HEADERS += \ country_decl.hpp \ index.hpp \ guides.hpp \ + storage_defines.hpp \ SOURCES += \ country.cpp \ diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp new file mode 100644 index 0000000000..454663cf64 --- /dev/null +++ b/storage/storage_defines.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "../std/stdint.hpp" +#include "../std/utility.hpp" + +namespace storage +{ + /// Used in GUI + enum class TStatus : int + { + EOnDisk = 0, + ENotDownloaded, + EDownloadFailed, + EDownloading, + EInQueue, + EUnknown, + EOnDiskOutOfDate, + EOutOfMemFailed // EDownloadFailed because not enougth memory + }; + + enum class TMapOptions : int + { + EMapOnly = 0x1, + ECarRouting = 0x2, + EMapWithCarRouting = 0x3 + }; + + inline TMapOptions operator | (TMapOptions const & lhs, TMapOptions const & rhs) + { + return static_cast<TMapOptions>(static_cast<int>(lhs) | static_cast<int>(rhs)); + } + + inline TMapOptions & operator |= (TMapOptions & lhs, TMapOptions rhs) + { + lhs = static_cast<TMapOptions>(static_cast<int>(lhs) | static_cast<int>(rhs)); + return lhs; + } + + inline bool operator & (TMapOptions const & testedFlags, TMapOptions const & match) + { + return (static_cast<int>(testedFlags) & static_cast<int>(match)) != 0; + } + + typedef pair<uint64_t, uint64_t> LocalAndRemoteSizeT; +} |