This commit is contained in:
Dennis Luxen 2013-08-09 20:16:26 +02:00
parent a542292ce2
commit 0285bb6ea5
3 changed files with 22 additions and 11 deletions

View File

@ -22,7 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM::OSRM(const char * server_ini_path) {
if( !testDataFile(server_ini_path) ){
throw OSRMException("server.ini not found");
std::string error_message = std::string(server_ini_path) + " not found";
throw OSRMException(error_message.c_str());
}
IniFile serverConfig(server_ini_path);

View File

@ -25,29 +25,36 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../DataStructures/HashTable.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
class IniFile {
public:
IniFile(const char * configFile) {
std::ifstream config( configFile );
if(!config) {
std::string str = "[config] " + std::string(configFile) + " not found";
throw OSRMException(str.c_str());
IniFile(const char * config_filename) {
boost::filesystem::path config_file(config_filename);
if ( !boost::filesystem::exists( config_file ) ) {
std::string error = std::string(config_filename) + " not found";
throw OSRMException(error);
}
if ( 0 == boost::filesystem::file_size( config_file ) ) {
std::string error = std::string(config_filename) + " is empty";
throw OSRMException(error);
}
boost::filesystem::ifstream config( config_file );
std::string line;
if (config.is_open()) {
while ( config.good() ) {
getline (config,line);
std::vector<std::string> tokens;
Tokenize(line, tokens);
if(2 == tokens.size() )
if(2 == tokens.size() ) {
parameters.insert(std::make_pair(tokens[0], tokens[1]));
}
}
config.close();
}

View File

@ -22,15 +22,18 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define OSRM_EXCEPTION_H
#include <exception>
#include <string>
class OSRMException: public std::exception {
public:
OSRMException(const char * message) : message(message) {}
OSRMException(const std::string & message) : message(message) {}
virtual ~OSRMException() throw() {}
private:
virtual const char* what() const throw() {
return message;
return message.c_str();
}
const char * message;
const std::string message;
};
#endif /* OSRM_EXCEPTION_H */
#endif /* OSRM_EXCEPTION_H */