libosmscout
0.1
|
#include <FileScanner.h>
Public Types | |
enum | Mode { Sequential, FastRandom, LowMemRandom, Normal } |
Public Member Functions | |
void | Close () |
Closes the file. More... | |
void | CloseFailsafe () |
Closes the file. More... | |
FileScanner ()=default | |
std::string | GetFilename () const |
FileOffset | GetPos () const |
Returns the current position of the reading cursor in relation to the begining of the file. More... | |
void | GotoBegin () |
Moves the reading cursor to the start of the file (offset 0) More... | |
bool | HasError () const |
bool | IsEOF () const |
bool | IsOpen () const |
void | Open (const std::string &filename, Mode mode, bool useMmap) |
void | Read (char *buffer, size_t bytes) |
uint16_t | Read (size_t bytes) |
void | Read (std::vector< Point > &nodes, std::vector< SegmentGeoBox > &segments, GeoBox &bbox, bool readIds) |
Reads vector of Point and pre-compute segments and bounding box for it. More... | |
bool | ReadBool () |
GeoBox | ReadBox () |
std::byte | ReadByte () |
Color | ReadColor () |
std::tuple< GeoCoord, bool > | ReadConditionalCoord () |
GeoCoord | ReadCoord () |
FileOffset | ReadFileOffset () |
FileOffset | ReadFileOffset (size_t bytes) |
int16_t | ReadInt16 () |
int16_t | ReadInt16Number () |
int32_t | ReadInt32 () |
int32_t | ReadInt32Number () |
int64_t | ReadInt64 () |
int64_t | ReadInt64Number () |
int8_t | ReadInt8 () |
ObjectFileRef | ReadObjectFileRef () |
std::vector< ObjectFileRef > | ReadObjectFileRefs (size_t count) |
std::string | ReadString () |
TypeId | ReadTypeId (uint8_t maxBytes) |
uint16_t | ReadUInt16 () |
uint16_t | ReadUInt16Number () |
uint32_t | ReadUInt32 () |
uint32_t | ReadUInt32 (size_t bytes) |
uint32_t | ReadUInt32Number () |
uint64_t | ReadUInt64 () |
uint64_t | ReadUInt64 (size_t bytes) |
uint64_t | ReadUInt64Number () |
uint8_t | ReadUInt8 () |
void | SetPos (FileOffset pos) |
Moves the reading cursor to the given file position. More... | |
~FileScanner () | |
FileScanner implements platform independent sequential scanning-like access to data in files. File access is buffered.
FileScanner will use mmap in read-only mode if available (and will fall back to normal buffered IO if available but failing), resulting in mapping the complete file into the memory of the process (without allocating real memory) resulting in measurable speed increase because of exchanging buffered file access with in memory array access.
|
default |
osmscout::FileScanner::~FileScanner | ( | ) |
References CloseFailsafe(), IsOpen(), osmscout::log, and osmscout::Log::Warn().
void osmscout::FileScanner::Close | ( | ) |
Closes the file.
If the file was never opened or was already closed an exception is thrown.
If closing the file fails, an exception is thrown
Referenced by osmscout::CoordDataFile::Close(), osmscout::CoverageIndex::Close(), osmscout::AreaIndex::Close(), osmscout::OptimizeWaysLowZoom::Close(), osmscout::WaterIndex::Close(), osmscout::AreaNodeIndex::Close(), osmscout::OptimizeAreasLowZoom::Close(), osmscout::AreaAreaIndex::Close(), osmscout::TypeConfig::GetDatabaseFileFormatVersion(), osmscout::BoundingBoxDataFile::Load(), osmscout::ObjectVariantDataFile::Load(), osmscout::TypeDistributionDataFile::Load(), and osmscout::TypeConfig::LoadFromDataFile().
void osmscout::FileScanner::CloseFailsafe | ( | ) |
Closes the file.
Does not throw any exceptions even if an error occurs.
Use this variant of Close() in cases where the file already run into errors and you just want to clean up the resources using best effort.
Referenced by osmscout::CoverageIndex::Close(), osmscout::AreaIndex::Close(), osmscout::OptimizeWaysLowZoom::Close(), osmscout::WaterIndex::Close(), osmscout::AreaNodeIndex::Close(), osmscout::OptimizeAreasLowZoom::Close(), osmscout::AreaAreaIndex::Close(), osmscout::TypeConfig::GetDatabaseFileFormatVersion(), osmscout::BoundingBoxDataFile::Load(), osmscout::ObjectVariantDataFile::Load(), osmscout::TypeDistributionDataFile::Load(), osmscout::TypeConfig::LoadFromDataFile(), osmscout::CoordDataFile::Open(), and ~FileScanner().
std::string osmscout::FileScanner::GetFilename | ( | ) | const |
FileOffset osmscout::FileScanner::GetPos | ( | ) | const |
Returns the current position of the reading cursor in relation to the begining of the file.
throws IOException on error
References HasError().
Referenced by osmscout::Node::Read(), osmscout::Route::Read(), osmscout::RouteNode::Read(), osmscout::Way::Read(), osmscout::PTRoute::Read(), osmscout::Area::Read(), osmscout::Area::ReadImport(), osmscout::Way::ReadOptimized(), and osmscout::Area::ReadOptimized().
void osmscout::FileScanner::GotoBegin | ( | ) |
Moves the reading cursor to the start of the file (offset 0)
throws IOException on error
References SetPos().
|
inline |
Referenced by GetPos(), IsEOF(), osmscout::CoverageIndex::Open(), osmscout::AreaIndex::Open(), osmscout::OptimizeWaysLowZoom::Open(), osmscout::WaterIndex::Open(), osmscout::OptimizeAreasLowZoom::Open(), osmscout::AreaNodeIndex::Open(), osmscout::AreaAreaIndex::Open(), Read(), ReadBool(), ReadBox(), ReadByte(), ReadColor(), ReadConditionalCoord(), ReadCoord(), ReadFileOffset(), ReadInt16(), ReadInt16Number(), ReadInt32(), ReadInt32Number(), ReadInt64(), ReadInt64Number(), ReadInt8(), ReadString(), ReadUInt16(), ReadUInt16Number(), ReadUInt32(), ReadUInt32Number(), ReadUInt64(), ReadUInt64Number(), ReadUInt8(), and SetPos().
bool osmscout::FileScanner::IsEOF | ( | ) | const |
References HasError().
|
inline |
Referenced by osmscout::CoordDataFile::Close(), osmscout::CoverageIndex::Close(), osmscout::AreaIndex::Close(), osmscout::OptimizeWaysLowZoom::Close(), osmscout::WaterIndex::Close(), osmscout::AreaNodeIndex::Close(), osmscout::OptimizeAreasLowZoom::Close(), osmscout::AreaAreaIndex::Close(), osmscout::CoverageIndex::IsOpen(), osmscout::AreaIndex::IsOpen(), and ~FileScanner().
void osmscout::FileScanner::Open | ( | const std::string & | filename, |
Mode | mode, | ||
bool | useMmap | ||
) |
References osmscout::Log::Error(), FastRandom, osmscout::log, LowMemRandom, and Sequential.
Referenced by osmscout::TypeConfig::GetDatabaseFileFormatVersion(), osmscout::BoundingBoxDataFile::Load(), osmscout::ObjectVariantDataFile::Load(), osmscout::TypeDistributionDataFile::Load(), osmscout::TypeConfig::LoadFromDataFile(), osmscout::CoordDataFile::Open(), osmscout::CoverageIndex::Open(), osmscout::AreaIndex::Open(), osmscout::OptimizeWaysLowZoom::Open(), osmscout::WaterIndex::Open(), osmscout::OptimizeAreasLowZoom::Open(), osmscout::AreaNodeIndex::Open(), and osmscout::AreaAreaIndex::Open().
void osmscout::FileScanner::Read | ( | char * | buffer, |
size_t | bytes | ||
) |
References HasError().
Referenced by osmscout::Route::Read(), osmscout::Way::Read(), osmscout::Area::Read(), osmscout::Area::ReadImport(), osmscout::Way::ReadOptimized(), and osmscout::Area::ReadOptimized().
uint16_t osmscout::FileScanner::Read | ( | size_t | bytes | ) |
References HasError().
void osmscout::FileScanner::Read | ( | std::vector< Point > & | nodes, |
std::vector< SegmentGeoBox > & | segments, | ||
GeoBox & | bbox, | ||
bool | readIds | ||
) |
Reads vector of Point and pre-compute segments and bounding box for it.
nodes | |
segments | |
bbox | |
readIds |
References osmscout::SegmentGeoBox::bbox, osmscout::SegmentGeoBox::from, osmscout::GetBoundingBox(), osmscout::GeoCoord::GetLat(), osmscout::GeoCoord::GetLon(), osmscout::latConversionFactor, osmscout::lonConversionFactor, ReadCoord(), ReadUInt8(), and osmscout::SegmentGeoBox::to.
bool osmscout::FileScanner::ReadBool | ( | ) |
References HasError().
Referenced by osmscout::WaterIndex::Open(), osmscout::AreaNodeIndex::Open(), and osmscout::TypeInfo::Read().
GeoBox osmscout::FileScanner::ReadBox | ( | ) |
References HasError(), and ReadCoord().
Referenced by osmscout::BoundingBoxDataFile::Load(), and osmscout::Route::Read().
std::byte osmscout::FileScanner::ReadByte | ( | ) |
References HasError().
Color osmscout::FileScanner::ReadColor | ( | ) |
References HasError().
Referenced by osmscout::ColorFeatureValue::Read(), and osmscout::PTRoute::Read().
std::tuple< GeoCoord, bool > osmscout::FileScanner::ReadConditionalCoord | ( | ) |
References osmscout::coordByteSize, and HasError().
Referenced by osmscout::CoordDataFile::Get().
GeoCoord osmscout::FileScanner::ReadCoord | ( | ) |
References osmscout::coordByteSize, and HasError().
Referenced by osmscout::AreaNodeIndex::Open(), osmscout::Node::Read(), osmscout::RouteNode::Read(), Read(), osmscout::Area::Read(), ReadBox(), and osmscout::Area::ReadOptimized().
FileOffset osmscout::FileScanner::ReadFileOffset | ( | ) |
References HasError().
Referenced by osmscout::AreaIndex::GetOffsets(), osmscout::CoordDataFile::Open(), osmscout::AreaIndex::Open(), osmscout::OptimizeWaysLowZoom::Open(), osmscout::WaterIndex::Open(), osmscout::OptimizeAreasLowZoom::Open(), osmscout::AreaNodeIndex::Open(), osmscout::AreaAreaIndex::Open(), and ReadObjectFileRef().
FileOffset osmscout::FileScanner::ReadFileOffset | ( | size_t | bytes | ) |
References HasError().
int16_t osmscout::FileScanner::ReadInt16 | ( | ) |
References HasError().
int16_t osmscout::FileScanner::ReadInt16Number | ( | ) |
References osmscout::DecodeNumber(), and HasError().
Referenced by osmscout::EleFeatureValue::Read().
int32_t osmscout::FileScanner::ReadInt32 | ( | ) |
References HasError().
Referenced by osmscout::ConstructionYearFeatureValue::Read().
int32_t osmscout::FileScanner::ReadInt32Number | ( | ) |
References osmscout::DecodeNumber(), and HasError().
int64_t osmscout::FileScanner::ReadInt64 | ( | ) |
References HasError().
int64_t osmscout::FileScanner::ReadInt64Number | ( | ) |
References osmscout::DecodeNumber(), and HasError().
Referenced by osmscout::TurnRestriction::Read().
int8_t osmscout::FileScanner::ReadInt8 | ( | ) |
References HasError().
Referenced by osmscout::LayerFeatureValue::Read().
ObjectFileRef osmscout::FileScanner::ReadObjectFileRef | ( | ) |
References ReadFileOffset(), and ReadUInt8().
Referenced by osmscout::RouteNode::Read(), and osmscout::PTRoute::Read().
std::vector< ObjectFileRef > osmscout::FileScanner::ReadObjectFileRefs | ( | size_t | count | ) |
References ReadUInt64Number().
std::string osmscout::FileScanner::ReadString | ( | ) |
References HasError().
Referenced by osmscout::TypeConfig::LoadFromDataFile(), osmscout::IsInFeatureValue::Read(), osmscout::PhoneFeatureValue::Read(), osmscout::PostalCodeFeatureValue::Read(), osmscout::DestinationFeatureValue::Read(), osmscout::NameShortFeatureValue::Read(), osmscout::WebsiteFeatureValue::Read(), osmscout::OpeningHoursFeatureValue::Read(), osmscout::OperatorFeatureValue::Read(), osmscout::BrandFeatureValue::Read(), osmscout::NetworkFeatureValue::Read(), osmscout::RefFeatureValue::Read(), osmscout::LocationFeatureValue::Read(), osmscout::NameFeatureValue::Read(), osmscout::NameAltFeatureValue::Read(), osmscout::AddressFeatureValue::Read(), osmscout::AdminLevelFeatureValue::Read(), osmscout::MaxStayFeatureValue::Read(), osmscout::ChargingStationFeatureValue::Read(), osmscout::FeeFeatureValue::Read(), osmscout::FromToFeatureValue::Read(), osmscout::LanesFeatureValue::Read(), osmscout::PTRoute::Read(), and osmscout::TypeInfo::Read().
TypeId osmscout::FileScanner::ReadTypeId | ( | uint8_t | maxBytes | ) |
uint16_t osmscout::FileScanner::ReadUInt16 | ( | ) |
uint16_t osmscout::FileScanner::ReadUInt16Number | ( | ) |
References HasError().
Referenced by osmscout::AreaNodeIndex::Open().
uint32_t osmscout::FileScanner::ReadUInt32 | ( | ) |
References HasError().
Referenced by osmscout::TypeConfig::GetDatabaseFileFormatVersion(), osmscout::ObjectVariantDataFile::Load(), osmscout::TypeDistributionDataFile::Load(), osmscout::TypeConfig::LoadFromDataFile(), osmscout::CoordDataFile::Open(), osmscout::CoverageIndex::Open(), osmscout::AreaIndex::Open(), osmscout::OptimizeWaysLowZoom::Open(), osmscout::OptimizeAreasLowZoom::Open(), and osmscout::AreaNodeIndex::Open().
uint32_t osmscout::FileScanner::ReadUInt32 | ( | size_t | bytes | ) |
References HasError().
uint32_t osmscout::FileScanner::ReadUInt32Number | ( | ) |
References HasError().
Referenced by osmscout::AreaIndex::GetOffsets(), osmscout::TypeConfig::LoadFromDataFile(), osmscout::AreaIndex::Open(), osmscout::WaterIndex::Open(), osmscout::AreaAreaIndex::Open(), osmscout::ObjectVariantData::Read(), osmscout::Intersection::Read(), osmscout::TurnRestriction::Read(), osmscout::Route::Read(), osmscout::RouteNode::Read(), osmscout::PTRoute::Read(), osmscout::Area::Read(), osmscout::Area::ReadImport(), and osmscout::Area::ReadOptimized().
uint64_t osmscout::FileScanner::ReadUInt64 | ( | ) |
References HasError().
Referenced by osmscout::CoordDataFile::Open(), and osmscout::RouteNode::Read().
uint64_t osmscout::FileScanner::ReadUInt64 | ( | size_t | bytes | ) |
References HasError().
uint64_t osmscout::FileScanner::ReadUInt64Number | ( | ) |
uint8_t osmscout::FileScanner::ReadUInt8 | ( | ) |
References HasError().
Referenced by osmscout::CoordDataFile::Get(), osmscout::CoverageIndex::Open(), osmscout::AreaIndex::Open(), osmscout::WaterIndex::Open(), osmscout::AreaNodeIndex::Open(), osmscout::ObjectVariantData::Read(), osmscout::GradeFeatureValue::Read(), osmscout::MaxSpeedFeatureValue::Read(), osmscout::WidthFeatureValue::Read(), osmscout::AdminLevelFeatureValue::Read(), osmscout::ChargingStationFeatureValue::Read(), osmscout::FeeFeatureValue::Read(), osmscout::SidewayFeatureValue::Read(), osmscout::AccessRestrictedFeatureValue::Read(), osmscout::LanesFeatureValue::Read(), osmscout::RouteNode::Read(), osmscout::AccessFeatureValue::Read(), osmscout::PTRoute::Read(), Read(), osmscout::Area::Read(), osmscout::TypeInfo::Read(), osmscout::FeatureValueBuffer::Read(), osmscout::Area::ReadImport(), ReadObjectFileRef(), osmscout::Area::ReadOptimized(), and ReadTypeId().
void osmscout::FileScanner::SetPos | ( | FileOffset | pos | ) |
Moves the reading cursor to the given file position.
throws IOException on error
References HasError().
Referenced by osmscout::CoordDataFile::Get(), osmscout::AreaIndex::GetOffsets(), GotoBegin(), osmscout::CoordDataFile::Open(), osmscout::OptimizeWaysLowZoom::Open(), and osmscout::OptimizeAreasLowZoom::Open().