Allow -1.0 as unlimited for default_radius value (#6599)
This commit is contained in:
+29
-1
@@ -12,6 +12,7 @@
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/optional/optional_io.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -70,6 +71,33 @@ std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm)
|
||||
}
|
||||
} // namespace osrm::engine
|
||||
|
||||
// overload validate for the double type to allow "unlimited" as an input
|
||||
namespace boost
|
||||
{
|
||||
void validate(boost::any &v, const std::vector<std::string> &values, double *, double)
|
||||
{
|
||||
boost::program_options::validators::check_first_occurrence(v);
|
||||
const std::string &s = boost::program_options::validators::get_single_string(values);
|
||||
|
||||
if (s == "unlimited")
|
||||
{
|
||||
v = -1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
v = std::stod(s);
|
||||
}
|
||||
catch (const std::invalid_argument &)
|
||||
{
|
||||
throw boost::program_options::validation_error(
|
||||
boost::program_options::validation_error::invalid_option_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned generateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
@@ -149,7 +177,7 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
value<double>(&config.max_radius_map_matching)->default_value(-1.0),
|
||||
"Max. radius size supported in map matching query. Default: unlimited.") //
|
||||
("default-radius",
|
||||
value<boost::optional<double>>(&config.default_radius),
|
||||
value<boost::optional<double>>(&config.default_radius)->default_value(-1.0),
|
||||
"Default radius size for queries. Default: unlimited.");
|
||||
|
||||
// hidden options, will be allowed on command line, but will not be shown to the user
|
||||
|
||||
Reference in New Issue
Block a user