CitiesBoundariesTable ---------------------------------------------------------------------------
| 45 | |
| 46 | // CitiesBoundariesTable --------------------------------------------------------------------------- |
| 47 | bool 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; |
nothing calls this directly
no test coverage detected