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

Method MatchRegions

libs/search/geocoder.cpp:928–1007  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

926}
927
928void Geocoder::MatchRegions(BaseContext & ctx, Region::Type type)
929{
930 TRACE(MatchRegions);
931
932 switch (type)
933 {
934 case Region::TYPE_STATE:
935 // Tries to skip state matching and go to cities matching.
936 // Then, performs states matching.
937 MatchCities(ctx);
938 break;
939 case Region::TYPE_COUNTRY:
940 // Tries to skip country matching and go to states matching.
941 // Then, performs countries matching.
942 MatchRegions(ctx, Region::TYPE_STATE);
943 break;
944 case Region::TYPE_COUNT: ASSERT(false, ("Invalid region type.")); return;
945 }
946
947 auto const & regions = m_regions[type];
948
949 auto const & fileName = m_context->GetName();
950 bool const isWorld = m_context->GetInfo()->GetType() == MwmInfo::WORLD;
951
952 // Try to match regions.
953 for (auto const & p : regions)
954 {
955 BailIfCancelled();
956
957 auto const & tokenRange = p.first;
958 if (ctx.HasUsedTokensInRange(tokenRange))
959 continue;
960
961 for (auto const & region : p.second)
962 {
963 bool matches = false;
964
965 // On the World.mwm we need to check that CITY - STATE - COUNTRY
966 // form a nested sequence. Otherwise, as mwm borders do not
967 // intersect state or country boundaries, it's enough to check
968 // mwm that is currently being processed belongs to region.
969 if (isWorld)
970 {
971 matches =
972 ctx.m_regions.empty() || m_infoGetter.BelongsToAnyRegion(region.m_center, ctx.m_regions.back()->m_ids);
973 }
974 else
975 {
976 matches = m_infoGetter.BelongsToAnyRegion(fileName, region.m_ids);
977 }
978
979 if (!matches)
980 continue;
981
982 ctx.m_regions.push_back(&region);
983 SCOPE_GUARD(cleanup, [&ctx]() { ctx.m_regions.pop_back(); });
984
985 ScopedMarkTokens mark(ctx.m_tokens, BaseContext::FromRegionType(type), tokenRange);

Callers

nothing calls this directly

Calls 12

ASSERTFunction · 0.85
BailIfCancelledFunction · 0.85
HasUsedTokensInRangeMethod · 0.80
BelongsToAnyRegionMethod · 0.80
backMethod · 0.80
AllTokensUsedMethod · 0.80
GetNameMethod · 0.45
GetTypeMethod · 0.45
GetInfoMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected