本文整理汇总了C++中Area::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ Area::Read方法的具体用法?C++ Area::Read怎么用?C++ Area::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Area
的用法示例。
在下文中一共展示了Area::Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ScanAreaIds
bool OptimizeAreaWayIdsGenerator::ScanAreaIds(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
NodeUseMap& nodeUseMap)
{
FileScanner scanner;
uint32_t dataCount=0;
progress.SetAction("Scanning ids from 'areas.tmp'");
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas.tmp"),
FileScanner::Sequential,
parameter.GetAreaDataMemoryMaped())) {
progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'");
return false;
}
if (!scanner.Read(dataCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
for (size_t current=1; current<=dataCount; current++) {
uint8_t type;
Id id;
Area data;
progress.SetProgress(current,dataCount);
if (!scanner.Read(type) ||
!scanner.Read(id) ||
!data.Read(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(current)+" of "+
NumberToString(dataCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
for (const auto& ring: data.rings) {
std::unordered_set<Id> nodeIds;
if (!ring.GetType()->CanRoute()) {
continue;
}
for (const auto id: ring.ids) {
if (nodeIds.find(id)==nodeIds.end()) {
nodeUseMap.SetNodeUsed(id);
nodeIds.insert(id);
}
}
}
}
if (!scanner.Close()) {
progress.Error(std::string("Error while closing file '")+
scanner.GetFilename()+"'");
return false;
}
return true;
}
示例2: Import
bool AreaAreaIndexGenerator::Import(const TypeConfigRef& typeConfig,
const ImportParameter& parameter,
Progress& progress)
{
FileScanner scanner;
size_t areas=0; // Number of areas found
size_t areasConsumed=0; // Number of areas consumed
std::vector<double> cellWidth;
std::vector<double> cellHeight;
std::map<Pixel,AreaLeaf> leafs;
std::map<Pixel,AreaLeaf> newAreaLeafs;
cellWidth.resize(parameter.GetAreaAreaIndexMaxMag()+1);
cellHeight.resize(parameter.GetAreaAreaIndexMaxMag()+1);
for (size_t i=0; i<cellWidth.size(); i++) {
cellWidth[i]=360.0/pow(2.0,(int)i);
}
for (size_t i=0; i<cellHeight.size(); i++) {
cellHeight[i]=180.0/pow(2.0,(int)i);
}
//
// Writing index file
//
progress.SetAction("Generating 'areaarea.idx'");
FileWriter writer;
FileOffset topLevelOffset=0;
FileOffset topLevelOffsetOffset; // Offset of the toplevel entry
if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areaarea.idx"))) {
progress.Error("Cannot create 'areaarea.idx'");
return false;
}
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas.dat"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error("Cannot open 'areas.dat'");
return false;
}
writer.WriteNumber((uint32_t)parameter.GetAreaAreaIndexMaxMag()); // MaxMag
if (!writer.GetPos(topLevelOffsetOffset)) {
progress.Error("Cannot read current file position");
return false;
}
if (!writer.WriteFileOffset(topLevelOffset)) {
progress.Error("Cannot write top level entry offset");
return false;
}
int l=parameter.GetAreaAreaIndexMaxMag();
while (l>=0) {
size_t areaLevelEntries=0;
progress.Info(std::string("Storing level ")+NumberToString(l)+"...");
newAreaLeafs.clear();
SetOffsetOfChildren(leafs,newAreaLeafs);
leafs=newAreaLeafs;
// Areas
if (areas==0 ||
(areas>0 && areas>areasConsumed)) {
uint32_t areaCount=0;
progress.Info(std::string("Scanning areas.dat for areas of index level ")+NumberToString(l)+"...");
if (!scanner.GotoBegin()) {
progress.Error("Cannot go to begin of way file");
}
if (!scanner.Read(areaCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
areas=0;
for (uint32_t a=1; a<=areaCount; a++) {
progress.SetProgress(a,areaCount);
FileOffset offset;
Area area;
scanner.GetPos(offset);
if (!area.Read(typeConfig,
scanner)) {
//.........这里部分代码省略.........
示例3: CopyAreas
bool OptimizeAreaWayIdsGenerator::CopyAreas(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
NodeUseMap& nodeUseMap)
{
FileScanner scanner;
FileWriter writer;
uint32_t areaCount=0;
if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas2.tmp"))) {
progress.Error(std::string("Cannot create '")+writer.GetFilename()+"'");
return false;
}
writer.Write(areaCount);
progress.SetAction("Copy data from 'areas.tmp' to 'areas2.tmp'");
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas.tmp"),
FileScanner::Sequential,
parameter.GetAreaDataMemoryMaped())) {
progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'");
return false;
}
if (!scanner.Read(areaCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
for (size_t current=1; current<=areaCount; current++) {
uint8_t type;
Id id;
Area data;
progress.SetProgress(current,areaCount);
if (!scanner.Read(type) ||
!scanner.Read(id) ||
!data.Read(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(current)+" of "+
NumberToString(areaCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
for (auto& ring : data.rings) {
std::unordered_set<Id> nodeIds;
for (auto& id : ring.ids) {
if (!nodeUseMap.IsNodeUsedAtLeastTwice(id)) {
id=0;
}
}
}
if (!writer.Write(type) ||
!writer.Write(id) ||
!data.Write(typeConfig,
writer)) {
progress.Error(std::string("Error while writing data entry to file '")+
writer.GetFilename()+"'");
return false;
}
}
if (!scanner.Close()) {
progress.Error(std::string("Error while closing file '")+
scanner.GetFilename()+"'");
return false;
}
if (!writer.SetPos(0)) {
return false;
}
if (!writer.Write(areaCount)) {
return false;
}
if (!writer.Close()) {
progress.Error(std::string("Error while closing file '")+
writer.GetFilename()+"'");
return false;
}
return true;
}