forked from organicmaps/organicmaps
[new downloader] Parsing field affiliations in countries.txt if any.
This commit is contained in:
parent
2c9057e44b
commit
ea089c4023
4 changed files with 53 additions and 23 deletions
|
@ -28,6 +28,7 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * node, TCountryId co
|
|||
if (!id)
|
||||
MYTHROW(my::Json::Exception, ("LoadGroupImpl. Id is missing.", id));
|
||||
|
||||
// Mapping two component (big) mwms to one componenst (small) ones.
|
||||
json_t * oldIds = json_object_get(node, "old");
|
||||
if (oldIds)
|
||||
{
|
||||
|
@ -35,7 +36,19 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * node, TCountryId co
|
|||
for (size_t k = 0; k < oldListSize; ++k)
|
||||
{
|
||||
string oldIdValue = json_string_value(json_array_get(oldIds, k));
|
||||
toDo(oldIdValue, id);
|
||||
toDo.InsertOldMwmMapping(id, oldIdValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Mapping affiliations to one componenst (small) mwms.
|
||||
json_t * affiliations = json_object_get(node, "affiliations");
|
||||
if (affiliations)
|
||||
{
|
||||
size_t const affiliationsSize = json_array_size(affiliations);
|
||||
for (size_t k = 0; k < affiliationsSize; ++k)
|
||||
{
|
||||
string affilationValue = json_string_value(json_array_get(affiliations, k));
|
||||
toDo.InsertAffiliation(id, affilationValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,10 +148,12 @@ namespace
|
|||
class DoStoreCountriesSingleMwms
|
||||
{
|
||||
TCountryTree & m_countries;
|
||||
TMapping m_idsMapping;
|
||||
TMappingAffiliations & m_affiliations;
|
||||
TMappingOldMwm m_idsMapping;
|
||||
|
||||
public:
|
||||
DoStoreCountriesSingleMwms(TCountryTree & countries) : m_countries(countries) {}
|
||||
DoStoreCountriesSingleMwms(TCountryTree & countries, TMappingAffiliations & affiliations)
|
||||
: m_countries(countries), m_affiliations(affiliations) {}
|
||||
|
||||
Country * operator()(TCountryId const & id, uint32_t mapSize, int depth, TCountryId const & parent)
|
||||
{
|
||||
|
@ -152,12 +167,17 @@ public:
|
|||
return &m_countries.AddAtDepth(depth, country);
|
||||
}
|
||||
|
||||
void operator()(TCountryId const & oldId, TCountryId const & newId)
|
||||
void InsertOldMwmMapping(TCountryId const & newId, TCountryId const & oldId)
|
||||
{
|
||||
m_idsMapping[oldId].insert(newId);
|
||||
}
|
||||
|
||||
TMapping GetMapping() const { return m_idsMapping; }
|
||||
void InsertAffiliation(TCountryId const & countryId, string const affilation)
|
||||
{
|
||||
m_affiliations.insert(make_pair(countryId, affilation));
|
||||
}
|
||||
|
||||
TMappingOldMwm GetMapping() const { return m_idsMapping; }
|
||||
};
|
||||
|
||||
class DoStoreCountriesTwoComponentMwms
|
||||
|
@ -165,7 +185,8 @@ class DoStoreCountriesTwoComponentMwms
|
|||
TCountryTree & m_countries;
|
||||
|
||||
public:
|
||||
DoStoreCountriesTwoComponentMwms(TCountryTree & cont) : m_countries(cont) {}
|
||||
DoStoreCountriesTwoComponentMwms(TCountryTree & countries, TMappingAffiliations & /* affiliations */)
|
||||
: m_countries(countries) {}
|
||||
|
||||
void operator()(string const & file, uint32_t mapSize,
|
||||
uint32_t routingSize, int depth, TCountryId const & parent)
|
||||
|
@ -183,7 +204,7 @@ public:
|
|||
|
||||
class DoStoreFile2InfoSingleMwms
|
||||
{
|
||||
TMapping m_idsMapping;
|
||||
TMappingOldMwm m_idsMapping;
|
||||
map<string, CountryInfo> & m_file2info;
|
||||
|
||||
public:
|
||||
|
@ -198,17 +219,14 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void operator()(TCountryId const & oldId, TCountryId const & newId)
|
||||
{
|
||||
m_idsMapping[oldId].insert(newId);
|
||||
}
|
||||
void InsertOldMwmMapping(TCountryId const & /* newId */, TCountryId const & /* oldId */) {}
|
||||
|
||||
TMapping GetMapping() const { return m_idsMapping; }
|
||||
void InsertAffiliation(TCountryId const & /* countryId */, string const & /* affilation */) {}
|
||||
};
|
||||
|
||||
class DoStoreFile2InfoTwoComponentMwms
|
||||
{
|
||||
TMapping m_idsMapping;
|
||||
TMappingOldMwm m_idsMapping;
|
||||
map<string, CountryInfo> & m_file2info;
|
||||
|
||||
public:
|
||||
|
@ -228,9 +246,10 @@ public:
|
|||
} // namespace
|
||||
|
||||
int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries,
|
||||
TMapping * mapping /* = nullptr */)
|
||||
TMappingAffiliations & affiliations, TMappingOldMwm * mapping /* = nullptr */)
|
||||
{
|
||||
countries.Clear();
|
||||
affiliations.clear();
|
||||
|
||||
int64_t version = -1;
|
||||
try
|
||||
|
@ -241,7 +260,7 @@ int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries,
|
|||
|
||||
if (version::IsSingleMwm(version))
|
||||
{
|
||||
DoStoreCountriesSingleMwms doStore(countries);
|
||||
DoStoreCountriesSingleMwms doStore(countries, affiliations);
|
||||
if (!LoadCountriesSingleMwmsImpl(jsonBuffer, doStore))
|
||||
return -1;
|
||||
if (mapping)
|
||||
|
@ -249,7 +268,7 @@ int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries,
|
|||
}
|
||||
else
|
||||
{
|
||||
DoStoreCountriesTwoComponentMwms doStore(countries);
|
||||
DoStoreCountriesTwoComponentMwms doStore(countries, affiliations);
|
||||
if (!LoadCountriesTwoComponentMwmsImpl(jsonBuffer, doStore))
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ class SizeUpdater;
|
|||
|
||||
namespace storage
|
||||
{
|
||||
using TMapping = map<TCountryId, TCountriesSet>;
|
||||
using TMappingOldMwm = map<TCountryId, TCountriesSet>;
|
||||
using TMappingAffiliations = unordered_multimap<TCountryId, string>;
|
||||
|
||||
/// This class keeps all the information about a country in country tree (TCountryTree).
|
||||
/// It is guaranteed that every node represent a unique region has a unique |m_name| in country
|
||||
|
@ -79,7 +80,7 @@ using TCountryTreeNode = TCountryTree::Node;
|
|||
|
||||
/// @return version of country file or -1 if error was encountered
|
||||
int64_t LoadCountries(string const & jsonBuffer, TCountryTree & countries,
|
||||
TMapping * mapping = nullptr);
|
||||
TMappingAffiliations & affiliations, TMappingOldMwm * mapping = nullptr);
|
||||
|
||||
void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryInfo> & id2info,
|
||||
bool & isSingleMwm);
|
||||
|
|
|
@ -122,7 +122,7 @@ Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
|
|||
: m_downloader(move(mapDownloaderForTesting)), m_currentSlotId(0),
|
||||
m_downloadMapOnTheMap(nullptr)
|
||||
{
|
||||
m_currentVersion = LoadCountries(referenceCountriesTxtJsonForTesting, m_countries);
|
||||
m_currentVersion = LoadCountries(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations);
|
||||
CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file"));
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ void Storage::Migrate(TCountriesVec const & existedCountries)
|
|||
Clear();
|
||||
m_countries.Clear();
|
||||
|
||||
TMapping mapping;
|
||||
TMappingOldMwm mapping;
|
||||
LoadCountriesFile(COUNTRIES_FILE, m_dataDir, &mapping);
|
||||
|
||||
vector<TCountryId> prefetchedMaps;
|
||||
|
@ -622,7 +622,7 @@ TCountryId Storage::GetCurrentDownloadingCountryId() const
|
|||
}
|
||||
|
||||
void Storage::LoadCountriesFile(string const & pathToCountriesFile,
|
||||
string const & dataDir, TMapping * mapping /* = nullptr */)
|
||||
string const & dataDir, TMappingOldMwm * mapping /* = nullptr */)
|
||||
{
|
||||
m_dataDir = dataDir;
|
||||
|
||||
|
@ -636,7 +636,7 @@ void Storage::LoadCountriesFile(string const & pathToCountriesFile,
|
|||
{
|
||||
string json;
|
||||
ReaderPtr<Reader>(GetPlatform().GetReader(pathToCountriesFile)).ReadAsString(json);
|
||||
m_currentVersion = LoadCountries(json, m_countries, mapping);
|
||||
m_currentVersion = LoadCountries(json, m_countries, m_affiliations, mapping);
|
||||
LOG_SHORT(LINFO, ("Loaded countries list for version:", m_currentVersion));
|
||||
if (m_currentVersion < 0)
|
||||
LOG(LERROR, ("Can't load countries file", pathToCountriesFile));
|
||||
|
|
|
@ -191,12 +191,20 @@ private:
|
|||
|
||||
unique_ptr<Storage> m_prefetchStorage;
|
||||
|
||||
// |m_affiliations| is mapping countryIds (mwm file names) to geographical names
|
||||
// which includes the mwm.
|
||||
// |m_affiliations| is filled during Storage initialization or during migration process.
|
||||
// It is filled with data of countries.txt (field "affiliations").
|
||||
// Once filled |m_affiliations| is not changed.
|
||||
// Node. |m_affiliations| is empty in case of countries_obsolete.txt.
|
||||
TMappingAffiliations m_affiliations;
|
||||
|
||||
DECLARE_THREAD_CHECKER(m_threadChecker);
|
||||
|
||||
void DownloadNextCountryFromQueue();
|
||||
|
||||
void LoadCountriesFile(string const & pathToCountriesFile,
|
||||
string const & dataDir, TMapping * mapping = nullptr);
|
||||
string const & dataDir, TMappingOldMwm * mapping = nullptr);
|
||||
|
||||
void ReportProgress(TCountryId const & countryId, MapFilesDownloader::TProgress const & p);
|
||||
void ReportProgressForHierarchy(TCountryId const & countryId,
|
||||
|
@ -334,6 +342,8 @@ public:
|
|||
/// \return true if updateInfo is filled correctly and false otherwise.
|
||||
bool GetUpdateInfo(TCountryId const & countryId, UpdateInfo & updateInfo) const;
|
||||
|
||||
TMappingAffiliations & GetAffiliations() { return m_affiliations; }
|
||||
|
||||
/// \brief Calls |toDo| for each node for subtree with |root|.
|
||||
/// For example ForEachInSubtree(GetRootId()) calls |toDo| for every node including
|
||||
/// the result of GetRootId() call.
|
||||
|
|
Loading…
Add table
Reference in a new issue