From 8a665bc04405a4f577713847e87422c5755680c7 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 31 Jan 2012 20:38:52 +0100 Subject: [PATCH] Fixes issue #73. --- DataStructures/PBFParser.h | 25 +++++++++++++------------ extractor.cpp | 11 ++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index efc435885..453bbd30e 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -358,7 +358,7 @@ private: } void loadBlock(_ThreadData * threadData) { - blockCount++; + ++blockCount; threadData->currentGroupID = 0; threadData->currentEntityID = 0; } @@ -380,14 +380,14 @@ private: if ( size > MAX_BLOB_HEADER_SIZE || size < 0 ) { return false; } - char *data = (char*)malloc(size); + char *data = new char[size]; stream.read(data, size*sizeof(data[0])); if ( !(threadData->PBFBlobHeader).ParseFromArray( data, size ) ){ - free(data); + delete[] data; return false; } - free(data); + delete[] data; return true; } @@ -487,25 +487,26 @@ private: return false; } - if ( !readPBFBlobHeader(stream, threadData) ) - return false; - - if ( threadData->PBFBlobHeader.type() != "OSMData" ) { - std::cerr << "[error] invalid block type, found" << threadData->PBFBlobHeader.type().data() << "instead of OSMData" << std::endl; + if ( !readPBFBlobHeader(stream, threadData) ){ return false; } - if ( !readBlob(stream, threadData) ) + if ( threadData->PBFBlobHeader.type() != "OSMData" ) { return false; + } + + if ( !readBlob(stream, threadData) ) { + return false; + } if ( !threadData->PBFprimitiveBlock.ParseFromArray( &(threadData->charBuffer[0]), threadData-> charBuffer.size() ) ) { - std::cerr << "[error] failed to parse PrimitiveBlock" << std::endl; + ERR("failed to parse PrimitiveBlock"); return false; } return true; } - static Endianness getMachineEndianness() { + Endianness getMachineEndianness() const { int i(1); char *p = (char *) &i; if (p[0] == 1) diff --git a/extractor.cpp b/extractor.cpp index cc5a129ba..f2f1f7df4 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -60,7 +60,7 @@ unsigned globalRestrictionCounter = 0; ExtractorCallbacks * extractCallBacks; bool nodeFunction(_Node n); -bool adressFunction(_Node n, HashTable keyVals); +bool adressFunction(_Node n, HashTable & keyVals); bool restrictionFunction(_RawRestrictionContainer r); bool wayFunction(_Way w); @@ -190,10 +190,9 @@ int main (int argc, char *argv[]) { parser = new XMLParser(argv[1]); } parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction, &adressFunction); - GUARANTEE(parser->Init(), "Parser not initialized!"); + if(!parser->Init()) + INFO("Parser not initialized!"); parser->Parse(); - DELETE(parser); - stringMap.clear(); try { // INFO("raw no. of names: " << externalMemory.nameVector.size()); @@ -485,7 +484,9 @@ int main (int argc, char *argv[]) { cerr << "Caught Execption:" << e.what() << endl; return false; } + DELETE(parser); + stringMap.clear(); delete extractCallBacks; cout << "[extractor] finished." << endl; return 0; @@ -496,7 +497,7 @@ bool nodeFunction(_Node n) { return true; } -bool adressFunction(_Node n, HashTable keyVals){ +bool adressFunction(_Node n, HashTable & keyVals){ extractCallBacks->adressFunction(n, keyVals); return true; }