osrm-backend/include/engine/api/route_parameters.hpp

166 lines
6.2 KiB
C++
Raw Normal View History

/*
Copyright (c) 2016, Project OSRM contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
2016-01-28 10:28:44 -05:00
#ifndef ENGINE_API_ROUTE_PARAMETERS_HPP
#define ENGINE_API_ROUTE_PARAMETERS_HPP
#include "engine/api/base_parameters.hpp"
#include <vector>
namespace osrm
{
namespace engine
{
namespace api
{
2016-04-01 11:23:41 -04:00
/**
* Parameters specific to the OSRM Route service.
*
* Holds member attributes:
* - steps: return route step for each route leg
* - alternatives: tries to find alternative routes
* - geometries: route geometry encoded in Polyline, Polyline6 or GeoJSON
2016-04-01 11:23:41 -04:00
* - overview: adds overview geometry either Full, Simplified (according to highest zoom level) or
* False (not at all)
2016-04-12 12:47:00 -04:00
* - continue_straight: enable or disable continue_straight (disabled by default)
2016-04-01 11:23:41 -04:00
*
* \see OSRM, Coordinate, Hint, Bearing, RouteParame, RouteParameters, TableParameters,
* NearestParameters, TripParameters, MatchParameters and TileParameters
*/
2016-01-28 10:28:44 -05:00
struct RouteParameters : public BaseParameters
{
enum class GeometriesType
{
Polyline,
Polyline6,
2016-01-28 10:28:44 -05:00
GeoJSON
};
enum class OverviewType
{
Simplified,
Full,
False
};
2017-01-31 10:04:32 -05:00
enum class AnnotationsType
{
None = 0,
2017-01-31 10:04:32 -05:00
Duration = 0x01,
Nodes = 0x02,
2017-02-01 09:33:43 -05:00
Distance = 0x04,
Weight = 0x08,
Datasources = 0x10,
All = Duration | Nodes | Distance | Weight | Datasources
};
2016-01-28 10:28:44 -05:00
RouteParameters() = default;
template <typename... Args>
RouteParameters(const bool steps_,
const bool alternatives_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
2017-01-27 07:40:17 -05:00
annotations{false}, annotations_type{AnnotationsType::None}, geometries{geometries_},
overview{overview_}, continue_straight{continue_straight_}
// Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one below.
{
}
// RouteParameters constructor adding the `annotations` setting in a API-compatible way.
2016-03-03 08:26:13 -05:00
template <typename... Args>
2016-01-28 10:28:44 -05:00
RouteParameters(const bool steps_,
2016-03-08 16:58:17 -05:00
const bool alternatives_,
2016-05-26 15:29:15 -04:00
const bool annotations_,
2016-01-28 10:28:44 -05:00
const GeometriesType geometries_,
const OverviewType overview_,
2016-04-12 12:47:00 -04:00
const boost::optional<bool> continue_straight_,
2016-03-03 08:26:13 -05:00
Args... args_)
2016-03-08 16:58:17 -05:00
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
2017-01-27 07:40:17 -05:00
annotations{annotations_},
annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None},
geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_}
{
}
// enum based implementation of annotations parameter
template <typename... Args>
RouteParameters(const bool steps_,
const bool alternatives_,
const AnnotationsType annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
2017-02-02 10:36:35 -05:00
annotations_type{annotations_}, annotations{annotations_ == AnnotationsType::None ? false : true}, geometries{geometries_},
2017-01-27 07:40:17 -05:00
overview{overview_}, continue_straight{continue_straight_}
2016-01-28 10:28:44 -05:00
{
}
bool steps = false;
bool alternatives = false;
2016-05-26 15:29:15 -04:00
bool annotations = false;
AnnotationsType annotations_type = AnnotationsType::None;
2016-01-28 10:28:44 -05:00
GeometriesType geometries = GeometriesType::Polyline;
OverviewType overview = OverviewType::Simplified;
2016-04-12 12:47:00 -04:00
boost::optional<bool> continue_straight;
2016-01-28 10:28:44 -05:00
2016-04-01 11:23:41 -04:00
bool IsValid() const { return coordinates.size() >= 2 && BaseParameters::IsValid(); }
2016-01-28 10:28:44 -05:00
};
2017-01-27 07:40:17 -05:00
inline bool operator&(RouteParameters::AnnotationsType lhs,
RouteParameters::AnnotationsType rhs)
{
return static_cast<bool>(
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(lhs) &
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
}
2017-01-27 07:40:17 -05:00
inline RouteParameters::AnnotationsType operator|(RouteParameters::AnnotationsType lhs,
RouteParameters::AnnotationsType rhs)
{
return (RouteParameters::AnnotationsType)(
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(lhs) |
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
}
2017-02-02 10:36:35 -05:00
inline RouteParameters::AnnotationsType operator|=(RouteParameters::AnnotationsType lhs,
RouteParameters::AnnotationsType rhs)
{
return lhs = lhs | rhs;
}
2016-01-28 10:28:44 -05:00
}
}
}
#endif