void OsmAnd::ObfMapSectionReader_P::readTreeNodeChildren( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfMapSectionInfo>& section, const std::shared_ptr<ObfMapSectionLevelTreeNode>& treeNode, MapFoundationType& foundation, QList< std::shared_ptr<ObfMapSectionLevelTreeNode> >* nodesWithData, const AreaI* bbox31, IQueryController* controller) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndMapIndex_MapDataBox::kBoxesFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); std::shared_ptr<ObfMapSectionLevelTreeNode> childNode(new ObfMapSectionLevelTreeNode()); childNode->_foundation = treeNode->_foundation; childNode->_offset = offset; childNode->_length = length; readTreeNode(reader, section, treeNode->_area31, childNode); if(bbox31 && !bbox31->intersects(childNode->_area31)) { cis->Skip(cis->BytesUntilLimit()); cis->PopLimit(oldLimit); break; } cis->PopLimit(oldLimit); if(childNode->_foundation != MapFoundationType::Undefined) { if(foundation == MapFoundationType::Undefined) foundation = childNode->_foundation; else if(foundation != childNode->_foundation) foundation = MapFoundationType::Mixed; } if(nodesWithData && childNode->_dataOffset > 0) nodesWithData->push_back(childNode); cis->Seek(offset); oldLimit = cis->PushLimit(length); cis->Skip(childNode->_childrenInnerOffset); readTreeNodeChildren(reader, section, childNode, foundation, nodesWithData, bbox31, controller); assert(cis->BytesUntilLimit() == 0); cis->PopLimit(oldLimit); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSectionReader_P::readAmenities( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, QSet<uint32_t>* desiredCategories, QList< std::shared_ptr<const Model::Amenity> >* amenitiesOut, const ZoomLevel& zoom, uint32_t zoomDepth, const AreaI* bbox31, std::function<bool (const std::shared_ptr<const Model::Amenity>&)> visitor, IQueryController* controller) { auto cis = reader->_codedInputStream.get(); QList< std::shared_ptr<Tile> > tiles; for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndPoiIndex::kBoxesFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto oldLimit = cis->PushLimit(length); readTile(reader, section, tiles, nullptr, desiredCategories, zoom, zoomDepth, bbox31, controller, nullptr); cis->PopLimit(oldLimit); if(controller && controller->isAborted()) return; } break; case OBF::OsmAndPoiIndex::kPoiDataFieldNumber: { // Sort tiles byte data offset, to all cache-friendly with I/O system qSort(tiles.begin(), tiles.end(), [](const std::shared_ptr<Tile>& l, const std::shared_ptr<Tile>& r) -> bool { return l->_hash < r->_hash; }); for(auto itTile = tiles.begin(); itTile != tiles.end(); ++itTile) { const auto& tile = *itTile; cis->Seek(section->_offset + tile->_offset); auto length = ObfReaderUtilities::readBigEndianInt(cis); auto oldLimit = cis->PushLimit(length); readAmenitiesFromTile(reader, section, tile.get(), desiredCategories, amenitiesOut, zoom, zoomDepth, bbox31, visitor, controller, nullptr); cis->PopLimit(oldLimit); if(controller && controller->isAborted()) return; } cis->Skip(cis->BytesUntilLimit()); } return; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfRoutingSectionReader_P::querySubsections( const std::unique_ptr<ObfReader_P>& reader, const QList< std::shared_ptr<ObfRoutingSubsectionInfo> >& in, QList< std::shared_ptr<const ObfRoutingSubsectionInfo> >* resultOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingSubsectionInfo>&)> visitor /*= nullptr*/) { auto cis = reader->_codedInputStream.get(); for(const auto& subsection : constOf(in)) { // If section is completely outside of bbox, skip it if(filter && !filter->acceptsArea(subsection->_area31)) continue; // Load children if they are not yet loaded if(subsection->_subsectionsOffset != 0 && subsection->_subsections.isEmpty()) { cis->Seek(subsection->_offset); auto oldLimit = cis->PushLimit(subsection->_length); cis->Skip(subsection->_subsectionsOffset - subsection->_offset); const auto contains = !filter || filter->acceptsArea(subsection->_area31); readSubsectionChildrenHeaders(reader, subsection, contains ? std::numeric_limits<uint32_t>::max() : 1); cis->PopLimit(oldLimit); } querySubsections(reader, subsection->_subsections, resultOut, filter, visitor); if(!visitor || visitor(subsection)) { if(resultOut) resultOut->push_back(subsection); } } }
void OsmAnd::ObfPoiSectionReader_P::read( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfPoiSectionInfo>& section ) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndPoiIndex::kNameFieldNumber: ObfReaderUtilities::readQString(cis, section->_name); break; case OBF::OsmAndPoiIndex::kBoundariesFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readBoundaries(reader, section); cis->PopLimit(oldLimit); } break; case OBF::OsmAndPoiIndex::kCategoriesTableFieldNumber: cis->Skip(cis->BytesUntilLimit()); return; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfMapSectionReader_P::readEncodingDecodingRules( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfMapSectionDecodingEncodingRules>& encodingDecodingRules) { auto cis = reader->_codedInputStream.get(); uint32_t defaultId = 1; for(;;) { gpb::uint32 tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: { encodingDecodingRules->createMissingRules(); } return; case OBF::OsmAndMapIndex::kRulesFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readEncodingDecodingRule(reader, defaultId++, encodingDecodingRules); cis->PopLimit(oldLimit); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSectionReader_P::readCategories( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, QList< std::shared_ptr<const Model::AmenityCategory> >& categories ) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndPoiIndex::kCategoriesTableFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::AmenityCategory> category(new Model::AmenityCategory()); readCategory(reader, category); cis->PopLimit(oldLimit); categories.push_back(category); } break; case OBF::OsmAndPoiIndex::kNameIndexFieldNumber: cis->Skip(cis->BytesUntilLimit()); return; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfRoutingSectionReader_P::readBorderLinePoints( const std::unique_ptr<ObfReader_P>& reader, QList< std::shared_ptr<const ObfRoutingBorderLinePoint> >* resultOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingBorderLinePoint>&)> visitor /*= nullptr*/ ) { auto cis = reader->_codedInputStream.get(); PointI location; gpb::uint64 id; for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndRoutingIndex_RouteBorderPointsBlock::kXFieldNumber: cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&location.x)); break; case OBF::OsmAndRoutingIndex_RouteBorderPointsBlock::kYFieldNumber: cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&location.y)); break; case OBF::OsmAndRoutingIndex_RouteBorderPointsBlock::kBaseIdFieldNumber: cis->ReadVarint64(&id); break; case OBF::OsmAndRoutingIndex_RouteBorderPointsBlock::kPointsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); const std::shared_ptr<ObfRoutingBorderLinePoint> point(new ObfRoutingBorderLinePoint()); readBorderLinePoint(reader, point); cis->PopLimit(oldLimit); point->_id += id; point->_location += location; id = point->_id; location = point->_location; bool valid = true; if(filter) valid = filter->acceptsPoint(point->location); if(valid && visitor) valid = visitor(point); if(valid && resultOut) resultOut->push_back(qMove(point)); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSection::loadCategories( OsmAnd::ObfReader* reader, OsmAnd::ObfPoiSection* section, QList< std::shared_ptr<OsmAnd::Model::Amenity::Category> >& categories ) { auto cis = reader->_codedInputStream.get(); cis->Seek(section->_offset); auto oldLimit = cis->PushLimit(section->_length); readCategories(reader, section, categories); cis->PopLimit(oldLimit); }
void OsmAnd::ObfRoutingSectionReader_P::loadSubsectionBorderBoxLinesPoints( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfRoutingSectionInfo>& section, QList< std::shared_ptr<const ObfRoutingBorderLinePoint> >* resultOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingBorderLineHeader>&)> visitorLine /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingBorderLinePoint>&)> visitorPoint /*= nullptr*/) { if(section->_d->_borderBoxOffset == 0 || section->_d->_borderBoxLength == 0) return; auto cis = reader->_codedInputStream.get(); cis->Seek(section->_d->_borderBoxOffset); auto oldLimit = cis->PushLimit(section->_d->_borderBoxLength); QList<uint32_t> pointsOffsets; readBorderBoxLinesHeaders(reader, nullptr, filter, [&] (const std::shared_ptr<const ObfRoutingBorderLineHeader>& borderLine) { auto valid = !visitorLine || visitorLine(borderLine); if(!valid) return false; pointsOffsets.push_back(borderLine->offset); return false; } ); cis->PopLimit(oldLimit); qSort(pointsOffsets); for(const auto& offset : constOf(pointsOffsets)) { cis->Seek(offset); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readBorderLinePoints(reader, resultOut, filter, visitorPoint); cis->PopLimit(oldLimit); } }
void OsmAnd::ObfPoiSection::readCategories( ObfReader* reader, ObfPoiSection* section, QList< std::shared_ptr<OsmAnd::Model::Amenity::Category> >& categories ) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndPoiIndex::kNameFieldNumber: ObfReader::readQString(cis, section->_name); break; case OBF::OsmAndPoiIndex::kBoundariesFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readBoundaries(reader, section); cis->PopLimit(oldLimit); } break; case OBF::OsmAndPoiIndex::kCategoriesTableFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::Amenity::Category> category(new Model::Amenity::Category()); readCategory(reader, category.get()); cis->PopLimit(oldLimit); categories.push_back(category); } break; case OBF::OsmAndPoiIndex::kNameIndexFieldNumber: cis->Skip(cis->BytesUntilLimit()); return; default: ObfReader::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSectionReader_P::loadCategories( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, QList< std::shared_ptr<const OsmAnd::Model::AmenityCategory> >& categories ) { auto cis = reader->_codedInputStream.get(); cis->Seek(section->_offset); auto oldLimit = cis->PushLimit(section->_length); readCategories(reader, section, categories); cis->PopLimit(oldLimit); }
void OsmAnd::ObfTransportSectionReader_P::read( const ObfReader_P& reader, const std::shared_ptr<ObfTransportSectionInfo>& section ) { const auto cis = reader.getCodedInputStream().get(); for(;;) { const auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: if (!ObfReaderUtilities::reachedDataEnd(cis)) return; return; case OBF::OsmAndTransportIndex::kRoutesFieldNumber: ObfReaderUtilities::skipUnknownField(cis, tag); break; case OBF::OsmAndTransportIndex::kNameFieldNumber: ObfReaderUtilities::readQString(cis, section->name); break; case OBF::OsmAndTransportIndex::kStopsFieldNumber: { section->_stopsLength = ObfReaderUtilities::readBigEndianInt(cis); section->_stopsOffset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(section->_stopsLength); readTransportStopsBounds(reader, section); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); } break; case OBF::OsmAndTransportIndex::kStringTableFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto offset = cis->CurrentPosition(); cis->Seek(offset + length); } //TODO: /*IndexStringTable st = new IndexStringTable(); st.length = codedIS.readRawVarint32(); st.fileOffset = codedIS.getTotalBytesRead(); // Do not cache for now save memory // readStringTable(st, 0, 20, true); ind.stringTable = st; codedIS.seek(st.length + st.fileOffset);*/ break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfRoutingSectionReader_P::readBorderBoxLinesHeaders(const std::unique_ptr<ObfReader_P>& reader, QList< std::shared_ptr<const ObfRoutingBorderLineHeader> >* resultOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingBorderLineHeader>&)> visitor /*= nullptr*/) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndRoutingIndex_RouteBorderBox::kBorderLinesFieldNumber: { auto offset = cis->CurrentPosition(); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); const std::shared_ptr<ObfRoutingBorderLineHeader> line(new ObfRoutingBorderLineHeader()); readBorderLineHeader(reader, line, offset); cis->PopLimit(oldLimit); bool isValid = true; if(filter) { if(line->_x2present) isValid = filter->acceptsArea(AreaI(line->_x, line->_y, line->_x2, line->_y)); else isValid = false; /*FIXME: borders approach else if(ln.hasToy()) isValid = req.intersects(ln.getX(), ln.getY(), ln.getX(), ln.getToy());*/ } if(isValid) { if(!visitor || (visitor && visitor(line))) { if(resultOut) resultOut->push_back(qMove(line)); } } } break; case OBF::OsmAndRoutingIndex_RouteBorderBox::kBlocksFieldNumber: return; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfAddressSection::AddressBlocksSection::loadStreetGroupsFromBlock( QList< std::shared_ptr<Model::StreetGroup> >* resultOut, std::function<bool (const std::shared_ptr<OsmAnd::Model::StreetGroup>&)> visitor, IQueryController* controller) { auto cis = owner->_codedInputStream.get(); cis->Seek(_offset); auto oldLimit = cis->PushLimit(_length); AddressBlocksSection::readStreetGroups(owner, this, resultOut, visitor, controller); cis->PopLimit(oldLimit); }
void OsmAnd::ObfPoiSectionReader_P::loadCategories( const ObfReader_P& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, QList< std::shared_ptr<const OsmAnd::AmenityCategory> >& categories ) { const auto cis = reader.getCodedInputStream().get(); cis->Seek(section->offset); auto oldLimit = cis->PushLimit(section->length); readCategories(reader, section, categories); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); }
void OsmAnd::ObfAddressSectionReader_P::readBuildingsFromStreet( const ObfReader_P& reader, const std::shared_ptr<const Model::Street>& street, QList< std::shared_ptr<const Model::Building> >* resultOut, std::function<bool (const std::shared_ptr<const OsmAnd::Model::Building>&)> visitor, const IQueryController* const controller) { auto cis = reader._codedInputStream.get(); for(;;) { if (controller && controller->isAborted()) return; auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::StreetIndex::kIntersectionsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); cis->Skip(length); } break; case OBF::StreetIndex::kBuildingsFieldNumber: { auto offset = cis->CurrentPosition(); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::Building> building(new Model::Building()); building->_offset = offset; readBuilding(reader, street, building); cis->PopLimit(oldLimit); if (!visitor || visitor(building)) { if (resultOut) resultOut->push_back(qMove(building)); } } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSectionReader_P::loadAmenities( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, const ZoomLevel& zoom, uint32_t zoomDepth /*= 3*/, const AreaI* bbox31 /*= nullptr*/, QSet<uint32_t>* desiredCategories /*= nullptr*/, QList< std::shared_ptr<const Model::Amenity> >* amenitiesOut /*= nullptr*/, std::function<bool (const std::shared_ptr<const Model::Amenity>&)> visitor /*= nullptr*/, IQueryController* controller /*= nullptr*/ ) { auto cis = reader->_codedInputStream.get(); cis->Seek(section->_offset); auto oldLimit = cis->PushLimit(section->_length); readAmenities(reader, section, desiredCategories, amenitiesOut, zoom, zoomDepth, bbox31, visitor, controller); cis->PopLimit(oldLimit); }
void OsmAnd::ObfMapSectionReader_P::read( const ObfReader_P& reader, const std::shared_ptr<ObfMapSectionInfo>& section) { const auto cis = reader.getCodedInputStream().get(); for (;;) { const auto tag = cis->ReadTag(); switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: if (!ObfReaderUtilities::reachedDataEnd(cis)) return; return; case OBF::OsmAndMapIndex::kNameFieldNumber: { ObfReaderUtilities::readQString(cis, section->name); section->isBasemap = section->name.contains(QLatin1String("basemap"), Qt::CaseInsensitive); section->isBasemapWithCoastlines = section->name == QLatin1String("basemap"); break; } case OBF::OsmAndMapIndex::kRulesFieldNumber: ObfReaderUtilities::skipBlockWithLength(cis); break; case OBF::OsmAndMapIndex::kLevelsFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); Ref<ObfMapSectionLevel> levelRoot(new ObfMapSectionLevel()); levelRoot->length = length; levelRoot->offset = offset; readMapLevelHeader(reader, levelRoot); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); section->levels.push_back(qMove(levelRoot)); break; } default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfRoutingSectionReader_P::readBorderLinePoint( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfRoutingBorderLinePoint>& point) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndRoutingIndex_RouteBorderPoint::kDxFieldNumber: cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&point->_location.x)); break; case OBF::OsmAndRoutingIndex_RouteBorderPoint::kDyFieldNumber: cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&point->_location.y)); break; case OBF::OsmAndRoutingIndex_RouteBorderPoint::kRoadIdFieldNumber: cis->ReadVarint64(&point->_id); break; case OBF::OsmAndRoutingIndex_RouteBorderPoint::kDirectionFieldNumber: { gpb::uint32 value; cis->ReadVarint32(&value); //TODO:p.direction = codedIS.readBool(); } break; case OBF::OsmAndRoutingIndex_RouteBorderPoint::kTypesFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); while(cis->BytesUntilLimit() > 0) { gpb::uint32 value; cis->ReadVarint32(&value); point->_types.push_back(value); } cis->PopLimit(oldLimit); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfAddressSection::loadStreetsFromGroup( ObfReader* reader, Model::StreetGroup* group, QList< std::shared_ptr<Model::Street> >* resultOut /*= nullptr*/, std::function<bool (const std::shared_ptr<OsmAnd::Model::Street>&)> visitor /*= nullptr*/, IQueryController* controller /*= nullptr*/) { //TODO:checkAddressIndex(c.getFileOffset()); auto cis = reader->_codedInputStream; cis->Seek(group->_offset); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readStreetsFromGroup(reader, group, resultOut, visitor, controller); cis->PopLimit(oldLimit); }
void OsmAnd::ObfAddressSectionReader_P::loadIntersectionsFromStreet( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const Model::Street>& street, QList< std::shared_ptr<const Model::StreetIntersection> >* resultOut /*= nullptr*/, std::function<bool (const std::shared_ptr<const OsmAnd::Model::StreetIntersection>&)> visitor /*= nullptr*/, IQueryController* controller /*= nullptr*/) { //TODO:checkAddressIndex(s.getFileOffset()); auto cis = reader->_codedInputStream; cis->Seek(street->_offset); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readIntersectionsFromStreet(reader, street, resultOut, visitor, controller); cis->PopLimit(oldLimit); }
void OsmAnd::ObfRoutingSectionReader_P::loadSubsectionData( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfRoutingSubsectionInfo>& subsection, QList< std::shared_ptr<const Model::Road> >* resultOut /*= nullptr*/, QMap< uint64_t, std::shared_ptr<const Model::Road> >* resultMapOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const Model::Road>&)> visitor /*= nullptr*/ ) { auto cis = reader->_codedInputStream.get(); cis->Seek(subsection->_offset + subsection->_dataOffset); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readSubsectionData(reader, subsection, resultOut, resultMapOut, filter, visitor); cis->PopLimit(oldLimit); }
void OsmAnd::ObfMapSectionReader_P::readAttributeMapping( const ObfReader_P& reader, const std::shared_ptr<const ObfMapSectionInfo>& section, const std::shared_ptr<ObfMapSectionAttributeMapping>& attributeMapping) { const auto cis = reader.getCodedInputStream().get(); bool atLeastOneRuleWasRead = false; uint32_t naturalId = 1; for (;;) { gpb::uint32 tag = cis->ReadTag(); switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: if (!ObfReaderUtilities::reachedDataEnd(cis)) return; attributeMapping->verifyRequiredMappingRegistered(); return; case OBF::OsmAndMapIndex::kRulesFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); const auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); readAttributeMappingEntry(reader, naturalId++, attributeMapping); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); atLeastOneRuleWasRead = true; break; } default: if (atLeastOneRuleWasRead) { attributeMapping->verifyRequiredMappingRegistered(); return; } ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfMapSectionReader_P::readMapLevelTreeNodes( const ObfReader_P& reader, const std::shared_ptr<const ObfMapSectionInfo>& section, const std::shared_ptr<const ObfMapSectionLevel>& level, QList< std::shared_ptr<const ObfMapSectionLevelTreeNode> >& trees) { const auto cis = reader.getCodedInputStream().get(); bool atLeastOneMapRootLevelRead = false; for (;;) { gpb::uint32 tag = cis->ReadTag(); switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: if (!ObfReaderUtilities::reachedDataEnd(cis)) return; return; case OBF::OsmAndMapIndex_MapRootLevel::kBoxesFieldNumber: { const auto length = ObfReaderUtilities::readBigEndianInt(cis); const auto offset = cis->CurrentPosition(); const auto oldLimit = cis->PushLimit(length); const std::shared_ptr<ObfMapSectionLevelTreeNode> levelTree(new ObfMapSectionLevelTreeNode(level)); levelTree->offset = offset; levelTree->length = length; readTreeNode(reader, section, level->area31, levelTree); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); trees.push_back(qMove(levelTree)); atLeastOneMapRootLevelRead = true; break; } default: if (atLeastOneMapRootLevelRead) return; ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfAddressSection::readIntersectionsFromStreet( ObfReader* reader, Model::Street* street, QList< std::shared_ptr<Model::StreetIntersection> >* resultOut, std::function<bool (const std::shared_ptr<OsmAnd::Model::StreetIntersection>&)> visitor, IQueryController* controller) { auto cis = reader->_codedInputStream.get(); for(;;) { if(controller && controller->isAborted()) return; auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::StreetIndex::kIntersectionsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::StreetIntersection> intersectedStreet(new Model::StreetIntersection()); readIntersectedStreet(reader, street, intersectedStreet.get()); if(!visitor || visitor(intersectedStreet)) { if(resultOut) resultOut->push_back(intersectedStreet); } cis->PopLimit(oldLimit); } break; case OBF::StreetIndex::kBuildingsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); cis->Skip(length); } break; default: ObfReader::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfPoiSectionReader_P::loadAmenities( const ObfReader_P& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, const ZoomLevel zoom, uint32_t zoomDepth /*= 3*/, const AreaI* bbox31 /*= nullptr*/, QSet<uint32_t>* desiredCategories /*= nullptr*/, QList< std::shared_ptr<const Amenity> >* amenitiesOut /*= nullptr*/, std::function<bool (std::shared_ptr<const Amenity>)> visitor /*= nullptr*/, const IQueryController* const controller /*= nullptr*/ ) { const auto cis = reader.getCodedInputStream().get(); cis->Seek(section->offset); auto oldLimit = cis->PushLimit(section->length); readAmenities(reader, section, desiredCategories, amenitiesOut, zoom, zoomDepth, bbox31, visitor, controller); ObfReaderUtilities::ensureAllDataWasRead(cis); cis->PopLimit(oldLimit); }
void OsmAnd::ObfAddressSectionReader_P::readStreetGroupsFromAddressBlocksSection( const ObfReader_P& reader, const std::shared_ptr<const ObfAddressBlocksSectionInfo>& section, QList< std::shared_ptr<const Model::StreetGroup> >* resultOut, std::function<bool (const std::shared_ptr<const OsmAnd::Model::StreetGroup>&)> visitor, const IQueryController* const controller ) { auto cis = reader._codedInputStream.get(); for(;;) { if (controller && controller->isAborted()) break; auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndAddressIndex_CitiesIndex::kCitiesFieldNumber: { auto offset = cis->CurrentPosition(); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<OsmAnd::Model::StreetGroup> streetGroup; readStreetGroupHeader(reader, section, offset, streetGroup); cis->PopLimit(oldLimit); if (streetGroup) { if (!visitor || visitor(streetGroup)) { if (resultOut) resultOut->push_back(qMove(streetGroup)); } } } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfAddressSectionReader_P::readStreetsFromGroup( const ObfReader_P& reader, const std::shared_ptr<const Model::StreetGroup>& group, QList< std::shared_ptr<const Model::Street> >* resultOut, std::function<bool (const std::shared_ptr<const OsmAnd::Model::Street>&)> visitor, const IQueryController* const controller) { auto cis = reader._codedInputStream.get(); for(;;) { if (controller && controller->isAborted()) return; auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::CityBlockIndex::kStreetsFieldNumber: { std::shared_ptr<Model::Street> street(new Model::Street(/*TODO:group*/)); street->_offset = cis->CurrentPosition(); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readStreet(reader, group, street); cis->PopLimit(oldLimit); if (!visitor || visitor(street)) { if (resultOut) resultOut->push_back(qMove(street)); } } break; case OBF::CityBlockIndex::kBuildingsFieldNumber: // buildings for the town are not used now default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfRoutingSectionReader_P::readSubsectionChildrenHeaders( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfRoutingSubsectionInfo>& subsection, uint32_t depth /*= std::numeric_limits<uint32_t>::max()*/ ) { if(!subsection->_subsectionsOffset) return; const auto shouldReadSubsections = (depth > 0 || subsection->_dataOffset != 0); if(!shouldReadSubsections) return; auto cis = reader->_codedInputStream.get(); for(;;) { auto lastPos = cis->CurrentPosition(); auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndRoutingIndex_RouteDataBox::kBoxesFieldNumber: { if(!shouldReadSubsections) { cis->Skip(cis->BytesUntilLimit()); break; } const std::shared_ptr<ObfRoutingSubsectionInfo> childSubsection(new ObfRoutingSubsectionInfo(subsection)); childSubsection->_length = ObfReaderUtilities::readBigEndianInt(cis); childSubsection->_offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(childSubsection->_length); readSubsectionHeader(reader, childSubsection, subsection, depth - 1); cis->PopLimit(oldLimit); subsection->_subsections.push_back(qMove(childSubsection)); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
void OsmAnd::ObfMapSectionReader_P::read( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfMapSectionInfo>& section ) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndMapIndex::kNameFieldNumber: { ObfReaderUtilities::readQString(cis, section->_name); section->_isBasemap = (QString::compare(section->_name, QLatin1String("basemap"), Qt::CaseInsensitive) == 0); } break; case OBF::OsmAndMapIndex::kRulesFieldNumber: ObfReaderUtilities::skipUnknownField(cis, tag); break; case OBF::OsmAndMapIndex::kLevelsFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); const std::shared_ptr<ObfMapSectionLevel> levelRoot(new ObfMapSectionLevel()); levelRoot->_length = length; levelRoot->_offset = offset; readMapLevelHeader(reader, section, levelRoot); cis->PopLimit(oldLimit); section->_levels.push_back(qMove(levelRoot)); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }