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;
        }
    }
}
Exemplo n.º 2
0
QStandardItem* XmlListReader::parse() {
    QFile file(m_table[m_listCategory]);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "Unable to open the file";
        return NULL;
    }

    qDebug() << "XML FILE TO IMPORT: " << m_table[m_listCategory];

    m_reader.setDevice(&file);

    // Start parsing the list.
    while (!m_reader.atEnd() && !m_reader.hasError()) {
        QXmlStreamReader::TokenType token = m_reader.readNext();

        if (token == QXmlStreamReader::StartDocument)
            continue;

        if (token == QXmlStreamReader::StartElement) {
            if (m_reader.name() == XML_TAG_LIST)
                continue;

            m_rootItem->appendRow(readCategory());
        }
    }

    if (m_reader.hasError()) {
        qDebug() << "xml parse error: " << m_reader.errorString();
    }

    m_reader.clear();
    return m_rootItem;
}
Exemplo n.º 3
0
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::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;
        }
    }
}
Exemplo n.º 5
0
bool QLandmarkFileHandlerLmx::readLandmark(QLandmark &landmark)
{
    /*
    <xsd:complexType name="landmarkType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" minOccurs="0" />
            <xsd:element name="description" type="xsd:string" minOccurs="0" />
            <xsd:element name="coordinates" type="coordinatesType" minOccurs="0" />
            <xsd:element name="coverageRadius" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:float">
                        <xsd:minInclusive value="0"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="addressInfo" type="addressInfoType" minOccurs="0" />
            <xsd:element name="mediaLink" type="mediaLinkType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="category" type="categoryType" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
    */

    if(m_cancel && (*m_cancel) == true) {
        m_errorCode = QLandmarkManager::CancelError;
        m_error = "Import of lmx file was canceled";
        return false;
    }

    Q_ASSERT(m_reader->isStartElement() &&
             (m_reader->name() == "landmark"));

    m_landmarkCategoryNames.append(QStringList());

    if (!m_reader->readNextStartElement())
        return true;

    if (m_reader->name() == "name") {
        landmark.setName(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "description") {
        landmark.setDescription(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "coordinates") {
        if (!readCoordinates(landmark))
            return false;

        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "coverageRadius") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s));
            return false;
        }

        qreal rad = (qreal)(s.toDouble(&ok));

        if (!ok) {
            m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s));
            return false;
        }

        if (rad < 0.0) {
            m_reader->raiseError(QString("The element \"coverageRadius\" is expected to have a non-negative value (value was \"%1\").").arg(s));
            return false;
        }

        landmark.setRadius(rad);

        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "addressInfo") {
        if (!readAddressInfo(landmark))
            return false;

        if (!m_reader->readNextStartElement())
            return true;
    }

    // TODO need to document the fact that only the first link is read
    // and the others are ignored
    bool mediaLinkRead = false;

    while (m_reader->name() == "mediaLink") {
        if (!mediaLinkRead) {
            mediaLinkRead = true;
            if (!readMediaLink(landmark))
                return false;
        }

        if (!m_reader->readNextStartElement())
            return true;
    }


    QStringList categoryNames;
    while (m_reader->name() == "category") {
        QString name;
        if (!readCategory(name))
            return false;
        categoryNames << name;

        if (!m_reader->readNextStartElement()) {
            m_landmarkCategoryNames.last() = categoryNames;
            return true;
        }
    }

    m_reader->raiseError(QString("The element \"landmark\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString()));
    return false;
}