Refactoring base config class into proper ini file name

This commit is contained in:
Dennis Luxen 2013-08-06 17:23:40 +02:00
parent db7d4f56b3
commit b405029f0f
11 changed files with 12 additions and 103 deletions

View File

@ -35,7 +35,6 @@
#include "../DataStructures/QueryEdge.h"
#include "../DataStructures/Percent.h"
#include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
#include "../Util/LuaUtil.h"
#include <stxxl.h>

View File

@ -25,7 +25,7 @@ OSRM::OSRM(const char * server_ini_path) {
throw OSRMException("server.ini not found");
}
BaseConfiguration serverConfig(server_ini_path);
IniFile serverConfig(server_ini_path);
boost::filesystem::path base_path =
boost::filesystem::absolute(server_ini_path).parent_path();

View File

@ -30,7 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Plugins/TimestampPlugin.h"
#include "../Plugins/ViaRoutePlugin.h"
#include "../Plugins/RouteParameters.h"
#include "../Util/BaseConfiguration.h"
#include "../Util/IniFile.h"
#include "../Util/OSRMException.h"
#include "../Util/InputFileUtil.h"
#include "../Server/BasicDatastructures.h"

View File

@ -27,7 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Server.h"
#include "../Util/BaseConfiguration.h"
#include "../Util/IniFile.h"
#include "../Util/InputFileUtil.h"
#include "../Util/OpenMPWrapper.h"
#include "../Util/OSRMException.h"
@ -38,7 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <zlib.h>
struct ServerFactory {
static Server * CreateServer(BaseConfiguration& serverConfig) {
static Server * CreateServer(IniFile& serverConfig) {
if(!testDataFile(serverConfig.GetParameter("nodesData"))) {
throw OSRMException("nodes file not found");
@ -76,7 +76,7 @@ struct ServerFactory {
}
static Server * CreateServer(const char * iniFile) {
BaseConfiguration serverConfig(iniFile);
IniFile serverConfig(iniFile);
return CreateServer(serverConfig);
}
};

View File

@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../DataStructures/DynamicGraph.h"
#include "../DataStructures/QueryEdge.h"
#include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
#include "../Util/InputFileUtil.h"
#include "../Util/GraphLoader.h"
#include "../Util/OSRMException.h"
@ -40,7 +39,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
typedef QueryEdge::EdgeData EdgeData;
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
typedef BaseConfiguration ContractorConfiguration;
std::vector<NodeInfo> internal_to_external_node_map;
std::vector<_Restriction> restrictions_vector;

View File

@ -46,7 +46,7 @@ void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_
int main (int argc, char * argv[]) {
std::cout << "\n starting up engines, compile at "
<< __DATE__ << ", " __TIME__ << std::endl;
BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini"));
IniFile serverConfig((argc > 1 ? argv[1] : "server.ini"));
OSRM routing_machine((argc > 1 ? argv[1] : "server.ini"));
RouteParameters route_parameters;

View File

@ -1,88 +0,0 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef BASECONFIGURATION_H_
#define BASECONFIGURATION_H_
#include "OSRMException.h"
#include "../DataStructures/HashTable.h"
#include <boost/algorithm/string.hpp>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
class BaseConfiguration {
public:
BaseConfiguration(const char * configFile) {
std::ifstream config( configFile );
if(!config) {
throw OSRMException("[config] .ini not found");
}
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() )
parameters.insert(std::make_pair(tokens[0], tokens[1]));
}
config.close();
}
}
std::string GetParameter(const std::string & key){
return parameters.Find(key);
}
void SetParameter(const char* key, const char* value) {
SetParameter(std::string(key), std::string(value));
}
void SetParameter(const std::string key, std::string value) {
parameters[key] = value;
}
private:
void Tokenize(
const std::string& str,
std::vector<std::string>& tokens,
const std::string& delimiters = "="
) {
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
while (std::string::npos != pos || std::string::npos != lastPos) {
std::string temp = str.substr(lastPos, pos - lastPos);
boost::trim(temp);
tokens.push_back( temp );
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
}
HashTable<std::string, std::string> parameters;
};
#endif /* BASECONFIGURATION_H_ */

0
Util/IniFile.h Normal file
View File

View File

@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "DataStructures/QueryEdge.h"
#include "DataStructures/StaticGraph.h"
#include "DataStructures/StaticRTree.h"
#include "Util/BaseConfiguration.h"
#include "Util/IniFile.h"
#include "Util/GraphLoader.h"
#include "Util/InputFileUtil.h"
#include "Util/LuaUtil.h"
@ -49,7 +49,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
typedef QueryEdge::EdgeData EdgeData;
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
typedef BaseConfiguration ContractorConfiguration;
typedef IniFile ContractorConfiguration;
std::vector<NodeInfo> internalToExternalNodeMapping;
std::vector<_Restriction> inputRestrictions;

View File

@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Extractor/ScriptingEnvironment.h"
#include "Extractor/PBFParser.h"
#include "Extractor/XMLParser.h"
#include "Util/BaseConfiguration.h"
#include "Util/IniFile.h"
#include "Util/InputFileUtil.h"
#include "Util/MachineInfo.h"
#include "Util/OpenMPWrapper.h"
@ -59,7 +59,7 @@ int main (int argc, char *argv[]) {
unsigned number_of_threads = omp_get_num_procs();
if(testDataFile("extractor.ini")) {
BaseConfiguration extractorConfig("extractor.ini");
IniFile extractorConfig("extractor.ini");
INFO("2");
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
INFO("3");

View File

@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Server/ServerFactory.h"
#include "Util/BaseConfiguration.h"
#include "Util/IniFile.h"
#include "Util/InputFileUtil.h"
#include "Util/OpenMPWrapper.h"
#include "Util/UUID.h"
@ -91,7 +91,7 @@ int main (int argc, char * argv[]) {
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
#endif
BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini"));
IniFile serverConfig((argc > 1 ? argv[1] : "server.ini"));
OSRM routing_machine((argc > 1 ? argv[1] : "server.ini"));
Server * s = ServerFactory::CreateServer(serverConfig);