support capitalized option names in extract/prepare
This commit is contained in:
parent
644fad8355
commit
5f90ed8b3e
@ -29,6 +29,7 @@ Custom validators for use with boost::program_options.
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -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<char>(config_stream)), std::istreambuf_iterator<char>() );
|
||||
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 */
|
||||
|
@ -80,7 +80,7 @@ int main (int argc, char *argv[]) {
|
||||
"Restrictions file in .osrm.restrictions format")
|
||||
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")
|
||||
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(10),
|
||||
("threads,t", boost::program_options::value<int>(&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);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ int main (int argc, char *argv[]) {
|
||||
config_options.add_options()
|
||||
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")
|
||||
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(10),
|
||||
("threads,t", boost::program_options::value<int>(&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);
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
15
routed.cpp
15
routed.cpp
@ -40,7 +40,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -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<char>(config_stream)), std::istreambuf_iterator<char>() );
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user