//============================================================================================ // FileReader::readRoads // // Input: // stream: A reference to the currenly open file. // cities: A map using city ids as keys and City objects as values. // optional: A boolean flag indicating whether the roads being read in are optional or not. // // Output: // A vector of Road objects. // // Read in a set of multiple optional or mandatoryroads from a file, updating the 'toRoads' // and 'fromRoads' attributes of each City object accordingly. //============================================================================================ std::vector<Road *> FileReader::readRoads(std::ifstream& stream, std::map<unsigned long, City*> cities, bool optional){ Road *temp; std::vector<Road *> roads; unsigned long numRoads; const char* optionalText = FileReader::getOptionalText(optional); numRoads = FileReader::readUL(stream, true); printf("Reading %lu uni-directional roads.\n", numRoads); for(int i = 0; i < numRoads; i++){ temp = readRoad(stream, optional, cities.size()); if(!optional){ cities[temp->from]->fromRoads.push_back(temp); cities[temp->to]->toRoads.push_back(temp); } else{ roads.push_back(temp); } printf(" Reading %s road from city %lu to city %lu with length of %lu\n", optionalText, temp->from, temp->to, temp->length); } printf("Done reading %s uni-directional roads.\n", optionalText); return roads; }
void OsmAnd::ObfRoutingSectionReader_P::readSubsectionData( 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*/ ) { QStringList roadNamesTable; QList<uint64_t> roadsIdsTable; QMap< uint32_t, std::shared_ptr<Model::Road> > resultsByInternalId; auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: { for(const auto& road : constOf(resultsByInternalId)) { // Fill names of roads from stringtable for(auto& encodedId : road->_names) { const uint32_t stringId = ObfReaderUtilities::decodeIntegerFromString(encodedId); encodedId = roadNamesTable[stringId]; } if(!visitor || visitor(road)) { if(resultOut) resultOut->push_back(road); if(resultMapOut) resultMapOut->insert(road->_id, road); } } } return; case OBF::OsmAndRoutingIndex_RouteDataBlock::kIdTableFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readSubsectionRoadsIds(reader, subsection, roadsIdsTable); cis->PopLimit(oldLimit); } break; case OBF::OsmAndRoutingIndex_RouteDataBlock::kDataObjectsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::Road> road(new Model::Road(subsection)); uint32_t internalId; readRoad(reader, subsection, roadsIdsTable, internalId, road); resultsByInternalId.insert(internalId, road); cis->PopLimit(oldLimit); } break; case OBF::OsmAndRoutingIndex_RouteDataBlock::kRestrictionsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); readSubsectionRestriction(reader, subsection, resultsByInternalId, roadsIdsTable); cis->PopLimit(oldLimit); } break; case OBF::OsmAndRoutingIndex_RouteDataBlock::kStringTableFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); ObfReaderUtilities::readStringTable(cis, roadNamesTable); cis->PopLimit(oldLimit); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }