diff --git a/include/engine/concepts.hpp b/include/engine/concepts.hpp new file mode 100644 index 0000000000..ed6da33360 --- /dev/null +++ b/include/engine/concepts.hpp @@ -0,0 +1,61 @@ +#ifndef OSRM_ENGINE_CONCEPTS_HPP +#define OSRM_ENGINE_CONCEPTS_HPP + +#include "engine/algorithm.hpp" +#include +#include + +namespace osrm::engine::routing_algorithms +{ + +/* + * RoutingAlgorithm concept + * ------------------------ + * This concept documents and checks the compile-time interface expected + * from the routing algorithm marker types used throughout the engine + * (e.g., routing_algorithms::ch::Algorithm and routing_algorithms::mld::Algorithm). + * + * Required compile-time/public interface (checked by this concept): + * - routing_algorithms::name() -> const char* + * - routing_algorithms::identifier() -> const char* + * - trait templates (instantiable): + * HasAlternativePathSearch + * HasShortestPathSearch + * HasDirectShortestPathSearch + * HasMapMatching + * HasManyToManySearch + * SupportsDistanceAnnotationType + * HasGetTileTurns + * HasExcludeFlags + * - the above trait specializations must expose a compile-time ::value convertible to bool + */ +template +concept RoutingAlgorithm = requires { + /* name() and identifier() are callable and return C strings */ + { name() } -> std::convertible_to; + { identifier() } -> std::convertible_to; + + /* trait templates are instantiable */ + typename HasAlternativePathSearch; + typename HasShortestPathSearch; + typename HasDirectShortestPathSearch; + typename HasMapMatching; + typename HasManyToManySearch; + typename SupportsDistanceAnnotationType; + typename HasGetTileTurns; + typename HasExcludeFlags; + + /* trait values are usable as compile-time booleans */ + { HasAlternativePathSearch::value } -> std::convertible_to; + { HasShortestPathSearch::value } -> std::convertible_to; + { HasDirectShortestPathSearch::value } -> std::convertible_to; + { HasMapMatching::value } -> std::convertible_to; + { HasManyToManySearch::value } -> std::convertible_to; + { SupportsDistanceAnnotationType::value } -> std::convertible_to; + { HasGetTileTurns::value } -> std::convertible_to; + { HasExcludeFlags::value } -> std::convertible_to; +}; + +} // namespace osrm::engine::routing_algorithms + +#endif // OSRM_ENGINE_CONCEPTS_HPP diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 9c21aa04d3..5c73c51484 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -38,7 +38,8 @@ class EngineInterface virtual Status Tile(const api::TileParameters ¶meters, api::ResultT &result) const = 0; }; -template class Engine final : public EngineInterface +template +class Engine final : public EngineInterface { public: explicit Engine(const EngineConfig &config) diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 9699f5d7a2..1c33caf1f8 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -2,6 +2,7 @@ #define OSRM_ENGINE_ROUTING_ALGORITHM_HPP #include "engine/algorithm.hpp" +#include "engine/concepts.hpp" #include "engine/internal_route_result.hpp" #include "engine/phantom_node.hpp" #include "engine/routing_algorithms/alternative_path.hpp" @@ -61,7 +62,8 @@ class RoutingAlgorithmsInterface }; // Short-lived object passed to each plugin in request to wrap routing algorithms -template class RoutingAlgorithms final : public RoutingAlgorithmsInterface +template +class RoutingAlgorithms final : public RoutingAlgorithmsInterface { public: RoutingAlgorithms(SearchEngineData &heaps, @@ -149,7 +151,7 @@ template class RoutingAlgorithms final : public RoutingAlgo std::shared_ptr> facade; }; -template +template InternalManyRoutesResult RoutingAlgorithms::AlternativePathSearch( const PhantomEndpointCandidates &endpoint_candidates, unsigned number_of_alternatives) const { @@ -157,7 +159,7 @@ InternalManyRoutesResult RoutingAlgorithms::AlternativePathSearch( heaps, *facade, endpoint_candidates, number_of_alternatives); } -template +template InternalRouteResult RoutingAlgorithms::ShortestPathSearch( const std::vector &waypoint_candidates, const std::optional continue_straight_at_waypoint) const @@ -166,14 +168,14 @@ InternalRouteResult RoutingAlgorithms::ShortestPathSearch( heaps, *facade, waypoint_candidates, continue_straight_at_waypoint); } -template +template InternalRouteResult RoutingAlgorithms::DirectShortestPathSearch( const PhantomEndpointCandidates &endpoint_candidates) const { return routing_algorithms::directShortestPathSearch(heaps, *facade, endpoint_candidates); } -template +template inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching( const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, @@ -190,7 +192,7 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatc allow_splitting); } -template +template std::pair, std::vector> RoutingAlgorithms::ManyToManySearch( const std::vector &candidates_list, @@ -222,7 +224,7 @@ RoutingAlgorithms::ManyToManySearch( calculate_distance); } -template +template inline std::vector RoutingAlgorithms::GetTileTurns( const std::vector &edges, const std::vector &sorted_edge_indexes) const diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index 253b9f98d7..f9057d183a 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -2,6 +2,7 @@ #define SEARCH_ENGINE_DATA_HPP #include "engine/algorithm.hpp" +#include "engine/concepts.hpp" #include "util/query_heap.hpp" #include "util/typedefs.hpp" @@ -14,7 +15,7 @@ namespace osrm::engine // - CH algorithms use CH heaps // - MLD algorithms use MLD heaps -template struct SearchEngineData +template struct SearchEngineData { };