| 48 | } |
| 49 | |
| 50 | void SerializeRestrictions(RestrictionCollector & restrictionCollector, std::string const & mwmPath) |
| 51 | { |
| 52 | std::vector<Restriction> restrictions = restrictionCollector.StealRestrictions(); |
| 53 | CHECK(std::is_sorted(restrictions.cbegin(), restrictions.cend()), ()); |
| 54 | |
| 55 | RestrictionHeader header; |
| 56 | |
| 57 | auto prevTypeEndIt = restrictions.cbegin(); |
| 58 | for (size_t i = 1; i <= RestrictionHeader::kRestrictionTypes.size(); ++i) |
| 59 | { |
| 60 | decltype(restrictions.cbegin()) firstNextType; |
| 61 | if (i != RestrictionHeader::kRestrictionTypes.size()) |
| 62 | { |
| 63 | firstNextType = std::lower_bound(restrictions.cbegin(), restrictions.cend(), |
| 64 | Restriction(RestrictionHeader::kRestrictionTypes[i], {} /* links */), |
| 65 | base::LessBy(&Restriction::m_type)); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | firstNextType = restrictions.cend(); |
| 70 | } |
| 71 | |
| 72 | CHECK_GREATER_OR_EQUAL(i, 1, ("Unexpected overflow.")); |
| 73 | auto const prevType = RestrictionHeader::kRestrictionTypes[i - 1]; |
| 74 | header.SetNumberOf(prevType, base::checked_cast<uint32_t>(std::distance(prevTypeEndIt, firstNextType))); |
| 75 | |
| 76 | prevTypeEndIt = firstNextType; |
| 77 | } |
| 78 | |
| 79 | LOG(LINFO, ("Routing restriction info:", header)); |
| 80 | |
| 81 | FilesContainerW cont(mwmPath, FileWriter::OP_WRITE_EXISTING); |
| 82 | auto w = cont.GetWriter(RESTRICTIONS_FILE_TAG); |
| 83 | header.Serialize(*w); |
| 84 | |
| 85 | base::SortUnique(restrictions); |
| 86 | RestrictionSerializer::Serialize(header, restrictions.begin(), restrictions.end(), *w); |
| 87 | } |
| 88 | |
| 89 | bool BuildRoadRestrictions(IndexGraph & graph, std::string const & mwmPath, std::string const & restrictionPath, |
| 90 | std::string const & osmIdsToFeatureIdsPath) |