本文整理汇总了C++中ObfReader_P类的典型用法代码示例。如果您正苦于以下问题:C++ ObfReader_P类的具体用法?C++ ObfReader_P怎么用?C++ ObfReader_P使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObfReader_P类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void OsmAnd::ObfTransportSectionReader_P::readTransportStopsBounds( 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::TransportStopsTree::kLeftFieldNumber:
section->_area24.left() = ObfReaderUtilities::readSInt32(cis);
break;
case OBF::TransportStopsTree::kRightFieldNumber:
section->_area24.right() = ObfReaderUtilities::readSInt32(cis);
break;
case OBF::TransportStopsTree::kTopFieldNumber:
section->_area24.top() = ObfReaderUtilities::readSInt32(cis);
break;
case OBF::TransportStopsTree::kBottomFieldNumber:
section->_area24.bottom() = ObfReaderUtilities::readSInt32(cis);
break;
default:
ObfReaderUtilities::skipUnknownField(cis, tag);
break;
}
}
}
示例2: switch
void OsmAnd::ObfPoiSectionReader_P::readCategory( const ObfReader_P& reader, const std::shared_ptr<AmenityCategory>& category )
{
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::OsmAndCategoryTable::kCategoryFieldNumber:
ObfReaderUtilities::readQString(cis, category->_name);
break;
case OBF::OsmAndCategoryTable::kSubcategoriesFieldNumber:
{
QString name;
if (ObfReaderUtilities::readQString(cis, name))
category->_subcategories.push_back(qMove(name));
}
break;
default:
ObfReaderUtilities::skipUnknownField(cis, tag);
break;
}
}
}
示例3: readCategories
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);
}
示例4: switch
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;
}
}
}
示例5: readAmenities
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);
}
示例6: tile
bool OsmAnd::ObfPoiSectionReader_P::readTile(
const 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,
const IQueryController* const controller,
QSet< uint64_t >* tilesToSkip)
{
const auto cis = reader.getCodedInputStream().get();
const auto zoomToSkip = zoom + zoomDepth;
QSet< uint64_t > tilesToSkip_;
if (parent == nullptr && !tilesToSkip)
tilesToSkip = &tilesToSkip_;
const std::shared_ptr<Tile> tile(new Tile());
gpb::uint32 lzoom;
for(;;)
{
if (controller && controller->isAborted())
return false;
const auto tag = cis->ReadTag();
switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
{
case 0:
if (!ObfReaderUtilities::reachedDataEnd(cis))
return false;
tiles.push_back(qMove(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);
const auto shouldSkip =
!bbox31->contains(area31) &&
!area31.contains(*bbox31) &&
!bbox31->intersects(area31);
if (shouldSkip)
{
// 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);
const auto offset = cis->CurrentPosition();
const auto oldLimit = cis->PushLimit(length);
const auto containsDesired = checkTileCategories(reader, section, desiredCategories);
ObfReaderUtilities::ensureAllDataWasRead(cis);
cis->PopLimit(oldLimit);
if (!containsDesired)
{
cis->Skip(cis->BytesUntilLimit());
return false;
}
//.........这里部分代码省略.........
示例7: filterById
void OsmAnd::ObfMapSectionReader_P::loadMapObjects(
const ObfReader_P& reader,
const std::shared_ptr<const ObfMapSectionInfo>& section,
ZoomLevel zoom,
const AreaI* bbox31,
QList< std::shared_ptr<const OsmAnd::BinaryMapObject> >* resultOut,
MapSurfaceType* outBBoxOrSectionSurfaceType,
const ObfMapSectionReader::FilterByIdFunction filterById,
const VisitorFunction visitor,
DataBlocksCache* cache,
QList< std::shared_ptr<const DataBlock> >* outReferencedCacheEntries,
const std::shared_ptr<const IQueryController>& queryController,
ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric)
{
const auto cis = reader.getCodedInputStream().get();
const auto filterReadById =
[filterById, zoom]
(const std::shared_ptr<const ObfMapSectionInfo>& section,
const ObfObjectId mapObjectId,
const AreaI& bbox,
const ZoomLevel firstZoomLevel,
const ZoomLevel lastZoomLevel) -> bool
{
return filterById(section, mapObjectId, bbox, firstZoomLevel, lastZoomLevel, zoom);
};
// Ensure encoding/decoding rules are read
if (section->_p->_attributeMappingLoaded.loadAcquire() == 0)
{
QMutexLocker scopedLocker(§ion->_p->_attributeMappingLoadMutex);
if (!section->_p->_attributeMapping)
{
// Read encoding/decoding rules
cis->Seek(section->offset);
auto oldLimit = cis->PushLimit(section->length);
const std::shared_ptr<ObfMapSectionAttributeMapping> attributeMapping(new ObfMapSectionAttributeMapping());
readAttributeMapping(reader, section, attributeMapping);
section->_p->_attributeMapping = attributeMapping;
cis->PopLimit(oldLimit);
section->_p->_attributeMappingLoaded.storeRelease(1);
}
}
ObfMapSectionReader_Metrics::Metric_loadMapObjects localMetric;
auto bboxOrSectionSurfaceType = MapSurfaceType::Undefined;
if (outBBoxOrSectionSurfaceType)
*outBBoxOrSectionSurfaceType = bboxOrSectionSurfaceType;
QList< std::shared_ptr<const DataBlock> > danglingReferencedCacheEntries;
for (const auto& mapLevel : constOf(section->levels))
{
// Update metric
if (metric)
metric->visitedLevels++;
if (mapLevel->minZoom > zoom || mapLevel->maxZoom < zoom)
continue;
if (bbox31)
{
const Stopwatch bboxLevelCheckStopwatch(metric != nullptr);
const auto shouldSkip =
!bbox31->contains(mapLevel->area31) &&
!mapLevel->area31.contains(*bbox31) &&
!bbox31->intersects(mapLevel->area31);
if (metric)
metric->elapsedTimeForLevelsBbox += bboxLevelCheckStopwatch.elapsed();
if (shouldSkip)
continue;
}
const Stopwatch treeNodesStopwatch(metric != nullptr);
if (metric)
metric->acceptedLevels++;
// If there are no tree nodes in map level, it means they are not loaded.
// Since loading may be called from multiple threads, loading of root nodes needs synchronization
// Ensure encoding/decoding rules are read
if (mapLevel->_p->_rootNodesLoaded.loadAcquire() == 0)
{
QMutexLocker scopedLocker(&mapLevel->_p->_rootNodesLoadMutex);
if (!mapLevel->_p->_rootNodes)
{
cis->Seek(mapLevel->offset);
auto oldLimit = cis->PushLimit(mapLevel->length);
cis->Skip(mapLevel->firstDataBoxInnerOffset);
const std::shared_ptr< QList< std::shared_ptr<const ObfMapSectionLevelTreeNode> > > rootNodes(
new QList< std::shared_ptr<const ObfMapSectionLevelTreeNode> >());
readMapLevelTreeNodes(reader, section, mapLevel, *rootNodes);
mapLevel->_p->_rootNodes = rootNodes;
cis->PopLimit(oldLimit);
//.........这里部分代码省略.........
示例8: mapObjectPointsStopwatch
void OsmAnd::ObfMapSectionReader_P::readMapObject(
const ObfReader_P& reader,
const std::shared_ptr<const ObfMapSectionInfo>& section,
uint64_t baseId,
const std::shared_ptr<const ObfMapSectionLevelTreeNode>& treeNode,
std::shared_ptr<OsmAnd::BinaryMapObject>& mapObject,
const AreaI* bbox31,
ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric)
{
const auto cis = reader.getCodedInputStream().get();
const auto baseOffset = cis->CurrentPosition();
for (;;)
{
const auto tag = cis->ReadTag();
const auto tgn = gpb::internal::WireFormatLite::GetTagFieldNumber(tag);
switch (tgn)
{
case 0:
{
if (!ObfReaderUtilities::reachedDataEnd(cis))
return;
if (mapObject && mapObject->points31.isEmpty())
{
LogPrintf(LogSeverityLevel::Warning,
"Empty BinaryMapObject %s detected in section '%s'",
qPrintable(mapObject->id.toString()),
qPrintable(section->name));
mapObject.reset();
}
return;
}
case OBF::MapData::kAreaCoordinatesFieldNumber:
case OBF::MapData::kCoordinatesFieldNumber:
{
const Stopwatch mapObjectPointsStopwatch(metric != nullptr);
gpb::uint32 length;
cis->ReadVarint32(&length);
const auto oldLimit = cis->PushLimit(length);
PointI p;
p.x = treeNode->area31.left() & MaskToRead;
p.y = treeNode->area31.top() & MaskToRead;
AreaI objectBBox;
objectBBox.top() = objectBBox.left() = std::numeric_limits<int32_t>::max();
objectBBox.bottom() = objectBBox.right() = 0;
auto lastUnprocessedVertexForBBox = 0;
// In protobuf, a sint32 can be encoded using [1..4] bytes,
// so try to guess size of array, and preallocate it.
// (BytesUntilLimit/2) is ~= number of vertices, and is always larger than needed.
// So it's impossible that a buffer overflow will ever happen. But assert on that.
const auto probableVerticesCount = (cis->BytesUntilLimit() / 2);
QVector< PointI > points31(probableVerticesCount);
auto pPoint = points31.data();
auto verticesCount = 0;
bool shouldNotSkip = (bbox31 == nullptr);
while (cis->BytesUntilLimit() > 0)
{
PointI d;
d.x = (ObfReaderUtilities::readSInt32(cis) << ShiftCoordinates);
d.y = (ObfReaderUtilities::readSInt32(cis) << ShiftCoordinates);
p += d;
// Save point into storage
assert(points31.size() > verticesCount);
*(pPoint++) = p;
verticesCount++;
// Check if map object should be maintained
if (!shouldNotSkip && bbox31)
{
const Stopwatch mapObjectBboxStopwatch(metric != nullptr);
shouldNotSkip = bbox31->contains(p);
objectBBox.enlargeToInclude(p);
if (metric)
metric->elapsedTimeForMapObjectsBbox += mapObjectBboxStopwatch.elapsed();
lastUnprocessedVertexForBBox = verticesCount;
}
}
cis->PopLimit(oldLimit);
// Since reserved space may be larger than actual amount of data,
// shrink the vertices array
points31.resize(verticesCount);
// If map object has no vertices, retain it in a special way to report later, when
// it's identifier will be known
if (points31.isEmpty())
{
//.........这里部分代码省略.........
示例9: readMapObjectStopwatch
void OsmAnd::ObfMapSectionReader_P::readMapObjectsBlock(
const ObfReader_P& reader,
const std::shared_ptr<const ObfMapSectionInfo>& section,
const std::shared_ptr<const ObfMapSectionLevelTreeNode>& tree,
QList< std::shared_ptr<const OsmAnd::BinaryMapObject> >* resultOut,
const AreaI* bbox31,
const FilterReadingByIdFunction filterById,
const VisitorFunction visitor,
const std::shared_ptr<const IQueryController>& queryController,
ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric)
{
const auto cis = reader.getCodedInputStream().get();
QList< std::shared_ptr<BinaryMapObject> > intermediateResult;
QStringList mapObjectsCaptionsTable;
gpb::uint64 baseId = 0;
for (;;)
{
const auto tag = cis->ReadTag();
switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
{
case 0:
{
if (!ObfReaderUtilities::reachedDataEnd(cis))
return;
for (const auto& mapObject : constOf(intermediateResult))
{
// Fill mapObject captions from string-table
for (auto& caption : mapObject->captions)
{
const auto stringId = ObfReaderUtilities::decodeIntegerFromString(caption);
if (stringId >= mapObjectsCaptionsTable.size())
{
LogPrintf(LogSeverityLevel::Error,
"Data mismatch: string #%d (map object %s not found in string table (size %d) in section '%s'",
stringId,
qPrintable(mapObject->id.toString()),
mapObjectsCaptionsTable.size(), qPrintable(section->name));
caption = QString::fromLatin1("#%1 NOT FOUND").arg(stringId);
continue;
}
caption = mapObjectsCaptionsTable[stringId];
}
//////////////////////////////////////////////////////////////////////////
//if (mapObject->id.getOsmId() == 49048972u)
//{
// int i = 5;
//}
//////////////////////////////////////////////////////////////////////////
if (!visitor || visitor(mapObject))
{
if (resultOut)
resultOut->push_back(qMove(mapObject));
}
}
return;
}
case OBF::MapDataBlock::kBaseIdFieldNumber:
{
cis->ReadVarint64(&baseId);
//////////////////////////////////////////////////////////////////////////
//if (bbox31)
// LogPrintf(LogSeverityLevel::Debug, "BBOX %d %d %d %d - MAP BLOCK %" PRIi64, bbox31->top, bbox31->left, bbox31->bottom, bbox31->right, baseId);
//////////////////////////////////////////////////////////////////////////
break;
}
case OBF::MapDataBlock::kDataObjectsFieldNumber:
{
gpb::uint32 length;
cis->ReadVarint32(&length);
const auto offset = cis->CurrentPosition();
// Read map object content
const Stopwatch readMapObjectStopwatch(metric != nullptr);
std::shared_ptr<OsmAnd::BinaryMapObject> mapObject;
auto oldLimit = cis->PushLimit(length);
readMapObject(reader, section, baseId, tree, mapObject, bbox31, metric);
ObfReaderUtilities::ensureAllDataWasRead(cis);
cis->PopLimit(oldLimit);
// Update metric
if (metric)
metric->visitedMapObjects++;
// If map object was not read, skip it
if (!mapObject)
{
if (metric)
metric->elapsedTimeForOnlyVisitedMapObjects += readMapObjectStopwatch.elapsed();
break;
}
//.........这里部分代码省略.........
示例10: if
void OsmAnd::ObfMapSectionReader_P::readTreeNodeChildren(
const ObfReader_P& reader,
const std::shared_ptr<const ObfMapSectionInfo>& section,
const std::shared_ptr<const ObfMapSectionLevelTreeNode>& treeNode,
MapSurfaceType& outChildrenSurfaceType,
QList< std::shared_ptr<const ObfMapSectionLevelTreeNode> >* nodesWithData,
const AreaI* bbox31,
const std::shared_ptr<const IQueryController>& queryController,
ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric)
{
const auto cis = reader.getCodedInputStream().get();
outChildrenSurfaceType = MapSurfaceType::Undefined;
for (;;)
{
const auto tag = cis->ReadTag();
switch (gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
{
case 0:
if (!ObfReaderUtilities::reachedDataEnd(cis))
return;
return;
case OBF::OsmAndMapIndex_MapDataBox::kBoxesFieldNumber:
{
const auto length = ObfReaderUtilities::readBigEndianInt(cis);
const auto offset = cis->CurrentPosition();
const auto oldLimit = cis->PushLimit(length);
const std::shared_ptr<ObfMapSectionLevelTreeNode> childNode(new ObfMapSectionLevelTreeNode(treeNode->level));
childNode->surfaceType = treeNode->surfaceType;
childNode->offset = offset;
childNode->length = length;
readTreeNode(reader, section, treeNode->area31, childNode);
ObfReaderUtilities::ensureAllDataWasRead(cis);
cis->PopLimit(oldLimit);
// Update metric
if (metric)
metric->visitedNodes++;
if (bbox31)
{
const auto shouldSkip =
!bbox31->contains(childNode->area31) &&
!childNode->area31.contains(*bbox31) &&
!bbox31->intersects(childNode->area31);
if (shouldSkip)
break;
}
// Update metric
if (metric)
metric->acceptedNodes++;
if (nodesWithData && childNode->dataOffset > 0)
nodesWithData->push_back(childNode);
auto subchildrenSurfaceType = MapSurfaceType::Undefined;
if (childNode->hasChildrenDataBoxes)
{
cis->Seek(childNode->offset);
const auto oldLimit = cis->PushLimit(childNode->length);
cis->Skip(childNode->firstDataBoxInnerOffset);
readTreeNodeChildren(reader, section, childNode, subchildrenSurfaceType, nodesWithData, bbox31, queryController, metric);
ObfReaderUtilities::ensureAllDataWasRead(cis);
cis->PopLimit(oldLimit);
}
const auto surfaceTypeToMerge = (subchildrenSurfaceType != MapSurfaceType::Undefined) ? subchildrenSurfaceType : childNode->surfaceType;
if (surfaceTypeToMerge != MapSurfaceType::Undefined)
{
if (outChildrenSurfaceType == MapSurfaceType::Undefined)
outChildrenSurfaceType = surfaceTypeToMerge;
else if (outChildrenSurfaceType != surfaceTypeToMerge)
outChildrenSurfaceType = MapSurfaceType::Mixed;
}
break;
}
default:
ObfReaderUtilities::skipUnknownField(cis, tag);
break;
}
}
}