From 5f90ed8b3edb9e7d44fd1fad4d78e8b1a5112a94 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 24 Sep 2013 21:50:20 +0200 Subject: [PATCH] support capitalized option names in extract/prepare --- Util/ProgramOptions.h | 11 +++++++++++ createHierarchy.cpp | 11 ++++++----- extractor.cpp | 10 ++++++---- features/testbot/graph.feature | 2 +- routed.cpp | 17 +++++------------ 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index a1e2d4c46..faba2dcc0 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -29,6 +29,7 @@ Custom validators for use with boost::program_options. #include #include #include +#include #include #include @@ -57,4 +58,14 @@ namespace boost { } } +//support old capitalized option names by downcasing them with a regex replace +//read from file and store in a stringstream that can be passed to boost::program_options +inline void PrepareConfigFile(const boost::filesystem::path& path, std::string& output ) { + std::ifstream config_stream(path.c_str()); + std::string input_str( (std::istreambuf_iterator(config_stream)), std::istreambuf_iterator() ); + boost::regex regex( "^([^=]*)" ); //match from start of line to '=' + std::string format( "\\L$1\\E" ); //replace with downcased substring + output = boost::regex_replace( input_str, regex, format ); +} + #endif /* PROGRAM_OPTIONS_H */ diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 13088effa..4db469b6e 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -80,7 +80,7 @@ int main (int argc, char *argv[]) { "Restrictions file in .osrm.restrictions format") ("profile,p", boost::program_options::value(&profile_path)->default_value("profile.lua"), "Path to LUA routing profile") - ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(10), + ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(8), "Number of threads to use"); // hidden options, will be allowed both on command line and in config file, but will not be shown to the user @@ -120,11 +120,12 @@ int main (int argc, char *argv[]) { boost::program_options::notify(option_variables); - // parse config file if(boost::filesystem::is_regular_file(config_file_path)) { - std::ifstream ifs(config_file_path.c_str()); - SimpleLogger().Write() << "Reading options from: " << config_file_path.filename().string(); - boost::program_options::store(parse_config_file(ifs, config_file_options), option_variables); + SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str(); + std::string config_str; + PrepareConfigFile( config_file_path.c_str(), config_str ); + std::stringstream config_stream( config_str ); + boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables); boost::program_options::notify(option_variables); } diff --git a/extractor.cpp b/extractor.cpp index 81f86695c..73c49ccc8 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -63,7 +63,7 @@ int main (int argc, char *argv[]) { config_options.add_options() ("profile,p", boost::program_options::value(&profile_path)->default_value("profile.lua"), "Path to LUA routing profile") - ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(10), + ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(8), "Number of threads to use"); // hidden options, will be allowed both on command line and in config file, but will not be shown to the user @@ -105,9 +105,11 @@ int main (int argc, char *argv[]) { // parse config file if(boost::filesystem::is_regular_file(config_file_path)) { - std::ifstream ifs(config_file_path.c_str()); - SimpleLogger().Write() << "Reading options from: " << config_file_path.filename().string(); - boost::program_options::store(parse_config_file(ifs, config_file_options), option_variables); + SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str(); + std::string config_str; + PrepareConfigFile( config_file_path.c_str(), config_str ); + std::stringstream config_stream( config_str ); + boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables); boost::program_options::notify(option_variables); } diff --git a/features/testbot/graph.feature b/features/testbot/graph.feature index 481d7ff38..a870106dc 100644 --- a/features/testbot/graph.feature +++ b/features/testbot/graph.feature @@ -1,6 +1,6 @@ @routing @graph Feature: Basic Routing -Test the input data descibed on https://github.com/DennisOSRM/Project-OSRM/wiki/Graph-representation +#Test the input data descibed on https://github.com/DennisOSRM/Project-OSRM/wiki/Graph-representation Background: Given the profile "testbot" diff --git a/routed.cpp b/routed.cpp index 40d9106bf..6f7b15fc2 100644 --- a/routed.cpp +++ b/routed.cpp @@ -40,7 +40,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include -#include #include @@ -109,7 +108,7 @@ int main (int argc, char * argv[]) { "IP address") ("port,p", boost::program_options::value(&ip_port)->default_value(5000), "IP Port") - ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(8), + ("threads,t", boost::program_options::value(&requested_num_threads)->default_value(8), "Number of threads to use"); // hidden options, will be allowed both on command line and in config file, but will not be shown to the user @@ -152,16 +151,10 @@ int main (int argc, char * argv[]) { // parse config file if(boost::filesystem::is_regular_file(paths["config"])) { SimpleLogger().Write() << "Reading options from: " << paths["config"].c_str(); - std::ifstream config_stream(paths["config"].c_str()); - std::string config_str( (std::istreambuf_iterator(config_stream)), std::istreambuf_iterator() ); - - //support old capitalized option names by downcasing them with a regex replace - boost::regex option_name_regex( "^([^=]*)" ); //match from start of line to '=' - std::string option_name_format( "\\L$1\\E" ); //replace with downcased substring - std::string modified_config_str = boost::regex_replace( config_str, option_name_regex, option_name_format ); - std::stringstream modified_stream(modified_config_str); - - boost::program_options::store(parse_config_file(modified_stream, config_file_options), option_variables); + std::string config_str; + PrepareConfigFile( paths["config"], config_str ); + std::stringstream config_stream( config_str ); + boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables); boost::program_options::notify(option_variables); }