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

Method Load

libs/search/cities_boundaries_table.cpp:47–109  ·  view source on GitHub ↗

CitiesBoundariesTable ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

45
46// CitiesBoundariesTable ---------------------------------------------------------------------------
47bool CitiesBoundariesTable::Load()
48{
49 auto handle = FindWorld(m_dataSource);
50 if (!handle.IsAlive())
51 {
52 LOG(LWARNING, ("Can't find World map file."));
53 return false;
54 }
55
56 // Skip if table was already loaded from this file.
57 if (handle.GetId() == m_mwmId)
58 return true;
59
60 MwmContext context(std::move(handle));
61 base::Cancellable const cancellable;
62 auto const localities = CategoriesCache(LocalitiesSource{}, cancellable).Get(context);
63
64 auto const & cont = context.m_value.m_cont;
65
66 if (!cont.IsExist(CITIES_BOUNDARIES_FILE_TAG))
67 {
68 LOG(LWARNING, ("No cities boundaries table in the world map."));
69 return false;
70 }
71
72 vector<vector<CityBoundary>> all;
73 double precision;
74
75 try
76 {
77 auto reader = cont.GetReader(CITIES_BOUNDARIES_FILE_TAG);
78 ReaderSource<ReaderPtr<ModelReader>> source(reader);
79 CitiesBoundariesSerDes::Deserialize(source, all, precision);
80 }
81 catch (Reader::Exception const & e)
82 {
83 LOG(LERROR, ("Can't read cities boundaries table from the world map:", e.Msg()));
84 return false;
85 }
86
87 if (all.size() != localities.PopCount())
88 {
89 LOG(LERROR, ("Wrong number of boundaries, expected:", localities.PopCount(), "actual:", all.size()));
90 return false;
91 }
92
93 m_mwmId = context.GetId();
94 m_table.clear();
95 m_eps = precision;
96 size_t idx = 0, notEmpty = 0;
97 localities.ForEach([&](uint64_t fid)
98 {
99 if (!all[idx].empty())
100 {
101 CHECK(m_table.emplace(base::asserted_cast<uint32_t>(fid), std::move(all[idx])).second, ());
102 ++notEmpty;
103 }
104 ++idx;

Callers

nothing calls this directly

Calls 13

FindWorldFunction · 0.85
CategoriesCacheClass · 0.85
IsExistMethod · 0.80
IsAliveMethod · 0.45
GetIdMethod · 0.45
GetMethod · 0.45
GetReaderMethod · 0.45
sizeMethod · 0.45
PopCountMethod · 0.45
clearMethod · 0.45
ForEachMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected