From b405029f0f495e8a9fedfe4fa1def5efb7e5224a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 17:23:40 +0200 Subject: [PATCH] Refactoring base config class into proper ini file name --- Contractor/EdgeBasedGraphFactory.h | 1 - Library/OSRM.cpp | 2 +- Library/OSRM.h | 2 +- Server/ServerFactory.h | 6 +- Tools/componentAnalysis.cpp | 2 - Tools/simpleclient.cpp | 2 +- Util/BaseConfiguration.h | 88 ------------------------------ Util/IniFile.h | 0 createHierarchy.cpp | 4 +- extractor.cpp | 4 +- routed.cpp | 4 +- 11 files changed, 12 insertions(+), 103 deletions(-) delete mode 100644 Util/BaseConfiguration.h create mode 100644 Util/IniFile.h diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 7949af6ff..d23f93549 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -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 diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 2da379901..f0937c988 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -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(); diff --git a/Library/OSRM.h b/Library/OSRM.h index 5f36211c8..a879a1223 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -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" diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index 8101d78a3..a41253105 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -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 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); } }; diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index af9e76c75..b38d980fa 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -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::InputEdge InputEdge; -typedef BaseConfiguration ContractorConfiguration; std::vector internal_to_external_node_map; std::vector<_Restriction> restrictions_vector; diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index 74aa8c8f3..361bbce4b 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -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; diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h deleted file mode 100644 index 8a3d95907..000000000 --- a/Util/BaseConfiguration.h +++ /dev/null @@ -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 - -#include -#include -#include -#include - -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 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& 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 parameters; -}; - -#endif /* BASECONFIGURATION_H_ */ diff --git a/Util/IniFile.h b/Util/IniFile.h new file mode 100644 index 000000000..e69de29bb diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 6dd0f3b86..035cba63a 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -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::InputEdge InputEdge; typedef StaticGraph::InputEdge StaticEdge; -typedef BaseConfiguration ContractorConfiguration; +typedef IniFile ContractorConfiguration; std::vector internalToExternalNodeMapping; std::vector<_Restriction> inputRestrictions; diff --git a/extractor.cpp b/extractor.cpp index 773914c03..182545029 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -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"); diff --git a/routed.cpp b/routed.cpp index 1f4e43550..bd916266a 100644 --- a/routed.cpp +++ b/routed.cpp @@ -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);