コード例 #1
0
void OsmAnd::ObfRoutingSectionReader_P::readBorderLineHeader(
    const std::unique_ptr<ObfReader_P>& reader,
    const std::shared_ptr<ObfRoutingBorderLineHeader>& borderLine, uint32_t outerOffset)
{
    auto cis = reader->_codedInputStream.get();
    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            return;
        case OBF::OsmAndRoutingIndex_RouteBorderLine::kXFieldNumber:
            cis->ReadVarint32(&borderLine->_x);
            break;
        case OBF::OsmAndRoutingIndex_RouteBorderLine::kYFieldNumber:
            cis->ReadVarint32(&borderLine->_y);
            break;
        case OBF::OsmAndRoutingIndex_RouteBorderLine::kToxFieldNumber:
            cis->ReadVarint32(&borderLine->_x2);
            borderLine->_x2present = true;
            break;
        case OBF::OsmAndRoutingIndex_RouteBorderLine::kToyFieldNumber:
            cis->ReadVarint32(&borderLine->_y2);
            borderLine->_y2present = true;
            break;
        case OBF::OsmAndRoutingIndex_RouteBorderLine::kShiftToPointsBlockFieldNumber:
            borderLine->_offset = outerOffset + ObfReaderUtilities::readBigEndianInt(cis);
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #2
0
void OsmAnd::ObfPoiSectionReader_P::readBoundaries( 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::OsmAndTileBox::kLeftFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_area31.left));
            break;
        case OBF::OsmAndTileBox::kRightFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_area31.right));
            break;
        case OBF::OsmAndTileBox::kTopFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_area31.top));
            break;
        case OBF::OsmAndTileBox::kBottomFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_area31.bottom));
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #3
0
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;
        }
    }
}
コード例 #4
0
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;
        }
    }
}
コード例 #5
0
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;
        }
    }
}
コード例 #6
0
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;
        }
    }
}
コード例 #7
0
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;
        }
    }
}
コード例 #8
0
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;
        }
    }
}
コード例 #9
0
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;
        }
    }
}
コード例 #10
0
ファイル: ObfPoiSection.cpp プロジェクト: cdavila/OsmAnd-core
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;
        }
    }
}
コード例 #11
0
void OsmAnd::ObfRoutingSectionReader_P::readSubsectionRestriction(
    const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfRoutingSubsectionInfo>& subsection,
    const QMap< uint32_t, std::shared_ptr<Model::Road> >& roads, const QList<uint64_t>& roadsInternalIdToGlobalIdMap )
{
    uint32_t originInternalId;
    uint32_t destinationInternalId;
    uint32_t restrictionType;

    auto cis = reader->_codedInputStream.get();
    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            {
                auto originRoad = roads[originInternalId];
                auto destinationRoadId = roadsInternalIdToGlobalIdMap[destinationInternalId];
                originRoad->_restrictions.insert(destinationRoadId, static_cast<Model::RoadRestriction>(restrictionType));
            }
            return;
        case OBF::RestrictionData::kFromFieldNumber:
            {
                cis->ReadVarint32(&originInternalId);
            }
            break;
        case OBF::RestrictionData::kToFieldNumber:
            {
                cis->ReadVarint32(&destinationInternalId);
            }
            break;
        case OBF::RestrictionData::kTypeFieldNumber:
            {
                cis->ReadVarint32(&restrictionType);
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }       
}
コード例 #12
0
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;
        }
    }
}
コード例 #13
0
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;
        }
    }
}
コード例 #14
0
void OsmAnd::ObfAddressSectionReader_P::readStreet(
    const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const Model::StreetGroup>& group,
    const std::shared_ptr<Model::Street>& street)
{
    auto cis = reader->_codedInputStream.get();

    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            if(street->_latinName.isEmpty())
                street->_latinName = reader->transliterate(street->_name);
            return;
        case OBF::StreetIndex::kIdFieldNumber:
            cis->ReadVarint64(reinterpret_cast<gpb::uint64*>(&street->_id));
            break;
        case OBF::StreetIndex::kNameEnFieldNumber:
            ObfReaderUtilities::readQString(cis, street->_latinName);
            break;
        case OBF::StreetIndex::kNameFieldNumber:
            ObfReaderUtilities::readQString(cis, street->_name);
            break;
        case OBF::StreetIndex::kXFieldNumber:
            {
                auto dx = ObfReaderUtilities::readSInt32(cis);
                street->_tile24.x = (Utilities::get31TileNumberX(group->_longitude) >> 7) + dx;
            }
            break;
        case OBF::StreetIndex::kYFieldNumber:
            {
                auto dy = ObfReaderUtilities::readSInt32(cis);
                street->_tile24.y = (Utilities::get31TileNumberY(group->_latitude) >> 7) + dy;
            }
            break;
        case OBF::StreetIndex::kIntersectionsFieldNumber:
        case OBF::StreetIndex::kBuildingsFieldNumber:
            {
                gpb::uint32 length;
                cis->ReadVarint32(&length);
                cis->Skip(length);
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #15
0
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);
}
コード例 #16
0
void OsmAnd::ObfMapSectionReader_P::readEncodingDecodingRule(
    const std::unique_ptr<ObfReader_P>& reader,
    uint32_t defaultId, const std::shared_ptr<ObfMapSectionDecodingEncodingRules>& encodingDecodingRules)
{
    auto cis = reader->_codedInputStream.get();

    gpb::uint32 ruleId = defaultId;
    gpb::uint32 ruleType = 0;
    QString ruleTag;
    QString ruleValue;
    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            encodingDecodingRules->createRule(ruleType, ruleId, ruleTag, ruleValue);
            return;
        case OBF::OsmAndMapIndex_MapEncodingRule::kValueFieldNumber:
            ObfReaderUtilities::readQString(cis, ruleValue);
            break;
        case OBF::OsmAndMapIndex_MapEncodingRule::kTagFieldNumber:
            ObfReaderUtilities::readQString(cis, ruleTag);
            break;
        case OBF::OsmAndMapIndex_MapEncodingRule::kTypeFieldNumber:
            cis->ReadVarint32(&ruleType);
            break;
        case OBF::OsmAndMapIndex_MapEncodingRule::kIdFieldNumber:
            cis->ReadVarint32(&ruleId);
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #17
0
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);
}
コード例 #18
0
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);
}
コード例 #19
0
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;
        }
    }
}
コード例 #20
0
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;
        }
    }
}
コード例 #21
0
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;
        }
    }
}
コード例 #22
0
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);
    }
}
コード例 #23
0
void OsmAnd::ObfAddressSection::AddressBlocksSection::read( ObfReader* reader, AddressBlocksSection* section )
{
    auto cis = reader->_codedInputStream.get();

    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            return;
        case OBF::OsmAndAddressIndex_CitiesIndex::kTypeFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_type));
            return;
        default:
            ObfReader::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #24
0
void OsmAnd::ObfAddressSectionReader_P::readAddressBlocksSectionHeader( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<ObfAddressBlocksSectionInfo>& section )
{
    auto cis = reader->_codedInputStream.get();

    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            return;
        case OBF::OsmAndAddressIndex_CitiesIndex::kTypeFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&section->_type));
            return;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #25
0
void OsmAnd::ObfPoiSectionReader_P::readCategories(
    const ObfReader_P& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section,
    QList< std::shared_ptr<const AmenityCategory> >& categories )
{
    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::OsmAndPoiIndex::kCategoriesTableFieldNumber:
            {
                gpb::uint32 length;
                cis->ReadVarint32(&length);
                const auto offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(length);
                
                std::shared_ptr<AmenityCategory> category(new AmenityCategory());
                readCategory(reader, category);
                
                ObfReaderUtilities::ensureAllDataWasRead(cis);
                cis->PopLimit(oldLimit);

                categories.push_back(qMove(category));
            }
            break;
        case OBF::OsmAndPoiIndex::kNameIndexFieldNumber:
            cis->Skip(cis->BytesUntilLimit());
            return;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #26
0
void OsmAnd::ObfMapSectionReader_P::readMapLevelHeader(
    const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfMapSectionInfo>& section,
    const std::shared_ptr<ObfMapSectionLevel>& level )
{
    auto cis = reader->_codedInputStream.get();

    for(;;)
    {
        const auto tagPos = cis->CurrentPosition();
        const auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            return;
        case OBF::OsmAndMapIndex_MapRootLevel::kMaxZoomFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_maxZoom));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kMinZoomFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_minZoom));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kLeftFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_area31.left));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kRightFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_area31.right));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kTopFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_area31.top));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kBottomFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&level->_area31.bottom));
            break;
        case OBF::OsmAndMapIndex_MapRootLevel::kBoxesFieldNumber:
            {
                // Save boxes offset
                level->_boxesInnerOffset = tagPos - level->_offset;

                // Skip reading boxes and surely, following blocks
                cis->Skip(cis->BytesUntilLimit());
            }
            return;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #27
0
void OsmAnd::ObfMapSectionReader_P::readRules(
    const std::unique_ptr<ObfReader_P>& reader,
    const std::shared_ptr<ObfMapSectionInfo_P::Rules>& rules)
{
    auto cis = reader->_codedInputStream.get();

    uint32_t defaultId = 1;
    for(;;)
    {
        gpb::uint32 tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            {
                auto free = rules->_decodingRules.size() * 2 + 1;
                rules->_coastlineBrokenEncodingType = free++;
                createRule(rules, 0, rules->_coastlineBrokenEncodingType, QString::fromLatin1("natural"), QString::fromLatin1("coastline_broken"));
                if(rules->_landEncodingType == -1)
                {
                    rules->_landEncodingType = free++;
                    createRule(rules, 0, rules->_landEncodingType, QString::fromLatin1("natural"), QString::fromLatin1("land"));
                }
            }
            return;
        case OBF::OsmAndMapIndex::kRulesFieldNumber:
            {
                gpb::uint32 length;
                cis->ReadVarint32(&length);
                auto oldLimit = cis->PushLimit(length);
                readRule(reader, defaultId++, rules);
                cis->PopLimit(oldLimit);
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }
}
コード例 #28
0
void OsmAnd::ObfMapSectionReader_P::readAttributeMappingEntry(
    const ObfReader_P& reader,
    const uint32_t naturalId,
    const std::shared_ptr<ObfMapSectionAttributeMapping>& attributeMapping)
{
    const auto cis = reader.getCodedInputStream().get();

    uint32_t entryId = naturalId;
    QString entryTag;
    QString entryValue;
    for (;;)
    {
        const auto tag = cis->ReadTag();
        switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
            case 0:
                if (!ObfReaderUtilities::reachedDataEnd(cis))
                    return;

                attributeMapping->registerMapping(entryId, entryTag, entryValue);
                return;
            case OBF::OsmAndMapIndex_MapEncodingRule::kValueFieldNumber:
                ObfReaderUtilities::readQString(cis, entryValue);
                break;
            case OBF::OsmAndMapIndex_MapEncodingRule::kTagFieldNumber:
                ObfReaderUtilities::readQString(cis, entryTag);
                break;
            case OBF::OsmAndMapIndex_MapEncodingRule::kIdFieldNumber:
                cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&entryId));
                break;
            default:
                ObfReaderUtilities::skipUnknownField(cis, tag);
                break;
        }
    }
}
コード例 #29
0
ファイル: ObfReader_P.cpp プロジェクト: vmkrish/OsmAnd-core
bool OsmAnd::ObfReader_P::readInfo(const ObfReader_P& reader, std::shared_ptr<const ObfInfo>& info_)
{
    auto cis = reader._codedInputStream.get();

    std::shared_ptr<ObfInfo> info(new ObfInfo());
    bool loadedCorrectly = false;
    for(;;)
    {
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            if(loadedCorrectly)
                info_ = info;

            return loadedCorrectly;
        case OBF::OsmAndStructure::kVersionFieldNumber:
            cis->ReadVarint32(reinterpret_cast<gpb::uint32*>(&info->_version));
            break;
        case OBF::OsmAndStructure::kDateCreatedFieldNumber:
            cis->ReadVarint64(reinterpret_cast<gpb::uint64*>(&info->_creationTimestamp));
            break;
        case OBF::OsmAndStructure::kMapIndexFieldNumber:
            {
                const std::shared_ptr<ObfMapSectionInfo> section(new ObfMapSectionInfo(info));
                section->_length = ObfReaderUtilities::readBigEndianInt(cis);
                section->_offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(section->_length);

                ObfMapSectionReader_P::read(reader, section);

                info->_isBasemap = info->_isBasemap || section->isBasemap;
                cis->PopLimit(oldLimit);
                cis->Seek(section->_offset + section->_length);

                info->_mapSections.push_back(qMove(section));
            }
            break;
        case OBF::OsmAndStructure::kAddressIndexFieldNumber:
            {
                const std::shared_ptr<ObfAddressSectionInfo> section(new ObfAddressSectionInfo(info));
                section->_length = ObfReaderUtilities::readBigEndianInt(cis);
                section->_offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(section->_length);

                ObfAddressSectionReader_P::read(reader, section);

                cis->PopLimit(oldLimit);
                cis->Seek(section->_offset + section->_length);

                info->_addressSections.push_back(qMove(section));
            }
            break;
        case OBF::OsmAndStructure::kTransportIndexFieldNumber:
            {
                const std::shared_ptr<ObfTransportSectionInfo> section(new ObfTransportSectionInfo(info));
                section->_length = ObfReaderUtilities::readBigEndianInt(cis);
                section->_offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(section->_length);

                ObfTransportSectionReader_P::read(reader, section);

                cis->PopLimit(oldLimit);
                cis->Seek(section->_offset + section->_length);

                info->_transportSections.push_back(qMove(section));
            }
            break;
        case OBF::OsmAndStructure::kRoutingIndexFieldNumber:
            {
                const std::shared_ptr<ObfRoutingSectionInfo> section(new ObfRoutingSectionInfo(info));
                section->_length = ObfReaderUtilities::readBigEndianInt(cis);
                section->_offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(section->_length);

                ObfRoutingSectionReader_P::read(reader, section);

                cis->PopLimit(oldLimit);
                cis->Seek(section->_offset + section->_length);

                info->_routingSections.push_back(qMove(section));
            }
            break;
        case OBF::OsmAndStructure::kPoiIndexFieldNumber:
            {
                const std::shared_ptr<ObfPoiSectionInfo> section(new ObfPoiSectionInfo(info));
                section->_length = ObfReaderUtilities::readBigEndianInt(cis);
                section->_offset = cis->CurrentPosition();
                auto oldLimit = cis->PushLimit(section->_length);

                ObfPoiSectionReader_P::read(reader, section);

                cis->PopLimit(oldLimit);
                cis->Seek(section->_offset + section->_length);

                info->_poiSections.push_back(qMove(section));
            }
            break;
        case OBF::OsmAndStructure::kVersionConfirmFieldNumber:
            {
                gpb::uint32 controlVersion;
                cis->ReadVarint32(&controlVersion);
                loadedCorrectly = (controlVersion == info->_version);
                if(!loadedCorrectly)
                    break;
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
    }

    return false;
}
コード例 #30
0
bool OsmAnd::ObfPoiSectionReader_P::readTile(
    const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section,
    QList< std::shared_ptr<Tile> >& tiles,
    Tile* parent,
    QSet<uint32_t>* desiredCategories,
    uint32_t zoom, uint32_t zoomDepth, const AreaI* bbox31,
    IQueryController* controller,
    QSet< uint64_t >* tilesToSkip)
{
    auto cis = reader->_codedInputStream.get();

    const auto zoomToSkip = zoom + zoomDepth;
    QSet< uint64_t > tilesToSkip_;
    if(parent == nullptr && !tilesToSkip)
        tilesToSkip = &tilesToSkip_;

    std::shared_ptr<Tile> tile(new Tile());
    gpb::uint32 lzoom;

    for(;;)
    {
        if(controller && controller->isAborted())
            return false;
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            tiles.push_back(tile);
            return true;
        case OBF::OsmAndPoiBox::kZoomFieldNumber:
            {
                cis->ReadVarint32(&lzoom);
                tile->_zoom = lzoom;
                if(parent)
                    tile->_zoom += parent->_zoom;
            }
            break;
        case OBF::OsmAndPoiBox::kLeftFieldNumber:
            {
                auto x = ObfReaderUtilities::readSInt32(cis);
                if(parent)
                    tile->_x = x + (parent->_x << lzoom);
                else
                    tile->_x = x;
            }
            break;
        case OBF::OsmAndPoiBox::kTopFieldNumber:
            {
                auto y = ObfReaderUtilities::readSInt32(cis);
                if(parent)
                    tile->_y = y + (parent->_y << lzoom);
                else
                    tile->_y = y;

                // Check that we're inside bounding box, if requested
                if(bbox31)
                {
                    AreaI area31;
                    area31.left = tile->_x << (31 - tile->_zoom);
                    area31.right = (tile->_x + 1) << (31 - tile->_zoom);
                    area31.top = tile->_y << (31 - tile->_zoom);
                    area31.bottom = (tile->_y + 1) << (31 - tile->_zoom);

                    if(!bbox31->intersects(area31))
                    {
                        // This tile is outside of bounding box
                        cis->Skip(cis->BytesUntilLimit());
                        return false;
                    }
                }
            }
            break;
        case OBF::OsmAndPoiBox::kCategoriesFieldNumber:
            {
                if(!desiredCategories)
                {
                    ObfReaderUtilities::skipUnknownField(cis, tag);
                    break;
                }
                gpb::uint32 length;
                cis->ReadLittleEndian32(&length);
                auto oldLimit = cis->PushLimit(length);
                const auto containsDesired = checkTileCategories(reader, section, desiredCategories);
                cis->PopLimit(oldLimit);
                if(!containsDesired)
                {
                    cis->Skip(cis->BytesUntilLimit());
                    return false;
                }
            }
            break;
        case OBF::OsmAndPoiBox::kSubBoxesFieldNumber:
            {
                auto length = ObfReaderUtilities::readBigEndianInt(cis);
                auto oldLimit = cis->PushLimit(length);
                auto tileOmitted = readTile(reader, section, tiles, tile.get(), desiredCategories, zoom, zoomDepth, bbox31, controller, tilesToSkip);
                cis->PopLimit(oldLimit);

                if(tilesToSkip && tile->_zoom >= zoomToSkip && tileOmitted)
                {
                    auto skipHash = (static_cast<uint64_t>(tile->_x) >> (tile->_zoom - zoomToSkip)) << zoomToSkip;
                    skipHash |= static_cast<uint64_t>(tile->_y) >> (tile->_zoom - zoomToSkip);
                    if(tilesToSkip->contains(skipHash))
                    {
                        cis->Skip(cis->BytesUntilLimit());
                        return true;
                    }
                }
            }
            break;
        case OBF::OsmAndPoiBox::kShiftToDataFieldNumber:
            {
                tile->_offset = ObfReaderUtilities::readBigEndianInt(cis);
                tile->_hash  = static_cast<uint64_t>(tile->_x) << tile->_zoom;
                tile->_hash |= static_cast<uint64_t>(tile->_y);
                tile->_hash |= tile->_zoom;

                // skipTiles - these tiles are going to be ignored, since we need only 1 POI object (x;y)@zoom
                if(tilesToSkip && tile->_zoom >= zoomToSkip)
                {
                    auto skipHash = (static_cast<uint64_t>(tile->_x) >> (tile->_zoom - zoomToSkip)) << zoomToSkip;
                    skipHash |= static_cast<uint64_t>(tile->_y) >> (tile->_zoom - zoomToSkip);
                    tilesToSkip->insert(skipHash);
                }
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }