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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/observer_list.hpp8
-rw-r--r--drape_head/drape_surface.cpp3
-rw-r--r--generator/generator_tests/check_mwms.cpp4
-rw-r--r--generator/routing_generator.cpp6
-rw-r--r--indexer/index.cpp74
-rw-r--r--indexer/index.hpp36
-rw-r--r--indexer/indexer_tests/index_test.cpp12
-rw-r--r--indexer/indexer_tests/mwm_set_test.cpp6
-rw-r--r--indexer/mwm_set.cpp21
-rw-r--r--indexer/mwm_set.hpp24
-rw-r--r--map/benchmark_engine.cpp5
-rw-r--r--map/benchmark_tool/features_loading.cpp4
-rw-r--r--map/feature_vec_model.cpp24
-rw-r--r--map/feature_vec_model.hpp8
-rw-r--r--map/framework.cpp17
-rw-r--r--map/framework.hpp7
-rw-r--r--map/map_tests/bookmarks_test.cpp5
-rw-r--r--map/mwm_tests/multithread_mwm_test.cpp4
-rw-r--r--map/mwm_tests/mwm_foreach_test.cpp4
-rw-r--r--map/mwm_tests/mwm_index_test.cpp4
-rw-r--r--search/search_tests/house_detector_tests.cpp15
-rw-r--r--search/search_tests/locality_finder_test.cpp5
22 files changed, 185 insertions, 111 deletions
diff --git a/base/observer_list.hpp b/base/observer_list.hpp
index 915c78f1d8..6599afbe91 100644
--- a/base/observer_list.hpp
+++ b/base/observer_list.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "../base/logging.hpp"
+
#include "../std/algorithm.hpp"
#include "../std/mutex.hpp"
#include "../std/vector.hpp"
@@ -17,7 +19,10 @@ public:
lock_guard<mutex> lock(m_observersLock);
auto it = find(m_observers.begin(), m_observers.end(), &observer);
if (it != m_observers.end())
+ {
+ LOG(LWARNING, ("Can't add the same observer twice:", &observer));
return false;
+ }
m_observers.push_back(&observer);
return true;
}
@@ -27,7 +32,10 @@ public:
lock_guard<mutex> lock(m_observersLock);
auto it = find(m_observers.begin(), m_observers.end(), &observer);
if (it == m_observers.end())
+ {
+ LOG(LWARNING, ("Can't remove non-registered observer:", &observer));
return false;
+ }
m_observers.erase(it);
return true;
}
diff --git a/drape_head/drape_surface.cpp b/drape_head/drape_surface.cpp
index 8a41da185b..e1286e27cf 100644
--- a/drape_head/drape_surface.cpp
+++ b/drape_head/drape_surface.cpp
@@ -32,7 +32,8 @@ DrapeSurface::DrapeSurface()
Platform & pl = GetPlatform();
pl.GetFilesByExt(pl.WritableDir(), DATA_FILE_EXTENSION, maps);
- for_each(maps.begin(), maps.end(), bind(&model::FeaturesFetcher::RegisterMap, &m_model, _1));
+ feature::DataHeader::Version version;
+ for_each(maps.begin(), maps.end(), bind(&model::FeaturesFetcher::RegisterMap, &m_model, _1, version));
///}
///
m_navigator.LoadState();
diff --git a/generator/generator_tests/check_mwms.cpp b/generator/generator_tests/check_mwms.cpp
index 45a3f417e6..cc97cf4c21 100644
--- a/generator/generator_tests/check_mwms.cpp
+++ b/generator/generator_tests/check_mwms.cpp
@@ -2,6 +2,7 @@
#include "../../map/feature_vec_model.hpp"
+#include "../../indexer/data_header.hpp"
#include "../../indexer/interval_index.hpp"
#include "../../platform/platform.hpp"
@@ -23,7 +24,8 @@ UNIT_TEST(CheckMWM_LoadAll)
{
try
{
- m.RegisterMap(s);
+ feature::DataHeader::Version version;
+ m.RegisterMap(s, version);
}
catch (RootException const & ex)
{
diff --git a/generator/routing_generator.cpp b/generator/routing_generator.cpp
index 56e38e40ca..7e5648e634 100644
--- a/generator/routing_generator.cpp
+++ b/generator/routing_generator.cpp
@@ -9,10 +9,11 @@
#include "../routing/osrm_router.hpp"
#include "../routing/cross_routing_context.hpp"
-#include "../indexer/index.hpp"
#include "../indexer/classificator_loader.hpp"
+#include "../indexer/data_header.hpp"
#include "../indexer/feature.hpp"
#include "../indexer/ftypes_matcher.hpp"
+#include "../indexer/index.hpp"
#include "../indexer/mercator.hpp"
#include "../geometry/distance_on_sphere.hpp"
@@ -226,7 +227,8 @@ void BuildRoutingIndex(string const & baseDir, string const & countryName, strin
string const mwmFile = baseDir + countryName + DATA_FILE_EXTENSION;
Index index;
m2::RectD rect;
- if (!index.Register(mwmFile, rect))
+ feature::DataHeader::Version version;
+ if (!index.Register(mwmFile, rect, version))
{
LOG(LCRITICAL, ("MWM file not found"));
return;
diff --git a/indexer/index.cpp b/indexer/index.cpp
index b07c6375ec..724e0fede3 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -1,5 +1,4 @@
#include "index.hpp"
-#include "data_header.hpp"
#include "../platform/platform.hpp"
@@ -41,23 +40,23 @@ string Index::MwmLock::GetFileName() const
// Index implementation
//////////////////////////////////////////////////////////////////////////////////
-int Index::GetInfo(string const & name, MwmInfo & info) const
+bool Index::GetVersion(string const & name, MwmInfo & info,
+ feature::DataHeader::Version & version) const
{
MwmValue value(name);
feature::DataHeader const & h = value.GetHeader();
- if (h.IsMWMSuitable())
- {
- info.m_limitRect = h.GetBounds();
+ if (!h.IsMWMSuitable())
+ return false;
- pair<int, int> const scaleR = h.GetScaleRange();
- info.m_minScale = static_cast<uint8_t>(scaleR.first);
- info.m_maxScale = static_cast<uint8_t>(scaleR.second);
+ info.m_limitRect = h.GetBounds();
- return h.GetVersion();
- }
- else
- return -1;
+ pair<int, int> const scaleR = h.GetScaleRange();
+ info.m_minScale = static_cast<uint8_t>(scaleR.first);
+ info.m_maxScale = static_cast<uint8_t>(scaleR.second);
+
+ version = h.GetVersion();
+ return true;
}
MwmValue * Index::CreateValue(string const & name) const
@@ -105,28 +104,30 @@ namespace
}
}
-int Index::RegisterMap(string const & fileName, m2::RectD & rect)
+bool Index::RegisterMap(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version)
{
if (GetPlatform().IsFileExistsByFullPath(GetFullPath(fileName + READY_FILE_EXTENSION)))
{
- int const ret = UpdateMap(fileName, rect);
- switch (ret)
+ UpdateStatus status = UpdateMap(fileName, rect, version);
+ switch (status)
{
- case -1:
- return -1;
- case -2:
- // Not dangerous, but it's strange when adding existing maps.
- ASSERT(false, ());
- return feature::DataHeader::v3;
- default:
- return ret;
+ case UPDATE_STATUS_OK:
+ return true;
+ case UPDATE_STATUS_BAD_FILE:
+ return false;
+ case UPDATE_STATUS_UPDATE_DELAYED:
+ // Not dangerous, but it's strange when adding existing maps.
+ ASSERT(false, ());
+ version = feature::DataHeader::v3;
+ return true;
}
}
- int rv = Register(fileName, rect);
- if (rv >= 0)
- m_observers.ForEach(&Observer::OnMapRegistered, fileName);
- return rv;
+ if (!Register(fileName, rect, version))
+ return false;
+ m_observers.ForEach(&Observer::OnMapRegistered, fileName);
+ return true;
}
bool Index::DeleteMap(string const & fileName)
@@ -153,9 +154,10 @@ bool Index::RemoveObserver(Observer & observer)
return m_observers.Remove(observer);
}
-int Index::UpdateMap(string const & fileName, m2::RectD & rect)
+Index::UpdateStatus Index::UpdateMap(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version)
{
- int rv = -1;
+ UpdateStatus status = UPDATE_STATUS_OK;
{
lock_guard<mutex> lock(m_lock);
@@ -163,17 +165,19 @@ int Index::UpdateMap(string const & fileName, m2::RectD & rect)
if (id != INVALID_MWM_ID && m_info[id].m_lockCount > 0)
{
m_info[id].SetStatus(MwmInfo::STATUS_PENDING_UPDATE);
- rv = -2;
- } else {
+ status = UPDATE_STATUS_UPDATE_DELAYED;
+ }
+ else
+ {
ReplaceFileWithReady(fileName);
- rv = RegisterImpl(fileName, rect);
+ status = RegisterImpl(fileName, rect, version) ? UPDATE_STATUS_OK : UPDATE_STATUS_BAD_FILE;
}
}
- if (rv != -1)
+ if (status != UPDATE_STATUS_BAD_FILE)
m_observers.ForEach(&Observer::OnMapUpdateIsReady, fileName);
- if (rv >= 0)
+ if (status == UPDATE_STATUS_OK)
m_observers.ForEach(&Observer::OnMapUpdated, fileName);
- return rv;
+ return status;
}
void Index::UpdateMwmInfo(MwmId id)
diff --git a/indexer/index.hpp b/indexer/index.hpp
index 1e1f97080d..aa21d9f714 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -30,16 +30,23 @@ public:
string GetFileName() const;
};
-
class Index : public MwmSet
{
protected:
- /// @return mwm format version or -1 if file isn't suitable (greater version).
- virtual int GetInfo(string const & name, MwmInfo & info) const;
- virtual MwmValue * CreateValue(string const & name) const;
- virtual void UpdateMwmInfo(MwmId id);
+ // MwmSet overrides:
+ bool GetVersion(string const & name, MwmInfo & info,
+ feature::DataHeader::Version & version) const override;
+ MwmValue * CreateValue(string const & name) const override;
+ void UpdateMwmInfo(MwmId id) override;
public:
+ enum UpdateStatus
+ {
+ UPDATE_STATUS_OK,
+ UPDATE_STATUS_BAD_FILE,
+ UPDATE_STATUS_UPDATE_DELAYED
+ };
+
/// An Observer interface to MwmSet. Note that these functions can
/// be called from *ANY* thread because most signals are sent when
/// some thread releases its MwmLock, so overrides must be as fast
@@ -84,17 +91,24 @@ public:
/// Registers new map.
///
- /// \return mwm format version or -1 if file isn't suitable (greater
- /// version).
- int RegisterMap(string const & fileName, m2::RectD & rect);
+ /// \return True if map was successfully registered. In this case
+ /// version is set to the file format version. Otherwise
+ /// returns false and version is not modified. This means
+ /// that file isn't suitable, for example, because of
+ /// greater version.
+ bool RegisterMap(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version);
/// Replaces map file corresponding to fileName with a new one, when
/// it's possible - no clients of the map file. Otherwise, update
/// will be delayed.
///
- /// \return mwm format version or -1 if file isn't suitable (greater
- /// version). -2 if file is busy now (delayed update).
- int UpdateMap(string const & fileName, m2::RectD & rect);
+ /// \return UPDATE_STATUS_OK, when map file have updated, as a side effect
+ /// sets version to an mwm format version.
+ /// UPDATE_STATUS_BAD_FILE when file isn't suitable for update.
+ /// UPDATE_STATUS_UPDATE_DELAYED when update is delayed.
+ UpdateStatus UpdateMap(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version);
/// Deletes map both from file system and internal tables, also,
/// deletes all files related to the map. If map was successfully
diff --git a/indexer/indexer_tests/index_test.cpp b/indexer/indexer_tests/index_test.cpp
index 8d09c4d653..7fbd85b4e1 100644
--- a/indexer/indexer_tests/index_test.cpp
+++ b/indexer/indexer_tests/index_test.cpp
@@ -1,4 +1,6 @@
#include "../../testing/testing.hpp"
+
+#include "../data_header.hpp"
#include "../index.hpp"
#include "../../coding/file_name_utils.hpp"
@@ -75,7 +77,8 @@ UNIT_TEST(Index_Parse)
Index index;
m2::RectD dummyRect;
- index.RegisterMap("minsk-pass" DATA_FILE_EXTENSION, dummyRect);
+ feature::DataHeader::Version dummyVersion;
+ index.RegisterMap("minsk-pass" DATA_FILE_EXTENSION, dummyRect, dummyVersion);
// Make sure that index is actually parsed.
NoopFunctor fn;
@@ -100,14 +103,15 @@ UNIT_TEST(Index_MwmStatusNotifications)
TEST_EQUAL(0, observer.map_registered_calls(), ());
m2::RectD dummyRect;
+ feature::DataHeader::Version dummyVersion;
// Check that observers are triggered after map registration.
- TEST_LESS_OR_EQUAL(0, index.RegisterMap(testMapName, dummyRect), ());
+ TEST(index.RegisterMap(testMapName, dummyRect, dummyVersion), ());
TEST_EQUAL(1, observer.map_registered_calls(), ());
// Check that map can't registered twice and observers aren't
// triggered.
- TEST_EQUAL(-1, index.RegisterMap(testMapName, dummyRect), ());
+ TEST(!index.RegisterMap(testMapName, dummyRect, dummyVersion), ());
TEST_EQUAL(1, observer.map_registered_calls(), ());
TEST(my::CopyFileX(testMapPath, testMapUpdatePath), ());
@@ -116,7 +120,7 @@ UNIT_TEST(Index_MwmStatusNotifications)
// Check that observers are notified when map is deleted.
TEST_EQUAL(0, observer.map_update_is_ready_calls(), ());
TEST_EQUAL(0, observer.map_updated_calls(), ());
- TEST_LESS_OR_EQUAL(0, index.UpdateMap(testMapName, dummyRect), ());
+ TEST_EQUAL(Index::UPDATE_STATUS_OK, index.UpdateMap(testMapName, dummyRect, dummyVersion), ());
TEST_EQUAL(1, observer.map_update_is_ready_calls(), ());
TEST_EQUAL(1, observer.map_updated_calls(), ());
diff --git a/indexer/indexer_tests/mwm_set_test.cpp b/indexer/indexer_tests/mwm_set_test.cpp
index 12eb87a7a3..6b1f15b520 100644
--- a/indexer/indexer_tests/mwm_set_test.cpp
+++ b/indexer/indexer_tests/mwm_set_test.cpp
@@ -11,12 +11,14 @@ namespace
class TestMwmSet : public MwmSet
{
protected:
- virtual int GetInfo(string const & path, MwmInfo & info) const
+ virtual bool GetVersion(string const & path, MwmInfo & info,
+ feature::DataHeader::Version & version) const
{
int n = path[0] - '0';
info.m_maxScale = n;
info.m_limitRect = m2::RectD(0, 0, 1, 1);
- return 1;
+ version = feature::DataHeader::lastVersion;
+ return true;
}
virtual MwmValue * CreateValue(string const &) const
{
diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp
index 46d9bea017..359640066d 100644
--- a/indexer/mwm_set.cpp
+++ b/indexer/mwm_set.cpp
@@ -102,7 +102,8 @@ MwmSet::MwmId MwmSet::GetIdByName(string const & name)
return INVALID_MWM_ID;
}
-int MwmSet::Register(string const & fileName, m2::RectD & rect)
+bool MwmSet::Register(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version)
{
lock_guard<mutex> lock(m_lock);
@@ -110,23 +111,23 @@ int MwmSet::Register(string const & fileName, m2::RectD & rect)
if (id != INVALID_MWM_ID)
{
if (m_info[id].IsRegistered())
- LOG(LWARNING, ("Trying to add already added map", fileName));
+ LOG(LWARNING, ("Trying to add already registered map", fileName));
else
m_info[id].SetStatus(MwmInfo::STATUS_UP_TO_DATE);
- return -1;
+ return false;
}
- return RegisterImpl(fileName, rect);
+ return RegisterImpl(fileName, rect, version);
}
-int MwmSet::RegisterImpl(string const & fileName, m2::RectD & rect)
+bool MwmSet::RegisterImpl(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version)
{
// this function can throw an exception for bad mwm file
MwmInfo info;
- int const version = GetInfo(fileName, info);
- if (version == -1)
- return -1;
+ if (!GetVersion(fileName, info, version))
+ return false;
info.SetStatus(MwmInfo::STATUS_UP_TO_DATE);
@@ -135,8 +136,8 @@ int MwmSet::RegisterImpl(string const & fileName, m2::RectD & rect)
m_info[id] = info;
rect = info.m_limitRect;
- ASSERT ( rect.IsValid(), () );
- return version;
+ ASSERT(rect.IsValid(), ());
+ return true;
}
bool MwmSet::DeregisterImpl(MwmId id)
diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp
index f179831c6b..6d045a6877 100644
--- a/indexer/mwm_set.hpp
+++ b/indexer/mwm_set.hpp
@@ -1,4 +1,7 @@
#pragma once
+
+#include "data_header.hpp"
+
#include "../geometry/rect2d.hpp"
#include "../std/deque.hpp"
@@ -83,20 +86,25 @@ public:
/// Registers new map in the set.
/// @param[in] fileName File name (without full path) of country.
/// @param[out] rect Limit rect of country.
- /// @return Map format version or -1 if not added (already exists).
+ /// @param[out] version Version of the file.
+ ///
+ /// @return True when map is registered, false otherwise - map already
+ /// exists or it's not possible to get mwm's version.
//@{
protected:
- int RegisterImpl(string const & fileName, m2::RectD & rect);
+ bool RegisterImpl(string const & fileName, m2::RectD & rect,
+ feature::DataHeader::Version & version);
public:
- int Register(string const & fileName, m2::RectD & rect);
+ bool Register(string const & fileName, m2::RectD & rect, feature::DataHeader::Version & version);
//@}
/// Used in unit tests only.
inline void Register(string const & fileName)
{
- m2::RectD dummy;
- CHECK(Register(fileName, dummy), ());
+ m2::RectD dummyRect;
+ feature::DataHeader::Version dummyVersion;
+ CHECK(Register(fileName, dummyRect, dummyVersion), ());
}
/// @name Remove mwm.
@@ -126,8 +134,10 @@ public:
void ClearCache();
protected:
- /// @return mwm format version
- virtual int GetInfo(string const & name, MwmInfo & info) const = 0;
+ /// @return True when it's possible to get file format version - in
+ /// this case version is set to the file format version.
+ virtual bool GetVersion(string const & name, MwmInfo & info,
+ feature::DataHeader::Version & version) const = 0;
virtual MwmValueBase * CreateValue(string const & name) const = 0;
void Cleanup();
diff --git a/map/benchmark_engine.cpp b/map/benchmark_engine.cpp
index 511035d11f..94dd3b8296 100644
--- a/map/benchmark_engine.cpp
+++ b/map/benchmark_engine.cpp
@@ -1,6 +1,8 @@
#include "benchmark_engine.hpp"
#include "framework.hpp"
+#include "../indexer/data_header.hpp"
+
#include "../platform/settings.hpp"
#include "../platform/platform.hpp"
@@ -131,8 +133,9 @@ void BenchmarkEngine::PrepareMaps()
// add only maps needed for benchmarks
MapsCollector collector;
ForEachBenchmarkRecord(collector);
+ feature::DataHeader::Version version;
for_each(collector.m_maps.begin(), collector.m_maps.end(),
- bind(&Framework::RegisterMap, m_framework, _1));
+ bind(&Framework::RegisterMap, m_framework, _1, version));
}
BenchmarkEngine::BenchmarkEngine(Framework * fw)
diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp
index 0f56adcc04..efb6225336 100644
--- a/map/benchmark_tool/features_loading.cpp
+++ b/map/benchmark_tool/features_loading.cpp
@@ -3,6 +3,7 @@
#include "../feature_vec_model.hpp"
#include "../../indexer/data_factory.hpp"
+#include "../../indexer/data_header.hpp"
#include "../../indexer/feature_visibility.hpp"
#include "../../indexer/scales.hpp"
@@ -109,7 +110,8 @@ void RunFeaturesLoadingBenchmark(string const & file, pair<int, int> scaleR, All
return;
model::FeaturesFetcher src;
- src.RegisterMap(file);
+ feature::DataHeader::Version version;
+ src.RegisterMap(file, version);
RunBenchmark(src, header.GetBounds(), scaleR, res);
}
diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp
index 5acb0699a3..3ad91ec761 100644
--- a/map/feature_vec_model.cpp
+++ b/map/feature_vec_model.cpp
@@ -32,26 +32,25 @@ void FeaturesFetcher::InitClassificator()
}
}
-int FeaturesFetcher::RegisterMap(string const & file)
+bool FeaturesFetcher::RegisterMap(string const & file, feature::DataHeader::Version & version)
{
- int version = -1;
-
try
{
m2::RectD r;
- version = m_multiIndex.RegisterMap(file, r);
-
- if (version != -1)
- m_rect.Add(r);
- else
- LOG(LWARNING, ("Can't add map", file, "Probably it's already added or has newer data version."));
+ if (!m_multiIndex.RegisterMap(file, r, version))
+ {
+ LOG(LWARNING,
+ ("Can't add map", file, "Probably it's already added or has newer data version."));
+ return false;
+ }
+ m_rect.Add(r);
+ return true;
}
catch (RootException const & e)
{
LOG(LERROR, ("IO error while adding ", file, " map. ", e.what()));
+ return false;
}
-
- return version;
}
void FeaturesFetcher::DeregisterMap(string const & file) { m_multiIndex.Deregister(file); }
@@ -65,7 +64,8 @@ bool FeaturesFetcher::DeleteMap(string const & file)
bool FeaturesFetcher::UpdateMap(string const & file, m2::RectD & rect)
{
- return m_multiIndex.UpdateMap(file, rect) >= 0;
+ feature::DataHeader::Version version;
+ return m_multiIndex.UpdateMap(file, rect, version);
}
//void FeaturesFetcher::Clean()
diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp
index b786ced872..f0de9c28b3 100644
--- a/map/feature_vec_model.hpp
+++ b/map/feature_vec_model.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "../indexer/data_header.hpp"
#include "../indexer/index.hpp"
#include "../geometry/rect2d.hpp"
@@ -30,9 +31,10 @@ namespace model
void InitClassificator();
/// @param[in] file Name of mwm file with extension.
- //@{
- /// @return MWM format version for file or -1 if error and map was not added
- int RegisterMap(string const & file);
+ //{@
+ /// @return True when map was successfully registered, also, sets
+ /// version to the file format version.
+ bool RegisterMap(string const & file, feature::DataHeader::Version & version);
/// Deregisters map denoted by file from internal records.
void DeregisterMap(string const & file);
diff --git a/map/framework.cpp b/map/framework.cpp
index 551b2730b1..446093381d 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -84,11 +84,13 @@ namespace
static const int BM_TOUCH_PIXEL_INCREASE = 20;
}
-int Framework::RegisterMap(string const & file)
+bool Framework::RegisterMap(string const & file, feature::DataHeader::Version & version)
{
LOG(LINFO, ("Loading map:", file));
- int const version = m_model.RegisterMap(file);
+ if (!m_model.RegisterMap(file, version))
+ return false;
+
if (version == feature::DataHeader::v1)
{
// Now we do force delete of old (April 2011) maps.
@@ -97,10 +99,11 @@ int Framework::RegisterMap(string const & file)
DeregisterMap(file);
VERIFY(my::DeleteFileX(GetPlatform().WritablePathForFile(file)), ());
- return -1;
+ version = feature::DataHeader::unknownVersion;
+ return false;
}
- return version;
+ return true;
}
void Framework::DeregisterMap(string const & file) { m_model.DeregisterMap(file); }
@@ -408,9 +411,9 @@ void Framework::RegisterAllMaps()
GetMaps(maps);
for_each(maps.begin(), maps.end(), [&](string const & file)
{
- int const v = RegisterMap(file);
- if (v != -1 && v < minVersion)
- minVersion = v;
+ feature::DataHeader::Version version;
+ if (RegisterMap(file, version) && version < minVersion)
+ minVersion = version;
});
m_countryTree.Init(maps);
diff --git a/map/framework.hpp b/map/framework.hpp
index 503e82ef9f..15bd80a419 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -25,6 +25,8 @@
#include "routing_session.hpp"
#include "country_tree.hpp"
+#include "../indexer/data_header.hpp"
+
#include "../search/search_engine.hpp"
#include "../storage/storage.hpp"
@@ -170,8 +172,9 @@ public:
/// Registers local map file in internal indexes.
///
- /// @return Inner mwm data version from header or -1 in case of error.
- int RegisterMap(string const & file);
+ /// @return True and inner mwm data version from header in version
+ /// or false in case of errors.
+ bool RegisterMap(string const & file, feature::DataHeader::Version & version);
//@}
/// Deletes all disk files corresponding to country.
diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp
index ee7cd28d8e..f20ec89f87 100644
--- a/map/map_tests/bookmarks_test.cpp
+++ b/map/map_tests/bookmarks_test.cpp
@@ -1,5 +1,7 @@
#include "../../testing/testing.hpp"
+#include "../../indexer/data_header.hpp"
+
#include "../../map/framework.hpp"
#include "../../search/result.hpp"
@@ -398,7 +400,8 @@ UNIT_TEST(Bookmarks_AddressInfo)
// Maps added in constructor (we need minsk-pass.mwm only)
Framework fm;
fm.DeregisterAllMaps();
- fm.RegisterMap("minsk-pass.mwm");
+ feature::DataHeader::Version version;
+ fm.RegisterMap("minsk-pass.mwm", version);
fm.OnSize(800, 600);
diff --git a/map/mwm_tests/multithread_mwm_test.cpp b/map/mwm_tests/multithread_mwm_test.cpp
index ea5b9706e5..83b387e4cd 100644
--- a/map/mwm_tests/multithread_mwm_test.cpp
+++ b/map/mwm_tests/multithread_mwm_test.cpp
@@ -62,7 +62,9 @@ namespace
{
SourceT src;
src.InitClassificator();
- src.RegisterMap(file + DATA_FILE_EXTENSION);
+
+ feature::DataHeader::Version version;
+ src.RegisterMap(file + DATA_FILE_EXTENSION, version);
// Check that country rect is valid and not infinity.
m2::RectD const r = src.GetWorldRect();
diff --git a/map/mwm_tests/mwm_foreach_test.cpp b/map/mwm_tests/mwm_foreach_test.cpp
index 15c2544299..a6ee0375e3 100644
--- a/map/mwm_tests/mwm_foreach_test.cpp
+++ b/map/mwm_tests/mwm_foreach_test.cpp
@@ -250,7 +250,9 @@ void RunTest(string const & file)
{
model::FeaturesFetcher src1;
src1.InitClassificator();
- src1.RegisterMap(file);
+
+ feature::DataHeader::Version version;
+ src1.RegisterMap(file, version);
vector<m2::RectD> rects;
rects.push_back(src1.GetWorldRect());
diff --git a/map/mwm_tests/mwm_index_test.cpp b/map/mwm_tests/mwm_index_test.cpp
index f162d4c39b..a0ad429bf0 100644
--- a/map/mwm_tests/mwm_index_test.cpp
+++ b/map/mwm_tests/mwm_index_test.cpp
@@ -39,7 +39,8 @@ public:
bool RunTest(string const & fileName, int lowS, int highS)
{
model::FeaturesFetcher src;
- if (src.RegisterMap(fileName) == -1)
+ feature::DataHeader::Version version;
+ if (!src.RegisterMap(fileName, version) || version == feature::DataHeader::unknownVersion)
return false;
CheckNonEmptyGeometry doCheck;
@@ -52,7 +53,6 @@ bool RunTest(string const & fileName, int lowS, int highS)
return true;
}
-
}
UNIT_TEST(ForEachFeatureID_Test)
diff --git a/search/search_tests/house_detector_tests.cpp b/search/search_tests/house_detector_tests.cpp
index 689a79d140..4a11789e68 100644
--- a/search/search_tests/house_detector_tests.cpp
+++ b/search/search_tests/house_detector_tests.cpp
@@ -8,10 +8,11 @@
#include "../../geometry/distance_on_sphere.hpp"
+#include "../../indexer/classificator_loader.hpp"
+#include "../../indexer/data_header.hpp"
#include "../../indexer/ftypes_matcher.hpp"
-#include "../../indexer/scales.hpp"
#include "../../indexer/index.hpp"
-#include "../../indexer/classificator_loader.hpp"
+#include "../../indexer/scales.hpp"
#include "../../std/iostream.hpp"
#include "../../std/fstream.hpp"
@@ -183,8 +184,8 @@ UNIT_TEST(HS_StreetsMerge)
Index index;
m2::RectD rect;
-
- TEST(index.Register("minsk-pass.mwm", rect), ());
+ feature::DataHeader::Version version;
+ TEST(index.Register("minsk-pass.mwm", rect, version), ());
{
search::HouseDetector houser(&index);
@@ -272,7 +273,8 @@ UNIT_TEST(HS_FindHouseSmoke)
Index index;
m2::RectD rect;
- index.Register("minsk-pass.mwm", rect);
+ feature::DataHeader::Version version;
+ index.Register("minsk-pass.mwm", rect, version);
{
vector<string> streetName(1, "Московская улица");
@@ -374,7 +376,8 @@ UNIT_TEST(HS_MWMSearch)
Index index;
m2::RectD rect;
- if (!index.Register(country + ".mwm", rect))
+ feature::DataHeader::Version version;
+ if (!index.Register(country + ".mwm", rect, version))
{
LOG(LWARNING, ("MWM file not found"));
return;
diff --git a/search/search_tests/locality_finder_test.cpp b/search/search_tests/locality_finder_test.cpp
index 10de3fd69e..dfd060e98e 100644
--- a/search/search_tests/locality_finder_test.cpp
+++ b/search/search_tests/locality_finder_test.cpp
@@ -1,6 +1,8 @@
#include "../../testing/testing.hpp"
+#include "../../indexer/data_header.hpp"
#include "../../indexer/index.hpp"
+
#include "../locality_finder.hpp"
namespace
@@ -33,7 +35,8 @@ UNIT_TEST(LocalityFinder)
{
Index index;
m2::RectD rect;
- TEST(index.Register("World.mwm", rect), ());
+ feature::DataHeader::Version version;
+ TEST(index.Register("World.mwm", rect, version), ());
search::LocalityFinder finder(&index);
finder.SetLanguage(StringUtf8Multilang::GetLangIndex("en"));