|
1 | 1 | #include "server/service/table_service.hpp"
|
2 |
| -#include "server/service/utils.hpp" |
3 | 2 |
|
4 | 3 | #include "server/api/parameters_parser.hpp"
|
5 | 4 | #include "engine/api/table_parameters.hpp"
|
6 | 5 |
|
7 | 6 | #include "util/json_container.hpp"
|
8 | 7 |
|
| 8 | +#include <boost/format.hpp> |
| 9 | + |
9 | 10 | namespace osrm::server::service
|
10 | 11 | {
|
| 12 | + |
11 | 13 | namespace
|
12 | 14 | {
|
| 15 | + |
| 16 | +const constexpr char PARAMETER_SIZE_MISMATCH_MSG[] = |
| 17 | + "Number of elements in %1% size %2% does not match coordinate size %3%"; |
| 18 | + |
| 19 | +template <typename ParamT> |
| 20 | +bool constrainParamSize(const char *msg_template, |
| 21 | + const char *name, |
| 22 | + const ParamT ¶m, |
| 23 | + const std::size_t target_size, |
| 24 | + std::string &help) |
| 25 | +{ |
| 26 | + if (param.size() > 0 && param.size() != target_size) |
| 27 | + { |
| 28 | + help = (boost::format(msg_template) % name % param.size() % target_size).str(); |
| 29 | + return true; |
| 30 | + } |
| 31 | + return false; |
| 32 | +} |
| 33 | + |
13 | 34 | std::string getWrongOptionHelp(const engine::api::TableParameters ¶meters)
|
14 | 35 | {
|
15 | 36 | std::string help;
|
16 | 37 |
|
17 | 38 | const auto coord_size = parameters.coordinates.size();
|
18 |
| - const auto bearings_size = parameters.bearings.size(); |
19 |
| - |
20 |
| - const bool param_size_mismatch = constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, |
21 |
| - "hints", |
22 |
| - parameters.hints, |
23 |
| - "coordinates", |
24 |
| - coord_size, |
25 |
| - help) || |
26 |
| - constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, |
27 |
| - "bearings", |
28 |
| - parameters.bearings, |
29 |
| - "coordinates", |
30 |
| - coord_size, |
31 |
| - help) || |
32 |
| - constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, |
33 |
| - "radiuses", |
34 |
| - parameters.radiuses, |
35 |
| - "bearings", |
36 |
| - bearings_size, |
37 |
| - help) || |
38 |
| - constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, |
39 |
| - "radiuses", |
40 |
| - parameters.radiuses, |
41 |
| - "coordinates", |
42 |
| - coord_size, |
43 |
| - help) || |
44 |
| - constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, |
45 |
| - "approaches", |
46 |
| - parameters.approaches, |
47 |
| - "coordinates", |
48 |
| - coord_size, |
49 |
| - help); |
| 39 | + |
| 40 | + const bool param_size_mismatch = |
| 41 | + constrainParamSize( |
| 42 | + PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) || |
| 43 | + constrainParamSize( |
| 44 | + PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) || |
| 45 | + constrainParamSize( |
| 46 | + PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) || |
| 47 | + constrainParamSize( |
| 48 | + PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help); |
50 | 49 |
|
51 | 50 | if (!param_size_mismatch && parameters.coordinates.size() < 2)
|
52 | 51 | {
|
|
0 commit comments