Fixes grammar includes and formats them
This commit is contained in:
parent
996a27dbd1
commit
9bb4a68599
@ -3,21 +3,12 @@
|
|||||||
|
|
||||||
#include "engine/api/base_parameters.hpp"
|
#include "engine/api/base_parameters.hpp"
|
||||||
|
|
||||||
#include "engine/polyline_compressor.hpp"
|
|
||||||
#include "engine/hint.hpp"
|
|
||||||
#include "engine/bearing.hpp"
|
#include "engine/bearing.hpp"
|
||||||
|
#include "engine/hint.hpp"
|
||||||
|
#include "engine/polyline_compressor.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_char_.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_int.hpp>
|
|
||||||
#include <boost/spirit/include/qi_real.hpp>
|
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
#include <boost/spirit/include/qi_attr_cast.hpp>
|
|
||||||
#include <boost/spirit/include/qi_operator.hpp>
|
|
||||||
#include <boost/spirit/include/qi_repeat.hpp>
|
|
||||||
#include <boost/spirit/include/qi_as_string.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -30,41 +21,42 @@ namespace api
|
|||||||
|
|
||||||
namespace qi = boost::spirit::qi;
|
namespace qi = boost::spirit::qi;
|
||||||
|
|
||||||
template <typename T, char... Fmt>
|
template <typename T, char... Fmt> struct no_trailing_dot_policy : qi::real_policies<T>
|
||||||
struct no_trailing_dot_policy : qi::real_policies<T> {
|
{
|
||||||
|
template <typename Iterator> static bool parse_dot(Iterator &first, Iterator const &last)
|
||||||
template <typename Iterator>
|
{
|
||||||
static bool parse_dot(Iterator& first, Iterator const& last) {
|
|
||||||
if (first == last || *first != '.')
|
if (first == last || *first != '.')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
static const constexpr char fmt[sizeof...(Fmt)] = {Fmt...};
|
static const constexpr char fmt[sizeof...(Fmt)] = {Fmt...};
|
||||||
|
|
||||||
if (first + sizeof(fmt) < last
|
if (first + sizeof(fmt) < last && std::equal(fmt, fmt + sizeof(fmt), first + 1u))
|
||||||
&& std::equal(fmt, fmt + sizeof(fmt), first + 1u))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
++first;
|
++first;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iterator>
|
template <typename Iterator> static bool parse_exp(Iterator &, const Iterator &)
|
||||||
static bool parse_exp(Iterator&, const Iterator&) {
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iterator, typename Attribute>
|
template <typename Iterator, typename Attribute>
|
||||||
static bool parse_exp_n(Iterator&, const Iterator&, Attribute&) {
|
static bool parse_exp_n(Iterator &, const Iterator &, Attribute &)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iterator, typename Attribute>
|
template <typename Iterator, typename Attribute>
|
||||||
static bool parse_nan(Iterator&, const Iterator&, Attribute&) {
|
static bool parse_nan(Iterator &, const Iterator &, Attribute &)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iterator, typename Attribute>
|
template <typename Iterator, typename Attribute>
|
||||||
static bool parse_inf(Iterator&, const Iterator&, Attribute&) {
|
static bool parse_inf(Iterator &, const Iterator &, Attribute &)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -79,35 +71,30 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<std::string::iterator>
|
|||||||
: BaseParametersGrammar::base_type(root_rule_), base_parameters(parameters_)
|
: BaseParametersGrammar::base_type(root_rule_), base_parameters(parameters_)
|
||||||
{
|
{
|
||||||
const auto add_bearing =
|
const auto add_bearing =
|
||||||
[this](boost::optional<boost::fusion::vector2<short, short>> bearing_range)
|
[this](boost::optional<boost::fusion::vector2<short, short>> bearing_range) {
|
||||||
{
|
boost::optional<engine::Bearing> bearing;
|
||||||
boost::optional<engine::Bearing> bearing;
|
if (bearing_range)
|
||||||
if (bearing_range)
|
{
|
||||||
{
|
bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range),
|
||||||
bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range),
|
boost::fusion::at_c<1>(*bearing_range)};
|
||||||
boost::fusion::at_c<1>(*bearing_range)};
|
}
|
||||||
}
|
base_parameters.bearings.push_back(std::move(bearing));
|
||||||
base_parameters.bearings.push_back(std::move(bearing));
|
};
|
||||||
};
|
const auto set_radiuses = [this](RadiusesT radiuses) {
|
||||||
const auto set_radiuses = [this](RadiusesT radiuses)
|
|
||||||
{
|
|
||||||
base_parameters.radiuses = std::move(radiuses);
|
base_parameters.radiuses = std::move(radiuses);
|
||||||
};
|
};
|
||||||
const auto add_hint = [this](const std::string &hint_string)
|
const auto add_hint = [this](const std::string &hint_string) {
|
||||||
{
|
|
||||||
if (hint_string.size() > 0)
|
if (hint_string.size() > 0)
|
||||||
{
|
{
|
||||||
base_parameters.hints.push_back(engine::Hint::FromBase64(hint_string));
|
base_parameters.hints.push_back(engine::Hint::FromBase64(hint_string));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto add_coordinate = [this](const boost::fusion::vector<double, double> &lonLat)
|
const auto add_coordinate = [this](const boost::fusion::vector<double, double> &lonLat) {
|
||||||
{
|
|
||||||
base_parameters.coordinates.emplace_back(util::Coordinate(
|
base_parameters.coordinates.emplace_back(util::Coordinate(
|
||||||
util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION),
|
util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION),
|
||||||
util::FixedLatitude(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION)));
|
util::FixedLatitude(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION)));
|
||||||
};
|
};
|
||||||
const auto polyline_to_coordinates = [this](const std::string &polyline)
|
const auto polyline_to_coordinates = [this](const std::string &polyline) {
|
||||||
{
|
|
||||||
base_parameters.coordinates = engine::decodePolyline(polyline);
|
base_parameters.coordinates = engine::decodePolyline(polyline);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,8 +108,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<std::string::iterator>
|
|||||||
qi::as_string[qi::repeat(engine::ENCODED_HINT_SIZE)[base64_char]][add_hint] % ";";
|
qi::as_string[qi::repeat(engine::ENCODED_HINT_SIZE)[base64_char]][add_hint] % ";";
|
||||||
bearings_rule =
|
bearings_rule =
|
||||||
qi::lit("bearings=") >> (-(qi::short_ >> ',' >> qi::short_))[add_bearing] % ";";
|
qi::lit("bearings=") >> (-(qi::short_ >> ',' >> qi::short_))[add_bearing] % ";";
|
||||||
polyline_rule = qi::as_string[qi::lit("polyline(") >> +polyline_chars >>
|
polyline_rule = qi::as_string[qi::lit("polyline(") >> +polyline_chars >> qi::lit(")")]
|
||||||
qi::lit(")")][polyline_to_coordinates];
|
[polyline_to_coordinates];
|
||||||
location_rule = (double_ >> qi::lit(',') >> double_)[add_coordinate];
|
location_rule = (double_ >> qi::lit(',') >> double_)[add_coordinate];
|
||||||
query_rule = (location_rule % ';') | polyline_rule;
|
query_rule = (location_rule % ';') | polyline_rule;
|
||||||
|
|
||||||
|
@ -2,16 +2,10 @@
|
|||||||
#define MATCH_PARAMETERS_GRAMMAR_HPP
|
#define MATCH_PARAMETERS_GRAMMAR_HPP
|
||||||
|
|
||||||
#include "engine/api/match_parameters.hpp"
|
#include "engine/api/match_parameters.hpp"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
|
||||||
#include "server/api/base_parameters_grammar.hpp"
|
#include "server/api/base_parameters_grammar.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_bool.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
#include <boost/spirit/include/qi_uint.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -62,7 +56,8 @@ struct MatchParametersGrammar final : public BaseParametersGrammar
|
|||||||
timestamps_rule = qi::lit("timestamps=") >> qi::uint_ % ";";
|
timestamps_rule = qi::lit("timestamps=") >> qi::uint_ % ";";
|
||||||
match_rule = steps_rule[set_steps] | geometries_rule | overview_rule |
|
match_rule = steps_rule[set_steps] | geometries_rule | overview_rule |
|
||||||
timestamps_rule[set_timestamps];
|
timestamps_rule[set_timestamps];
|
||||||
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (match_rule | base_rule) % '&');
|
root_rule =
|
||||||
|
query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (match_rule | base_rule) % '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::api::MatchParameters parameters;
|
engine::api::MatchParameters parameters;
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
#define NEAREST_PARAMETERS_GRAMMAR_HPP
|
#define NEAREST_PARAMETERS_GRAMMAR_HPP
|
||||||
|
|
||||||
#include "engine/api/nearest_parameters.hpp"
|
#include "engine/api/nearest_parameters.hpp"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
|
||||||
#include "server/api/base_parameters_grammar.hpp"
|
#include "server/api/base_parameters_grammar.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
#include <boost/spirit/include/qi_uint.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -31,7 +26,8 @@ struct NearestParametersGrammar final : public BaseParametersGrammar
|
|||||||
parameters.number_of_results = number;
|
parameters.number_of_results = number;
|
||||||
};
|
};
|
||||||
nearest_rule = (qi::lit("number=") >> qi::uint_)[set_number];
|
nearest_rule = (qi::lit("number=") >> qi::uint_)[set_number];
|
||||||
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (nearest_rule | base_rule) % '&');
|
root_rule =
|
||||||
|
query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (nearest_rule | base_rule) % '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::api::NearestParameters parameters;
|
engine::api::NearestParameters parameters;
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
#define ROUTE_PARAMETERS_GRAMMAR_HPP
|
#define ROUTE_PARAMETERS_GRAMMAR_HPP
|
||||||
|
|
||||||
#include "engine/api/route_parameters.hpp"
|
#include "engine/api/route_parameters.hpp"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
|
||||||
#include "server/api/base_parameters_grammar.hpp"
|
#include "server/api/base_parameters_grammar.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_bool.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -65,7 +60,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar
|
|||||||
route_rule = steps_rule[set_steps] | alternatives_rule[set_alternatives] | geometries_rule |
|
route_rule = steps_rule[set_steps] | alternatives_rule[set_alternatives] | geometries_rule |
|
||||||
overview_rule | uturns_rule;
|
overview_rule | uturns_rule;
|
||||||
|
|
||||||
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (route_rule | base_rule) % '&');
|
root_rule =
|
||||||
|
query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (route_rule | base_rule) % '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::api::RouteParameters parameters;
|
engine::api::RouteParameters parameters;
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
#define TABLE_PARAMETERS_GRAMMAR_HPP
|
#define TABLE_PARAMETERS_GRAMMAR_HPP
|
||||||
|
|
||||||
#include "engine/api/table_parameters.hpp"
|
#include "engine/api/table_parameters.hpp"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
|
||||||
#include "server/api/base_parameters_grammar.hpp"
|
#include "server/api/base_parameters_grammar.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
#include <boost/spirit/include/qi_uint.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -41,7 +36,8 @@ struct TableParametersGrammar final : public BaseParametersGrammar
|
|||||||
(qi::lit("sources=") >> (qi::ulong_ % ";")[set_sources]) | qi::lit("sources=all");
|
(qi::lit("sources=") >> (qi::ulong_ % ";")[set_sources]) | qi::lit("sources=all");
|
||||||
table_rule = destinations_rule | sources_rule;
|
table_rule = destinations_rule | sources_rule;
|
||||||
|
|
||||||
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (table_rule | base_rule) % '&');
|
root_rule =
|
||||||
|
query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (table_rule | base_rule) % '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::api::TableParameters parameters;
|
engine::api::TableParameters parameters;
|
||||||
|
@ -3,14 +3,11 @@
|
|||||||
|
|
||||||
#include "engine/api/tile_parameters.hpp"
|
#include "engine/api/tile_parameters.hpp"
|
||||||
|
|
||||||
#include "engine/polyline_compressor.hpp"
|
|
||||||
#include "engine/hint.hpp"
|
#include "engine/hint.hpp"
|
||||||
|
#include "engine/polyline_compressor.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_uint.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
|
||||||
#include <boost/spirit/include/qi_operator.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -28,18 +25,9 @@ struct TileParametersGrammar final : boost::spirit::qi::grammar<std::string::ite
|
|||||||
|
|
||||||
TileParametersGrammar() : TileParametersGrammar::base_type(root_rule)
|
TileParametersGrammar() : TileParametersGrammar::base_type(root_rule)
|
||||||
{
|
{
|
||||||
const auto set_x = [this](const unsigned x_)
|
const auto set_x = [this](const unsigned x_) { parameters.x = x_; };
|
||||||
{
|
const auto set_y = [this](const unsigned y_) { parameters.y = y_; };
|
||||||
parameters.x = x_;
|
const auto set_z = [this](const unsigned z_) { parameters.z = z_; };
|
||||||
};
|
|
||||||
const auto set_y = [this](const unsigned y_)
|
|
||||||
{
|
|
||||||
parameters.y = y_;
|
|
||||||
};
|
|
||||||
const auto set_z = [this](const unsigned z_)
|
|
||||||
{
|
|
||||||
parameters.z = z_;
|
|
||||||
};
|
|
||||||
|
|
||||||
query_rule = qi::lit("tile(") >> qi::uint_[set_x] >> qi::lit(",") >> qi::uint_[set_y] >>
|
query_rule = qi::lit("tile(") >> qi::uint_[set_x] >> qi::lit(",") >> qi::uint_[set_y] >>
|
||||||
qi::lit(",") >> qi::uint_[set_z] >> qi::lit(")");
|
qi::lit(",") >> qi::uint_[set_z] >> qi::lit(")");
|
||||||
|
@ -2,16 +2,10 @@
|
|||||||
#define TRIP_PARAMETERS_GRAMMAR_HPP
|
#define TRIP_PARAMETERS_GRAMMAR_HPP
|
||||||
|
|
||||||
#include "engine/api/trip_parameters.hpp"
|
#include "engine/api/trip_parameters.hpp"
|
||||||
|
|
||||||
//#define BOOST_SPIRIT_DEBUG
|
|
||||||
#include "server/api/base_parameters_grammar.hpp"
|
#include "server/api/base_parameters_grammar.hpp"
|
||||||
|
|
||||||
#include <boost/spirit/include/qi_action.hpp>
|
//#define BOOST_SPIRIT_DEBUG
|
||||||
#include <boost/spirit/include/qi_bool.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/qi_grammar.hpp>
|
|
||||||
#include <boost/spirit/include/qi_lit.hpp>
|
|
||||||
#include <boost/spirit/include/qi_optional.hpp>
|
|
||||||
#include <boost/spirit/include/qi_uint.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -57,7 +51,8 @@ struct TripParametersGrammar final : public BaseParametersGrammar
|
|||||||
qi::lit("overview=false")[set_false_type];
|
qi::lit("overview=false")[set_false_type];
|
||||||
trip_rule = steps_rule[set_steps] | geometries_rule | overview_rule;
|
trip_rule = steps_rule[set_steps] | geometries_rule | overview_rule;
|
||||||
|
|
||||||
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (trip_rule | base_rule) % '&');
|
root_rule =
|
||||||
|
query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (trip_rule | base_rule) % '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::api::TripParameters parameters;
|
engine::api::TripParameters parameters;
|
||||||
|
Loading…
Reference in New Issue
Block a user