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:
authorYuri Gorshenin <y@maps.me>2016-07-05 21:28:14 +0300
committerYuri Gorshenin <y@maps.me>2016-07-05 21:43:49 +0300
commitabad74b76c735eca873ee1384de40607993aec32 (patch)
tree888a078227bc383ced634f6332b3640061586baa /indexer
parente7915eb557ff76a913e934da17c601d71f891fe6 (diff)
[indexer] Fixed FeaturesLoaderGuard.
Diffstat (limited to 'indexer')
-rw-r--r--indexer/index.cpp34
-rw-r--r--indexer/index.hpp11
-rw-r--r--indexer/osm_editor.cpp17
-rw-r--r--indexer/osm_editor.hpp3
4 files changed, 41 insertions, 24 deletions
diff --git a/indexer/index.cpp b/indexer/index.cpp
index 830faa1adf..6caaa521f7 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -83,36 +83,52 @@ bool Index::DeregisterMap(CountryFile const & countryFile) { return Deregister(c
// Index::FeaturesLoaderGuard implementation
//////////////////////////////////////////////////////////////////////////////////
-Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId const & id)
- : m_handle(parent.GetMwmHandleById(id))
- , m_vector(m_handle.GetValue<MwmValue>()->m_cont, m_handle.GetValue<MwmValue>()->GetHeader(),
- m_handle.GetValue<MwmValue>()->m_table.get())
+Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & index, MwmId const & id)
+ : m_handle(index.GetMwmHandleById(id))
{
+ if (!m_handle.IsAlive())
+ return;
+
+ auto const & value = *m_handle.GetValue<MwmValue>();
+ m_vector = make_unique<FeaturesVector>(value.m_cont, value.GetHeader(), value.m_table.get());
}
string Index::FeaturesLoaderGuard::GetCountryFileName() const
{
if (!m_handle.IsAlive())
return string();
+
return m_handle.GetValue<MwmValue>()->GetCountryFileName();
}
bool Index::FeaturesLoaderGuard::IsWorld() const
{
+ if (!m_handle.IsAlive())
+ return false;
+
return m_handle.GetValue<MwmValue>()->GetHeader().GetType() == feature::DataHeader::world;
}
-void Index::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t index, FeatureType & ft) const
+bool Index::FeaturesLoaderGuard::GetFeatureByIndex(uint32_t index, FeatureType & ft) const
{
+ if (!m_handle.IsAlive())
+ return false;
+
MwmId const & id = m_handle.GetId();
ASSERT_NOT_EQUAL(osm::Editor::FeatureStatus::Deleted, m_editor.GetFeatureStatus(id, index),
("Deleted feature was cached. It should not be here. Please review your code."));
- if (!m_editor.Instance().GetEditedFeature(id, index, ft))
- GetOriginalFeatureByIndex(index, ft);
+ if (m_editor.Instance().GetEditedFeature(id, index, ft))
+ return true;
+ return GetOriginalFeatureByIndex(index, ft);
}
-void Index::FeaturesLoaderGuard::GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const
+bool Index::FeaturesLoaderGuard::GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const
{
- m_vector.GetByIndex(index, ft);
+ if (!m_handle.IsAlive())
+ return false;
+
+ ASSERT(m_vector != nullptr, ());
+ m_vector->GetByIndex(index, ft);
ft.SetID(FeatureID(m_handle.GetId(), index));
+ return true;
}
diff --git a/indexer/index.hpp b/indexer/index.hpp
index 8c8467e49e..6979d7af10 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -272,20 +272,21 @@ public:
class FeaturesLoaderGuard
{
public:
- FeaturesLoaderGuard(Index const & parent, MwmId const & id);
+ FeaturesLoaderGuard(Index const & index, MwmId const & id);
inline MwmSet::MwmId const & GetId() const { return m_handle.GetId(); }
string GetCountryFileName() const;
bool IsWorld() const;
+
/// Everyone, except Editor core, should use this method.
- void GetFeatureByIndex(uint32_t index, FeatureType & ft) const;
+ WARN_UNUSED_RESULT bool GetFeatureByIndex(uint32_t index, FeatureType & ft) const;
+
/// Editor core only method, to get 'untouched', original version of feature.
- void GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const;
- inline FeaturesVector const & GetFeaturesVector() const { return m_vector; }
+ WARN_UNUSED_RESULT bool GetOriginalFeatureByIndex(uint32_t index, FeatureType & ft) const;
private:
MwmHandle m_handle;
- FeaturesVector m_vector;
+ unique_ptr<FeaturesVector> m_vector;
osm::Editor & m_editor = osm::Editor::Instance();
};
diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp
index 243b3097c0..c64f1c7bc1 100644
--- a/indexer/osm_editor.cpp
+++ b/indexer/osm_editor.cpp
@@ -97,18 +97,17 @@ bool AreFeaturesEqualButStreet(FeatureType const & a, FeatureType const & b)
return true;
}
-XMLFeature GetMatchingFeatureFromOSM(osm::ChangesetWrapper & cw,
- unique_ptr<FeatureType const> featurePtr)
+XMLFeature GetMatchingFeatureFromOSM(osm::ChangesetWrapper & cw, FeatureType const & ft)
{
- ASSERT_NOT_EQUAL(featurePtr->GetFeatureType(), feature::GEOM_LINE,
+ ASSERT_NOT_EQUAL(ft.GetFeatureType(), feature::GEOM_LINE,
("Line features are not supported yet."));
- if (featurePtr->GetFeatureType() == feature::GEOM_POINT)
- return cw.GetMatchingNodeFeatureFromOSM(featurePtr->GetCenter());
+ if (ft.GetFeatureType() == feature::GEOM_POINT)
+ return cw.GetMatchingNodeFeatureFromOSM(ft.GetCenter());
// Warning: geometry is cached in FeatureType. So if it wasn't BEST_GEOMETRY,
// we can never have it. Features here came from editors loader and should
// have BEST_GEOMETRY geometry.
- auto geometry = featurePtr->GetTriangesAsPoints(FeatureType::BEST_GEOMETRY);
+ auto geometry = ft.GetTriangesAsPoints(FeatureType::BEST_GEOMETRY);
// Filters out duplicate points for closed ways or triangles' vertices.
my::SortUnique(geometry);
@@ -770,8 +769,8 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset
feature.SetTagValue(kAddrStreetTag, fti.m_street);
ourDebugFeatureString = DebugPrint(feature);
- XMLFeature osmFeature =
- GetMatchingFeatureFromOSM(changeset, m_getOriginalFeatureFn(fti.m_feature.GetID()));
+ XMLFeature osmFeature = GetMatchingFeatureFromOSM(
+ changeset, *m_getOriginalFeatureFn(fti.m_feature.GetID()));
XMLFeature const osmFeatureCopy = osmFeature;
osmFeature.ApplyPatch(feature);
// Check to avoid uploading duplicates into OSM.
@@ -791,7 +790,7 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset
case FeatureStatus::Deleted:
changeset.Delete(GetMatchingFeatureFromOSM(
- changeset, m_getOriginalFeatureFn(fti.m_feature.GetID())));
+ changeset, *m_getOriginalFeatureFn(fti.m_feature.GetID())));
break;
}
fti.m_uploadStatus = kUploaded;
diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp
index e545470051..8a36f25788 100644
--- a/indexer/osm_editor.hpp
+++ b/indexer/osm_editor.hpp
@@ -113,7 +113,8 @@ public:
{
NothingWasChanged,
SavedSuccessfully,
- NoFreeSpaceError
+ NoFreeSpaceError,
+ NoUnderlyingMapError
};
/// Editor checks internally if any feature params were actually edited.
SaveResult SaveEditedFeature(EditableMapObject const & emo);