diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 18bee5de6..bbc3ad58e 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -434,8 +434,9 @@ public: p.printStatus(numberOfContractedNodes); } - BOOST_FOREACH(_ThreadData * data, threadData) + BOOST_FOREACH(_ThreadData * data, threadData) { delete data; + } threadData.clear(); } diff --git a/Contractor/TemporaryStorage.cpp b/Contractor/TemporaryStorage.cpp index dbd86e3e5..2f8691066 100644 --- a/Contractor/TemporaryStorage.cpp +++ b/Contractor/TemporaryStorage.cpp @@ -21,11 +21,7 @@ #include "TemporaryStorage.h" TemporaryStorage::TemporaryStorage() { - try { - tempDirectory = boost::filesystem::temp_directory_path(); - } catch(boost::filesystem::filesystem_error & e) { - ERR("could not retrieve location of temporary path: " << e.what()); - } + tempDirectory = boost::filesystem::temp_directory_path(); } TemporaryStorage & TemporaryStorage::GetInstance(){ @@ -39,12 +35,8 @@ TemporaryStorage::~TemporaryStorage() { void TemporaryStorage::removeAll() { boost::mutex::scoped_lock lock(mutex); - try { - for(unsigned slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID) - deallocateSlot(slotID); - - } catch(boost::filesystem::filesystem_error & e) { - ERR("could not retrieve location of temporary path: " << e.what()); + for(unsigned slot_id = 0; slot_id < vectorOfStreamDatas.size(); ++slot_id) { + deallocateSlot(slot_id); } vectorOfStreamDatas.clear(); } @@ -64,13 +56,13 @@ void TemporaryStorage::deallocateSlot(int slotID) { try { StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); - if(!boost::filesystem::exists(data.pathToTemporaryFile)) { + if(!boost::filesystem::exists(data.pathToTemporaryFile)) { return; } - if(data.streamToTemporaryFile->is_open()) + if(data.streamToTemporaryFile->is_open()) { data.streamToTemporaryFile->close(); + } - //INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile); boost::filesystem::remove(data.pathToTemporaryFile); } catch(boost::filesystem::filesystem_error & e) { abort(e); @@ -81,8 +73,10 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s try { StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); - if(!data.writeMode) - ERR("Writing after first read is not allowed"); + BOOST_ASSERT_MSG( + data.writeMode, + "Writing after first read is not allowed" + ); data.streamToTemporaryFile->write(pointer, size); } catch(boost::filesystem::filesystem_error & e) { abort(e); @@ -121,13 +115,11 @@ boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) { } catch(boost::filesystem::filesystem_error & e) { abort(e); } -// INFO("telling position: " << position); return position; } void TemporaryStorage::abort(boost::filesystem::filesystem_error& ) { removeAll(); -// ERR("I/O Error occured: " << e.what()); } void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) { @@ -135,7 +127,6 @@ void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type pos StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); data.streamToTemporaryFile->seekg(position); -// INFO("seeking to position: " << position); } catch(boost::filesystem::filesystem_error & e) { abort(e); } diff --git a/Contractor/TemporaryStorage.h b/Contractor/TemporaryStorage.h index 84004c71c..066d22de5 100644 --- a/Contractor/TemporaryStorage.h +++ b/Contractor/TemporaryStorage.h @@ -24,12 +24,14 @@ #include #include +#include #include #include #include #include #include +#include "../Util/OSRMException.h" #include "../typedefs.h" //This is one big workaround for latest boost renaming woes. @@ -102,8 +104,9 @@ private: streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)), readWriteMutex(new boost::mutex) { - if(streamToTemporaryFile->fail()) - ERR("Aborting, because temporary file at " << pathToTemporaryFile << " could not be created"); + if(streamToTemporaryFile->fail()) { + throw OSRMException("temporary file could not be created"); + } } }; //vector of file streams that is used to store temporary data diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 714560ccc..5da516b15 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EDGE_H #define EDGE_H + +#include "../Util/OSRMException.h" #include class NodeBasedEdge { @@ -40,8 +42,34 @@ public: return (source() < e.source()); } - explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar, bool cf) : - _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _contraFlow(cf) { if(ty < 0) {ERR("Type: " << ty);}; } + explicit NodeBasedEdge( + NodeID s, + NodeID t, + NodeID n, + EdgeWeight w, + bool f, + bool b, + short ty, + bool ra, + bool ig, + bool ar, + bool cf + ) : _source(s), + _target(t), + _name(n), + _weight(w), + forward(f), + backward(b), + _type(ty), + _roundabout(ra), + _ignoreInGrid(ig), + _accessRestricted(ar), + _contraFlow(cf) + { + if(ty < 0) { + throw OSRMException("negative edge type"); + } + } NodeID target() const {return _target; } NodeID source() const {return _source; } diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 48bad7879..4ec7ac1f3 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "PhantomNodes.h" #include "StaticRTree.h" #include "../Contractor/EdgeBasedGraphFactory.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include @@ -126,10 +127,14 @@ private: const std::string & nodes_file, const std::string & edges_file ) { - std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); - if(!nodes_input_stream) { ERR(nodes_file << " not found"); } - std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); - if(!edges_input_stream) { ERR(edges_file << " not found"); } + std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); + if(!nodes_input_stream) { + throw OSRMException("nodes file not found"); + } + std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); + if(!edges_input_stream) { + throw OSRMException("edges file not found"); + } DEBUG("Loading node data"); NodeInfo b; diff --git a/Extractor/BaseParser.cpp b/Extractor/BaseParser.cpp index 6981e9570..b5ba3e614 100644 --- a/Extractor/BaseParser.cpp +++ b/Extractor/BaseParser.cpp @@ -29,7 +29,9 @@ extractor_callbacks(ec), scriptingEnvironment(se), luaState(NULL), use_turn_rest void BaseParser::ReadUseRestrictionsSetting() { if( 0 != luaL_dostring( luaState, "return use_turn_restrictions\n") ) { - ERR(lua_tostring( luaState,-1)<< " occured in scripting block"); + throw OSRMException( + /*lua_tostring( luaState, -1 ) + */"ERROR occured in scripting block" + ); } if( lua_isboolean( luaState, -1) ) { use_turn_restrictions = lua_toboolean(luaState, -1); @@ -44,20 +46,14 @@ void BaseParser::ReadUseRestrictionsSetting() { void BaseParser::ReadRestrictionExceptions() { if(lua_function_exists(luaState, "get_exceptions" )) { //get list of turn restriction exceptions - try { - luabind::call_function( - luaState, - "get_exceptions", - boost::ref(restriction_exceptions) - ); - INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); - BOOST_FOREACH(std::string & str, restriction_exceptions) { - INFO(" " << str); - } - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); + luabind::call_function( + luaState, + "get_exceptions", + boost::ref(restriction_exceptions) + ); + INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); + BOOST_FOREACH(const std::string & str, restriction_exceptions) { + INFO(" " << str); } } else { INFO("Found no exceptions to turn restrictions"); @@ -72,37 +68,25 @@ void BaseParser::report_errors(lua_State *L, const int status) const { } void BaseParser::ParseNodeInLua(ImportNode& n, lua_State* localLuaState) { - try { - luabind::call_function( localLuaState, "node_function", boost::ref(n) ); - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); - } + luabind::call_function( localLuaState, "node_function", boost::ref(n) ); } void BaseParser::ParseWayInLua(ExtractionWay& w, lua_State* localLuaState) { if(2 > w.path.size()) { return; } - try { - luabind::call_function( localLuaState, "way_function", boost::ref(w) ); - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); - } + luabind::call_function( localLuaState, "way_function", boost::ref(w) ); } bool BaseParser::ShouldIgnoreRestriction(const std::string& except_tag_string) const { //should this restriction be ignored? yes if there's an overlap between: //a) the list of modes in the except tag of the restriction (except_tag_string), ex: except=bus;bicycle //b) the lua profile defines a hierachy of modes, ex: [access, vehicle, bicycle] - + if( "" == except_tag_string ) { return false; } - + //Be warned, this is quadratic work here, but we assume that //only a few exceptions are actually defined. std::vector exceptions; diff --git a/Extractor/BaseParser.h b/Extractor/BaseParser.h index 690f8a247..e65678fe4 100644 --- a/Extractor/BaseParser.h +++ b/Extractor/BaseParser.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorCallbacks.h" #include "ScriptingEnvironment.h" +#include "../Util/OSRMException.h" extern "C" { #include diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index 78c1b2a62..b2cc547d2 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -39,14 +39,10 @@ public: ExtractionContainers() { //Check if another instance of stxxl is already running or if there is a general problem - try { - stxxl::vector testForRunningInstance; - } catch(std::exception & e) { - ERR("Could not instantiate STXXL layer." << std::endl << e.what()); - } - + stxxl::vector testForRunningInstance; nameVector.push_back(""); } + virtual ~ExtractionContainers() { usedNodeIDs.clear(); allNodes.clear(); diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 51b099f98..1ce5a0231 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -28,7 +28,7 @@ PBFParser::PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnv input.open(fileName, std::ios::in | std::ios::binary); if (!input) { - std::cerr << fileName << ": File not found." << std::endl; + throw OSRMException("pbf file not found."); } #ifndef NDEBUG @@ -194,7 +194,9 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) { } inline void PBFParser::parseNode(_ThreadData * ) { - ERR("Parsing of simple nodes not supported. PBF should use dense nodes"); + throw OSRMException( + "Parsing of simple nodes not supported. PBF should use dense nodes" + ); } inline void PBFParser::parseRelation(_ThreadData * threadData) { @@ -475,7 +477,7 @@ bool PBFParser::readNextBlock(std::fstream& stream, _ThreadData * threadData) { } if ( !threadData->PBFprimitiveBlock.ParseFromArray( &(threadData->charBuffer[0]), threadData-> charBuffer.size() ) ) { - ERR("failed to parse PrimitiveBlock"); + std::cerr << "failed to parse PrimitiveBlock" << std::endl; return false; } return true; diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index a1606bb6f..18c28bed1 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -27,6 +27,7 @@ #include "../DataStructures/ConcurrentQueue.h" #include "../Util/MachineInfo.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 6bab21c5f..ab1cc8d00 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -40,59 +40,58 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { // Add our function to the state's global scope luabind::module(myLuaState) [ - luabind::def("print", LUA_print), - luabind::def("parseMaxspeed", parseMaxspeed), - luabind::def("durationIsValid", durationIsValid), - luabind::def("parseDuration", parseDuration) + luabind::def("print", LUA_print), + luabind::def("parseMaxspeed", parseMaxspeed), + luabind::def("durationIsValid", durationIsValid), + luabind::def("parseDuration", parseDuration) ]; luabind::module(myLuaState) [ - luabind::class_ >("keyVals") - .def("Add", &HashTable::Add) - .def("Find", &HashTable::Find) - .def("Holds", &HashTable::Holds) - ]; + luabind::class_ >("keyVals") + .def("Add", &HashTable::Add) + .def("Find", &HashTable::Find) + .def("Holds", &HashTable::Holds) + ]; luabind::module(myLuaState) [ - luabind::class_("Node") - .def(luabind::constructor<>()) - .def_readwrite("lat", &ImportNode::lat) - .def_readwrite("lon", &ImportNode::lon) - .def_readwrite("id", &ImportNode::id) - .def_readwrite("bollard", &ImportNode::bollard) - .def_readwrite("traffic_light", &ImportNode::trafficLight) - .def_readwrite("tags", &ImportNode::keyVals) - ]; + luabind::class_("Node") + .def(luabind::constructor<>()) + .def_readwrite("lat", &ImportNode::lat) + .def_readwrite("lon", &ImportNode::lon) + .def_readwrite("id", &ImportNode::id) + .def_readwrite("bollard", &ImportNode::bollard) + .def_readwrite("traffic_light", &ImportNode::trafficLight) + .def_readwrite("tags", &ImportNode::keyVals) + ]; luabind::module(myLuaState) [ - luabind::class_("Way") - .def(luabind::constructor<>()) - .def_readwrite("name", &ExtractionWay::name) - .def_readwrite("speed", &ExtractionWay::speed) - .def_readwrite("backward_speed", &ExtractionWay::backward_speed) - .def_readwrite("duration", &ExtractionWay::duration) - .def_readwrite("type", &ExtractionWay::type) - .def_readwrite("access", &ExtractionWay::access) - .def_readwrite("roundabout", &ExtractionWay::roundabout) - .def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted) - .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) - .def_readwrite("tags", &ExtractionWay::keyVals) - .def_readwrite("direction", &ExtractionWay::direction) - .enum_("constants") - [ - luabind::value("notSure", 0), - luabind::value("oneway", 1), - luabind::value("bidirectional", 2), - luabind::value("opposite", 3) - ] - ]; + luabind::class_("Way") + .def(luabind::constructor<>()) + .def_readwrite("name", &ExtractionWay::name) + .def_readwrite("speed", &ExtractionWay::speed) + .def_readwrite("backward_speed", &ExtractionWay::backward_speed) + .def_readwrite("duration", &ExtractionWay::duration) + .def_readwrite("type", &ExtractionWay::type) + .def_readwrite("access", &ExtractionWay::access) + .def_readwrite("roundabout", &ExtractionWay::roundabout) + .def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted) + .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) + .def_readwrite("tags", &ExtractionWay::keyVals) + .def_readwrite("direction", &ExtractionWay::direction) + .enum_("constants") [ + luabind::value("notSure", 0), + luabind::value("oneway", 1), + luabind::value("bidirectional", 2), + luabind::value("opposite", 3) + ] + ]; luabind::module(myLuaState) [ - luabind::class_ >("vector") - .def("Add", &std::vector::push_back) - ]; + luabind::class_ >("vector") + .def("Add", &std::vector::push_back) + ]; if(0 != luaL_dofile(myLuaState, fileName) ) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + throw OSRMException("ERROR occured in scripting block"); } } } diff --git a/Extractor/ScriptingEnvironment.h b/Extractor/ScriptingEnvironment.h index efb128100..315d84318 100644 --- a/Extractor/ScriptingEnvironment.h +++ b/Extractor/ScriptingEnvironment.h @@ -26,6 +26,7 @@ #include "../DataStructures/ImportNode.h" #include "../Util/LuaUtil.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include diff --git a/Library/OSRM.h b/Library/OSRM.h index 4f505f387..5f36211c8 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" #include "../Util/BaseConfiguration.h" +#include "../Util/OSRMException.h" #include "../Util/InputFileUtil.h" #include "../Server/BasicDatastructures.h" @@ -39,19 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include #include -class OSRMException: public std::exception { -public: - OSRMException(const char * message) : message(message) {} -private: - virtual const char* what() const throw() { - return message; - } - const char * message; -}; - class OSRM : boost::noncopyable { typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 69142434c..aa8956c1a 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -33,7 +33,9 @@ QueryObjectsStorage::QueryObjectsStorage( ) { INFO("loading graph data"); std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); - if(!hsgrInStream) { ERR(hsgrPath << " not found"); } + if(!hsgrInStream) { + throw OSRMException("hsgr not found"); + } //Deserialize road network graph std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrEdge> edgeList; @@ -79,7 +81,9 @@ QueryObjectsStorage::QueryObjectsStorage( //deserialize street name list INFO("Loading names index"); std::ifstream namesInStream(namesPath.c_str(), std::ios::binary); - if(!namesInStream) { ERR(namesPath << " not found"); } + if(!namesInStream) { + throw OSRMException("names file not found"); + } unsigned size(0); namesInStream.read((char *)&size, sizeof(unsigned)); diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index cd1b63b63..ebf4bef32 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include "../../Util/OSRMException.h" #include "../../DataStructures/NodeInformationHelpDesk.h" #include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index 160e5ac10..8101d78a3 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/BaseConfiguration.h" #include "../Util/InputFileUtil.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../Util/StringUtil.h" #include "../typedefs.h" @@ -40,31 +41,32 @@ struct ServerFactory { static Server * CreateServer(BaseConfiguration& serverConfig) { if(!testDataFile(serverConfig.GetParameter("nodesData"))) { - ERR("nodes file not found"); + throw OSRMException("nodes file not found"); } if(!testDataFile(serverConfig.GetParameter("hsgrData"))) { - ERR("hsgr file not found"); + throw OSRMException("hsgr file not found"); } if(!testDataFile(serverConfig.GetParameter("namesData"))) { - ERR("names file not found"); + throw OSRMException("names file not found"); } if(!testDataFile(serverConfig.GetParameter("ramIndex"))) { - ERR("ram index file not found"); + throw OSRMException("ram index file not found"); } if(!testDataFile(serverConfig.GetParameter("fileIndex"))) { - ERR("file index file not found"); + throw OSRMException("file index file not found"); } int threads = omp_get_num_procs(); - if(serverConfig.GetParameter("IP") == "") + if(serverConfig.GetParameter("IP") == "") { serverConfig.SetParameter("IP", "0.0.0.0"); - if(serverConfig.GetParameter("Port") == "") + } + if(serverConfig.GetParameter("Port") == "") { serverConfig.SetParameter("Port", "5000"); - + } if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads) threads = stringToInt( serverConfig.GetParameter("Threads") ); diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h index a998c6189..0ff634c82 100644 --- a/Util/BaseConfiguration.h +++ b/Util/BaseConfiguration.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASECONFIGURATION_H_ #define BASECONFIGURATION_H_ +#include "OSRMException.h" #include "../DataStructures/HashTable.h" #include @@ -33,26 +34,19 @@ public: BaseConfiguration(const char * configFile) { std::ifstream config( configFile ); if(!config) { - std::cerr << "[config] .ini not found" << std::endl; - return; + throw OSRMException("[config] .ini not found"); } std::string line; - try { - if (config.is_open()) { - while ( config.good() ) { - getline (config,line); - std::vector tokens; - Tokenize(line, tokens); - if(2 == tokens.size() ) - parameters.Add(tokens[0], tokens[1]); - } - config.close(); + if (config.is_open()) { + while ( config.good() ) { + getline (config,line); + std::vector tokens; + Tokenize(line, tokens); + if(2 == tokens.size() ) + parameters.Add(tokens[0], tokens[1]); } - } catch(std::exception& e) { - ERR("[config] " << configFile << " not found -> Exception: " < parameters; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index cd3e0cf7d..0e46db304 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef GRAPHLOADER_H #define GRAPHLOADER_H +#include "OSRMException.h" #include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportEdge.h" #include "../DataStructures/NodeCoords.h" @@ -308,19 +309,25 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s forward = false; } - if(length == 0) { ERR("loaded null length edge"); } + if(length == 0) { + throw OSRMException("loaded null length edge"); + } // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { - ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source); + throw OSRMException("unresolvable source Node ID"); } source = intNodeID->second; intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); } + if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { + throw OSRMException("unresolvable target Node ID"); + } target = intNodeID->second; - if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); } + if(source == UINT_MAX || target == UINT_MAX) { + throw OSRMException("nonexisting source or target" ); + } EdgeT inputEdge(source, target, 0, weight, forward, backward, type ); edgeList.push_back(inputEdge); @@ -351,8 +358,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s in >> source >> target >> weight >> dir; assert(weight > 0); - if(dir <0 || dir > 3) - ERR( "[error] direction bogus: " << dir ); + if(dir <0 || dir > 3) { + throw OSRMException( "[error] direction bogus"); + } assert(0<=dir && dir<=3); bool forward = true; @@ -361,7 +369,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s if (dir == 2) forward = false; if (dir == 3) {backward = true; forward = true;} - if(weight == 0) { ERR("loaded null length edge"); } + if(weight == 0) { + throw OSRMException("loaded null length edge"); + } if( nodeMap.find(source) == nodeMap.end()) { nodeMap.insert(std::make_pair(source, numberOfNodes )); @@ -395,7 +405,7 @@ unsigned readHSGRFromStream( WARN( ".hsgr was prepared with different build.\n" "Reprocess to get rid of this warning." - ) + ); } unsigned number_of_nodes = 0; diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 6945575f4..2b73b806c 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -165,12 +165,12 @@ inline bool StringStartsWith(const std::string & input, const std::string & pref // Function returns a 'random' filename in temporary directors. // May not be platform independent. -inline void GetTemporaryFileName(std::string & filename) { - char buffer[L_tmpnam]; - char * retPointer = tmpnam (buffer); - if(0 == retPointer) - ERR("Could not create temporary file name"); - filename = buffer; -} +// inline void GetTemporaryFileName(std::string & filename) { +// char buffer[L_tmpnam]; +// char * retPointer = tmpnam (buffer); +// if(0 == retPointer) { +// ERR("Could not create temporary file name"); +// filename = buffer; +// } #endif /* STRINGUTIL_H_ */ diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index 36726c4ae..8c2695525 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -61,35 +61,35 @@ const bool UUID::IsMagicNumberOK() const { const bool UUID::TestGraphUtil(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("hsgr input file misses magic number. Check or reprocess the file"); + throw OSRMException("hsgr input file misses magic number. Check or reprocess the file"); } return std::equal(md5_graph, md5_graph+32, other.md5_graph); } const bool UUID::TestPrepare(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("extracted input file misses magic number. Check or reprocess the file"); + throw OSRMException("extracted input file misses magic number. Check or reprocess the file"); } return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare); } const bool UUID::TestRTree(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("r-tree input file misses magic number. Check or reprocess the file"); + throw OSRMException("r-tree input file misses magic number. Check or reprocess the file"); } return std::equal(md5_tree, md5_tree+32, other.md5_tree); } const bool UUID::TestNodeInfo(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("nodes file misses magic number. Check or reprocess the file"); + throw OSRMException("nodes file misses magic number. Check or reprocess the file"); } return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo); } const bool UUID::TestQueryObjects(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("missing magic number. Check or reprocess the file"); + throw OSRMException("missing magic number. Check or reprocess the file"); } return std::equal(md5_objects, md5_objects+32, other.md5_objects); } diff --git a/Util/UUID.h b/Util/UUID.h index 188ab26a1..6647b9764 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef UUID_H #define UUID_H +#include "OSRMException.h" #include "../typedefs.h" #include diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 85cfea942..6dd0f3b86 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/InputFileUtil.h" #include "Util/LuaUtil.h" #include "Util/OpenMPWrapper.h" +#include "Util/OSRMException.h" #include "Util/StringUtil.h" #include "typedefs.h" @@ -59,7 +60,10 @@ std::vector edgeList; int main (int argc, char *argv[]) { try { if(argc < 3) { - ERR("usage: " << std::endl << argv[0] << " []"); + std::cerr << + "usage: \n" << + argv[0] << " []" << std::endl; + return -1; } double startupTime = get_timestamp(); @@ -75,7 +79,9 @@ int main (int argc, char *argv[]) { INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], std::ios::binary); if(!restrictionsInstream.good()) { - ERR("Could not access files"); + std::cerr << + "Could not access files" << std::endl; + } _Restriction restriction; UUID uuid_loaded, uuid_orig; @@ -85,7 +91,7 @@ int main (int argc, char *argv[]) { WARN( ".restrictions was prepared with different build.\n" "Reprocess to get rid of this warning." - ) + ); } restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); @@ -96,7 +102,7 @@ int main (int argc, char *argv[]) { std::ifstream in; in.open (argv[1], std::ifstream::in | std::ifstream::binary); if (!in.is_open()) { - ERR("Cannot open " << argv[1]); + throw OSRMException("Cannot open osrm input file"); } std::string nodeOut(argv[1]); nodeOut += ".nodes"; @@ -107,7 +113,7 @@ int main (int argc, char *argv[]) { /*** Setup Scripting Environment ***/ if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) { - ERR("Need profile.lua to apply traffic signal penalty"); + throw OSRMException("Cannot open profile.lua "); } // Create a new lua state @@ -125,18 +131,29 @@ int main (int argc, char *argv[]) { // Now call our function in a lua script INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") ); if(0 != luaL_dofile(myLuaState, (argc > 3 ? argv[3] : "profile.lua") )) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; } EdgeBasedGraphFactory::SpeedProfileProperties speedProfile; if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; + return -1; } speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1); if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; + return -1; } speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1); @@ -146,9 +163,13 @@ int main (int argc, char *argv[]) { NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions); in.close(); INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); - if(0 == edgeList.size()) - ERR("The input data is broken. It is impossible to do any turns in this graph"); - + if(0 == edgeList.size()) { + std::cerr << + "The input data is broken. " + "It is impossible to do any turns in this graph" << + std::endl; + return -1; + } /*** * Building an edge-expanded graph from node-based input an turn restrictions @@ -262,7 +283,13 @@ int main (int argc, char *argv[]) { currentEdge.data = contractedEdgeList[edge].data; if(currentEdge.data.distance <= 0) { INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); - ERR("Failed at edges of node " << node << " of " << numberOfNodes); + std::cerr << + "Failed at edges of node " << + node << + " of " << + numberOfNodes << + std::endl; + return -1; } //Serialize edges hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); @@ -278,8 +305,9 @@ int main (int argc, char *argv[]) { //cleanedEdgeList.clear(); _nodes.clear(); INFO("finished preprocessing"); - } catch (std::exception &e) { - ERR("Exception occured: " << e.what()); + } catch ( const std::exception &e ) { + std::cerr << "Exception occured: " << e.what() << std::endl; + return -1; } return 0; } diff --git a/extractor.cpp b/extractor.cpp index 5e580d8e7..221fb6a1e 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/InputFileUtil.h" #include "Util/MachineInfo.h" #include "Util/OpenMPWrapper.h" +#include "Util/OSRMException.h" #include "Util/StringUtil.h" #include "Util/UUID.h" #include "typedefs.h" @@ -45,7 +46,12 @@ int main (int argc, char *argv[]) { double startup_time = get_timestamp(); if(argc < 2) { - ERR("usage: \n" << argv[0] << " []"); + std::cerr << + "usage: \n" << + argv[0] << + " []" << + std::endl; + return -1; } /*** Setup Scripting Environment ***/ @@ -111,7 +117,7 @@ int main (int argc, char *argv[]) { } if(!parser->ReadHeader()) { - ERR("Parser not initialized!"); + throw OSRMException("Parser not initialized!"); } INFO("Parsing in progress.."); double parsing_start_time = get_timestamp(); @@ -128,11 +134,16 @@ int main (int argc, char *argv[]) { INFO("extraction finished after " << get_timestamp() - startup_time << "s"); - std::cout << "\nRun:\n" - << "./osrm-prepare " << output_file_name << " " << restrictionsFileName - << std::endl; - return 0; + std::cout << + "\nRun:\n" << + "./osrm-prepare " << + output_file_name << + " " << + restrictionsFileName << + std::endl; } catch(std::exception & e) { - WARN("unhandled exception: " << e.what()); + INFO("unhandled exception: " << e.what()); + return -1; } + return 0; }