use exceptions instead of hard abort
This commit is contained in:
+16
-20
@@ -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 <exception>
|
||||
@@ -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<std::string> 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<std::string> tokens;
|
||||
Tokenize(line, tokens);
|
||||
if(2 == tokens.size() )
|
||||
parameters.Add(tokens[0], tokens[1]);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
ERR("[config] " << configFile << " not found -> Exception: " <<e.what());
|
||||
if(config.is_open())
|
||||
config.close();
|
||||
config.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,18 +87,20 @@ private:
|
||||
|
||||
void TrimStringRight(std::string& str) {
|
||||
std::string::size_type pos = str.find_last_not_of(" ");
|
||||
if (pos != std::string::npos)
|
||||
if (pos != std::string::npos) {
|
||||
str.erase(pos+1);
|
||||
else
|
||||
} else {
|
||||
str.erase( str.begin() , str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
void TrimStringLeft(std::string& str) {
|
||||
std::string::size_type pos = str.find_first_not_of(" ");
|
||||
if (pos != std::string::npos)
|
||||
if (pos != std::string::npos) {
|
||||
str.erase(0, pos);
|
||||
else
|
||||
} else {
|
||||
str.erase( str.begin() , str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
HashTable<std::string, std::string> parameters;
|
||||
|
||||
+18
-8
@@ -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<EdgeT>& 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<EdgeT>& 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<EdgeT>& 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;
|
||||
|
||||
+7
-7
@@ -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_ */
|
||||
|
||||
+5
-5
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 <boost/noncopyable.hpp>
|
||||
|
||||
Reference in New Issue
Block a user