MCPcopy Create free account
hub / github.com/comaps/comaps / LoadEdits

Method LoadEdits

libs/editor/osm_editor.cpp:148–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148void Editor::LoadEdits()
149{
150 CHECK_THREAD_CHECKER(MainThreadChecker, ());
151 if (!m_delegate)
152 {
153 LOG(LERROR, ("Can't load any map edits, delegate has not been set."));
154 return;
155 }
156
157 LOG(LINFO, ("Loading OSM edits..."));
158
159 xml_document doc;
160 bool needRewriteEdits = false;
161
162 if (!m_storage->Load(doc))
163 return;
164
165 m_features.Set(make_shared<FeaturesContainer>());
166 auto loadedFeatures = make_shared<FeaturesContainer>();
167
168 auto rootNode = doc.child(kXmlRootNode);
169 // TODO: Empty rootNode is an OK case for the current logic and unit tests. Check if there is a better way to do it.
170 for (auto const & mwm : rootNode.children(kXmlMwmNode))
171 {
172 string const mapName = mwm.attribute("name").as_string("");
173 int64_t const mapVersion = mwm.attribute("version").as_llong(0);
174 auto const mwmId = GetMwmIdByMapName(mapName);
175
176 // TODO(mgsergio, milchakov): |mapName| may change between launches.
177 // The right thing to do here is to try to migrate all changes anyway.
178 if (!mwmId.IsAlive())
179 {
180 LOG(LINFO, ("Mwm", mapName, "was deleted"));
181 needRewriteEdits = true;
182 continue;
183 }
184
185 auto const needMigrateEdits = mapVersion != mwmId.GetInfo()->GetVersion();
186 needRewriteEdits = needRewriteEdits || needMigrateEdits;
187
188 LoadMwmEdits(*loadedFeatures, mwm, mwmId, needMigrateEdits);
189 }
190 // Save edits with new indexes and mwm version to avoid another migration on next startup.
191 if (needRewriteEdits)
192 SaveTransaction(loadedFeatures);
193 else
194 m_features.Set(loadedFeatures);
195}
196
197bool Editor::Save(FeaturesContainer const & features) const
198{

Callers 6

GetStatsTestMethod · 0.80
LoadMapEditsTestMethod · 0.80
LoadExistingEditsXmlMethod · 0.80
LoadMapsSyncMethod · 0.80
LoadMapsAsyncMethod · 0.80

Calls 5

LoadMethod · 0.45
SetMethod · 0.45
IsAliveMethod · 0.45
GetVersionMethod · 0.45
GetInfoMethod · 0.45

Tested by 4

GetStatsTestMethod · 0.64
LoadMapEditsTestMethod · 0.64
LoadExistingEditsXmlMethod · 0.64