forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
f6bba24d00
commit
25f7a7f2f3
22 changed files with 186 additions and 112 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(), ());
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
#include "../../geometry/distance_on_sphere.hpp"
|
||||
|
||||
#include "../../indexer/ftypes_matcher.hpp"
|
||||
#include "../../indexer/scales.hpp"
|
||||
#include "../../indexer/index.hpp"
|
||||
#include "../../indexer/classificator_loader.hpp"
|
||||
#include "../../indexer/data_header.hpp"
|
||||
#include "../../indexer/ftypes_matcher.hpp"
|
||||
#include "../../indexer/index.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;
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Add table
Reference in a new issue