Implements 34735b8aad (commitcomment-3828247)
This commit is contained in:
parent
a542292ce2
commit
0285bb6ea5
@ -22,7 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
OSRM::OSRM(const char * server_ini_path) {
|
OSRM::OSRM(const char * server_ini_path) {
|
||||||
if( !testDataFile(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);
|
IniFile serverConfig(server_ini_path);
|
||||||
|
@ -25,29 +25,36 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class IniFile {
|
class IniFile {
|
||||||
public:
|
public:
|
||||||
IniFile(const char * configFile) {
|
IniFile(const char * config_filename) {
|
||||||
std::ifstream config( configFile );
|
boost::filesystem::path config_file(config_filename);
|
||||||
if(!config) {
|
if ( !boost::filesystem::exists( config_file ) ) {
|
||||||
std::string str = "[config] " + std::string(configFile) + " not found";
|
std::string error = std::string(config_filename) + " not found";
|
||||||
throw OSRMException(str.c_str());
|
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;
|
std::string line;
|
||||||
if (config.is_open()) {
|
if (config.is_open()) {
|
||||||
while ( config.good() ) {
|
while ( config.good() ) {
|
||||||
getline (config,line);
|
getline (config,line);
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
Tokenize(line, tokens);
|
Tokenize(line, tokens);
|
||||||
if(2 == tokens.size() )
|
if(2 == tokens.size() ) {
|
||||||
parameters.insert(std::make_pair(tokens[0], tokens[1]));
|
parameters.insert(std::make_pair(tokens[0], tokens[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
config.close();
|
config.close();
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,18 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#define OSRM_EXCEPTION_H
|
#define OSRM_EXCEPTION_H
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class OSRMException: public std::exception {
|
class OSRMException: public std::exception {
|
||||||
public:
|
public:
|
||||||
OSRMException(const char * message) : message(message) {}
|
OSRMException(const char * message) : message(message) {}
|
||||||
|
OSRMException(const std::string & message) : message(message) {}
|
||||||
|
virtual ~OSRMException() throw() {}
|
||||||
private:
|
private:
|
||||||
virtual const char* what() const throw() {
|
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 */
|
||||||
|
Loading…
Reference in New Issue
Block a user