diff --git a/DataStructures/coordinate.cpp b/DataStructures/coordinate.cpp index 4305256ef..0b76a4306 100644 --- a/DataStructures/coordinate.cpp +++ b/DataStructures/coordinate.cpp @@ -25,7 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "../Util/MercatorUtil.h" #ifndef NDEBUG #include "../Util/simple_logger.hpp" @@ -34,6 +33,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + #ifndef NDEBUG #include #endif diff --git a/Include/osrm/coordinate.hpp b/Include/osrm/coordinate.hpp index baac61f94..3229f256f 100644 --- a/Include/osrm/coordinate.hpp +++ b/Include/osrm/coordinate.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef FIXED_POINT_COORDINATE_H_ -#define FIXED_POINT_COORDINATE_H_ +#ifndef COORDINATE_HPP_ +#define COORDINATE_HPP_ #include //for std::ostream #include @@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace { -constexpr float COORDINATE_PRECISION = 1000000.f; +constexpr static const float COORDINATE_PRECISION = 1000000.f; } struct FixedPointCoordinate { @@ -110,4 +110,4 @@ inline std::ostream &operator<<(std::ostream &out_stream, FixedPointCoordinate c return out_stream; } -#endif /* FIXED_POINT_COORDINATE_H_ */ +#endif /* COORDINATE_HPP_ */ diff --git a/Include/osrm/route_parameters.hpp b/Include/osrm/route_parameters.hpp index fd570a1ef..0a450d571 100644 --- a/Include/osrm/route_parameters.hpp +++ b/Include/osrm/route_parameters.hpp @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ROUTE_PARAMETERS_H #define ROUTE_PARAMETERS_H -#include +#include #include @@ -40,7 +40,7 @@ struct RouteParameters RouteParameters(); void setZoomLevel(const short level); - + void setNumberOfResults(const short number); void setAlternateRouteFlag(const bool flag); diff --git a/Library/OSRM.h b/Library/OSRM.h index 372e82c39..cfa84ae27 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OSRM_H #define OSRM_H -#include +#include #include diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 40fef682c..991a57f51 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -44,6 +44,8 @@ namespace boost { namespace interprocess { class named_mutex; } } #include "../Server/DataStructures/InternalDataFacade.h" #include "../Server/DataStructures/SharedBarriers.h" #include "../Server/DataStructures/SharedDataFacade.h" +//TODO: remove +#include "../Server/Http/Reply.h" #include "../Util/make_unique.hpp" #include "../Util/ProgramOptions.h" #include "../Util/simple_logger.hpp" @@ -52,6 +54,9 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include +#include +#include + #include #include #include diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index e8b47df56..b7d4bfed7 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -32,7 +32,7 @@ class BasePlugin; namespace http { class Reply; } struct RouteParameters; -#include +#include #include "../data_structures/query_edge.hpp" diff --git a/Server/Connection.h b/Server/Connection.h index 41b06d3a2..54e4e6305 100644 --- a/Server/Connection.h +++ b/Server/Connection.h @@ -30,10 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // #include "RequestParser.h" #include "Http/CompressionType.h" +#include "Http/Reply.h" #include "Http/Request.h" -#include - #include #include #include diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 3ea391cab..9ba454f19 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -39,7 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../Util/string_util.hpp" #include "../../typedefs.h" -#include +#include #include diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index d4f715c61..15927c785 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -43,8 +43,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../Util/graph_loader.hpp" #include "../../Util/simple_logger.hpp" -#include -#include +#include +#include template class InternalDataFacade : public BaseDataFacade { diff --git a/Server/Http/Reply.cpp b/Server/Http/Reply.cpp index e2cf0aecf..a03bf38e9 100644 --- a/Server/Http/Reply.cpp +++ b/Server/Http/Reply.cpp @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "Reply.h" #include "../../Util/cast.hpp" diff --git a/Server/RequestHandler.cpp b/Server/RequestHandler.cpp index b1178ba2b..50449d561 100644 --- a/Server/RequestHandler.cpp +++ b/Server/RequestHandler.cpp @@ -28,17 +28,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "RequestHandler.h" #include "APIGrammar.h" +#include "Http/Reply.h" #include "Http/Request.h" -#include "../data_structures/json_container.hpp" #include "../Library/OSRM.h" #include "../Util/json_renderer.hpp" #include "../Util/simple_logger.hpp" #include "../Util/string_util.hpp" #include "../typedefs.h" -#include -#include +#include +#include #include diff --git a/Server/RequestParser.h b/Server/RequestParser.h index 7f302a257..07cdd86da 100644 --- a/Server/RequestParser.h +++ b/Server/RequestParser.h @@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define REQUEST_PARSER_H #include "Http/CompressionType.h" -#include +#include "Http/Header.h" #include #include diff --git a/UnitTests/Algorithms/DouglasPeuckerTest.cpp b/UnitTests/Algorithms/DouglasPeuckerTest.cpp index 27818e596..93e2aee8e 100644 --- a/UnitTests/Algorithms/DouglasPeuckerTest.cpp +++ b/UnitTests/Algorithms/DouglasPeuckerTest.cpp @@ -27,12 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../algorithms/douglas_peucker.hpp" #include "../../data_structures/segment_information.hpp" -#include "../../Include/osrm/Coordinate.h" #include #include #include +#include + #include BOOST_AUTO_TEST_SUITE(douglas_peucker) diff --git a/UnitTests/data_structures/StaticRTreeTest.cpp b/UnitTests/data_structures/StaticRTreeTest.cpp index cf3dfd0b2..25e4cea51 100644 --- a/UnitTests/data_structures/StaticRTreeTest.cpp +++ b/UnitTests/data_structures/StaticRTreeTest.cpp @@ -31,12 +31,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../Util/floating_point.hpp" #include "../../typedefs.h" -#include - #include #include #include +#include + #include #include diff --git a/Util/DataStoreOptions.h b/Util/DataStoreOptions.h index 389c7231a..0ad3222fc 100644 --- a/Util/DataStoreOptions.h +++ b/Util/DataStoreOptions.h @@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "osrm_exception.hpp" #include "simple_logger.hpp" -#include +#include #include #include diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 3329b3108..185edb0f0 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -33,11 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "osrm_exception.hpp" #include "simple_logger.hpp" -#include - #include #include +#include + #include #include diff --git a/Util/compute_angle.cpp b/Util/compute_angle.cpp index b6350e445..bba4773e2 100644 --- a/Util/compute_angle.cpp +++ b/Util/compute_angle.cpp @@ -29,7 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "TrigonometryTables.h" #include "../Util/MercatorUtil.h" -#include + +#include #include diff --git a/Util/json_renderer.hpp b/Util/json_renderer.hpp index dd6089c8e..a5fc239bb 100644 --- a/Util/json_renderer.hpp +++ b/Util/json_renderer.hpp @@ -31,9 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef JSON_RENDERER_HPP #define JSON_RENDERER_HPP -#include "../data_structures/json_container.hpp" #include "cast.hpp" +#include + namespace JSON { struct Renderer : mapbox::util::static_visitor<> diff --git a/Util/xml_renderer.hpp b/Util/xml_renderer.hpp index 46e050115..4f08cddbe 100644 --- a/Util/xml_renderer.hpp +++ b/Util/xml_renderer.hpp @@ -28,9 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef XML_RENDERER_HPP #define XML_RENDERER_HPP -#include "../data_structures/json_container.hpp" #include "cast.hpp" +#include + namespace JSON { struct XMLToArrayRenderer : mapbox::util::static_visitor<> diff --git a/algorithms/douglas_peucker.cpp b/algorithms/douglas_peucker.cpp index 362f0a5a8..bb8da99b2 100644 --- a/algorithms/douglas_peucker.cpp +++ b/algorithms/douglas_peucker.cpp @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/segment_information.hpp" #include "../Util/integer_range.hpp" -#include +#include #include diff --git a/algorithms/polyline_compressor.cpp b/algorithms/polyline_compressor.cpp index 2f2972b15..7886de91c 100644 --- a/algorithms/polyline_compressor.cpp +++ b/algorithms/polyline_compressor.cpp @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "polyline_compressor.hpp" #include "../data_structures/segment_information.hpp" -#include +#include std::string PolylineCompressor::encode_vector(std::vector &numbers) const { diff --git a/algorithms/polyline_formatter.cpp b/algorithms/polyline_formatter.cpp index d72496ad6..e491b7570 100644 --- a/algorithms/polyline_formatter.cpp +++ b/algorithms/polyline_formatter.cpp @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "polyline_compressor.hpp" #include "../data_structures/segment_information.hpp" -#include +#include JSON::String PolylineFormatter::printEncodedString(const std::vector &polyline) const diff --git a/algorithms/polyline_formatter.hpp b/algorithms/polyline_formatter.hpp index 1d4744d0a..e4018154d 100644 --- a/algorithms/polyline_formatter.hpp +++ b/algorithms/polyline_formatter.hpp @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct SegmentInformation; -#include "../data_structures/json_container.hpp" +#include #include #include diff --git a/algorithms/tiny_components.hpp b/algorithms/tiny_components.hpp index 5cf5a75c6..9fb357c10 100644 --- a/algorithms/tiny_components.hpp +++ b/algorithms/tiny_components.hpp @@ -42,7 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/std_hash.hpp" #include "../Util/timing_util.hpp" -#include +#include #include diff --git a/benchmarks/static_rtree.cpp b/benchmarks/static_rtree.cpp index 7a24cfc8c..cc2ae4231 100644 --- a/benchmarks/static_rtree.cpp +++ b/benchmarks/static_rtree.cpp @@ -25,14 +25,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../data_structures/original_edge_data.hpp" -#include "../data_structures/query_node.hpp" -#include "../data_structures/shared_memory_vector_wrapper.hpp" -#include "../data_structures/static_rtree.hpp" -#include "../data_structures/edge_based_node.hpp" +#include "../DataStructures/OriginalEdgeData.h" +#include "../DataStructures/QueryNode.h" +#include "../DataStructures/SharedMemoryVectorWrapper.h" +#include "../DataStructures/StaticRTree.h" #include "../Util/BoostFileSystemFix.h" +#include "../DataStructures/EdgeBasedNode.h" -#include +#include #include diff --git a/data_structures/edge_based_node.hpp b/data_structures/edge_based_node.hpp index 98746d9a8..2566efffb 100644 --- a/data_structures/edge_based_node.hpp +++ b/data_structures/edge_based_node.hpp @@ -31,10 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/travel_mode.hpp" #include "../typedefs.h" -#include - #include +#include + #include struct EdgeBasedNode diff --git a/data_structures/hilbert_value.cpp b/data_structures/hilbert_value.cpp index 216b7c553..8487fac11 100644 --- a/data_structures/hilbert_value.cpp +++ b/data_structures/hilbert_value.cpp @@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "hilbert_value.hpp" -#include +#include uint64_t HilbertCode::operator()(const FixedPointCoordinate ¤t_coordinate) const { diff --git a/data_structures/phantom_node.hpp b/data_structures/phantom_node.hpp index 9286fb9b4..620850257 100644 --- a/data_structures/phantom_node.hpp +++ b/data_structures/phantom_node.hpp @@ -28,10 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef PHANTOM_NODES_H #define PHANTOM_NODES_H -#include -#include "../data_structures/travel_mode.hpp" +#include "../DataStructures/TravelMode.h" #include "../typedefs.h" +#include + #include #include diff --git a/data_structures/query_node.hpp b/data_structures/query_node.hpp index 7705df008..18808fd95 100644 --- a/data_structures/query_node.hpp +++ b/data_structures/query_node.hpp @@ -30,10 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" -#include - #include +#include + #include struct QueryNode diff --git a/data_structures/raw_route_data.hpp b/data_structures/raw_route_data.hpp index f9242cfb0..bb48a94c9 100644 --- a/data_structures/raw_route_data.hpp +++ b/data_structures/raw_route_data.hpp @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/turn_instructions.hpp" #include "../typedefs.h" -#include +#include #include diff --git a/data_structures/route_parameters.cpp b/data_structures/route_parameters.cpp index 1019a9149..fa54ad6b2 100644 --- a/data_structures/route_parameters.cpp +++ b/data_structures/route_parameters.cpp @@ -25,12 +25,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include - #include #include #include +#include + RouteParameters::RouteParameters() : zoom_level(18), print_instructions(false), alternate_route(true), geometry(true), compression(true), deprecatedAPI(false), uturn_default(false), check_sum(-1), num_results(1) diff --git a/data_structures/segment_information.hpp b/data_structures/segment_information.hpp index dd1fc574b..117bd3972 100644 --- a/data_structures/segment_information.hpp +++ b/data_structures/segment_information.hpp @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/travel_mode.hpp" #include "../typedefs.h" -#include +#include // Struct fits everything in one cache line struct SegmentInformation diff --git a/data_structures/static_rtree.hpp b/data_structures/static_rtree.hpp index f670ca34f..db7180468 100644 --- a/data_structures/static_rtree.hpp +++ b/data_structures/static_rtree.hpp @@ -44,7 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/timing_util.hpp" #include "../typedefs.h" -#include +#include #include #include diff --git a/datastore.cpp b/datastore.cpp index d29200420..326081b2f 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Util/FingerPrint.h" #include "typedefs.h" -#include +#include using RTreeLeaf = BaseDataFacade::RTreeLeaf; using RTreeNode = StaticRTree::vector, true>::TreeNode; diff --git a/descriptors/description_factory.cpp b/descriptors/description_factory.cpp index 075eff029..37ff8fb0c 100644 --- a/descriptors/description_factory.cpp +++ b/descriptors/description_factory.cpp @@ -27,8 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "description_factory.hpp" -#include - #include "../typedefs.h" #include "../algorithms/polyline_formatter.hpp" #include "../data_structures/raw_route_data.hpp" diff --git a/descriptors/description_factory.hpp b/descriptors/description_factory.hpp index 9b96dd20f..f001b9b8b 100644 --- a/descriptors/description_factory.hpp +++ b/descriptors/description_factory.hpp @@ -33,11 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/json_container.hpp" #include "../data_structures/segment_information.hpp" #include "../data_structures/turn_instructions.hpp" -#include "../typedefs.h" #include -#include +#include +#include #include diff --git a/descriptors/descriptor_base.hpp b/descriptors/descriptor_base.hpp index 31c08eaf1..670f0038f 100644 --- a/descriptors/descriptor_base.hpp +++ b/descriptors/descriptor_base.hpp @@ -32,13 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../data_structures/raw_route_data.hpp" #include "../typedefs.h" -#include - #include #include #include - struct DescriptorTable : public std::unordered_map { unsigned get_id(const std::string &key) diff --git a/descriptors/gpx_descriptor.hpp b/descriptors/gpx_descriptor.hpp index 2dd003490..8da8759b2 100644 --- a/descriptors/gpx_descriptor.hpp +++ b/descriptors/gpx_descriptor.hpp @@ -29,9 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define GPX_DESCRIPTOR_HPP #include "descriptor_base.hpp" -#include "../data_structures/json_container.hpp" #include "../Util/xml_renderer.hpp" +#include + #include template class GPXDescriptor final : public BaseDescriptor diff --git a/descriptors/json_descriptor.hpp b/descriptors/json_descriptor.hpp index 2aae939a9..f0f094246 100644 --- a/descriptors/json_descriptor.hpp +++ b/descriptors/json_descriptor.hpp @@ -1,393 +1,395 @@ -/* - -Copyright (c) 2014, Project OSRM, Dennis Luxen, others -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. - -*/ - -#ifndef JSON_DESCRIPTOR_HPP -#define JSON_DESCRIPTOR_HPP - -#include "descriptor_base.hpp" -#include "description_factory.hpp" -#include "../algorithms/object_encoder.hpp" -#include "../algorithms/route_name_extraction.hpp" -#include "../data_structures/json_container.hpp" -#include "../data_structures/segment_information.hpp" -#include "../data_structures/turn_instructions.hpp" -#include "../Util/bearing.hpp" -#include "../Util/integer_range.hpp" -#include "../Util/json_renderer.hpp" -#include "../Util/simple_logger.hpp" -#include "../Util/string_util.hpp" -#include "../Util/timing_util.hpp" - -#include - -template class JSONDescriptor final : public BaseDescriptor -{ - private: - DataFacadeT *facade; - DescriptorConfig config; - DescriptionFactory description_factory, alternate_description_factory; - FixedPointCoordinate current; - unsigned entered_restricted_area_count; - struct RoundAbout - { - RoundAbout() : start_index(INT_MAX), name_id(INVALID_NAMEID), leave_at_exit(INT_MAX) {} - int start_index; - unsigned name_id; - int leave_at_exit; - } round_about; - - struct Segment - { - Segment() : name_id(INVALID_NAMEID), length(-1), position(0) {} - Segment(unsigned n, int l, unsigned p) : name_id(n), length(l), position(p) {} - unsigned name_id; - int length; - unsigned position; - }; - std::vector shortest_path_segments, alternative_path_segments; - ExtractRouteNames GenerateRouteNames; - - public: - explicit JSONDescriptor(DataFacadeT *facade) : facade(facade), entered_restricted_area_count(0) {} - - void SetConfig(const DescriptorConfig &c) final { config = c; } - - unsigned DescribeLeg(const std::vector route_leg, - const PhantomNodes &leg_phantoms, - const bool target_traversed_in_reverse, - const bool is_via_leg) - { - unsigned added_element_count = 0; - // Get all the coordinates for the computed route - FixedPointCoordinate current_coordinate; - for (const PathData &path_data : route_leg) - { - current_coordinate = facade->GetCoordinateOfNode(path_data.node); - description_factory.AppendSegment(current_coordinate, path_data); - ++added_element_count; - } - description_factory.SetEndSegment( - leg_phantoms.target_phantom, target_traversed_in_reverse, is_via_leg); - ++added_element_count; - BOOST_ASSERT((route_leg.size() + 1) == added_element_count); - return added_element_count; - } - - void Run(const RawRouteData &raw_route, http::Reply &reply) final - { - JSON::Object json_result; - if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length) - { - // We do not need to do much, if there is no route ;-) - json_result.values["status"] = 207; - json_result.values["status_message"] = "Cannot find route between points"; - JSON::render(reply.content, json_result); - return; - } - - // check if first segment is non-zero - std::string road_name = facade->GetEscapedNameForNameID( - raw_route.segment_end_coordinates.front().source_phantom.name_id); - - BOOST_ASSERT(raw_route.unpacked_path_segments.size() == - raw_route.segment_end_coordinates.size()); - - description_factory.SetStartSegment( - raw_route.segment_end_coordinates.front().source_phantom, - raw_route.source_traversed_in_reverse.front()); - json_result.values["status"] = 0; - json_result.values["status_message"] = "Found route between points"; - - // for each unpacked segment add the leg to the description - for (const auto i : osrm::irange(0, raw_route.unpacked_path_segments.size())) - { -#ifndef NDEBUG - const int added_segments = -#endif - DescribeLeg(raw_route.unpacked_path_segments[i], - raw_route.segment_end_coordinates[i], - raw_route.target_traversed_in_reverse[i], - raw_route.is_via_leg(i)); - BOOST_ASSERT(0 < added_segments); - } - description_factory.Run(facade, config.zoom_level); - - if (config.geometry) - { - JSON::Value route_geometry = - description_factory.AppendGeometryString(config.encode_geometry); - json_result.values["route_geometry"] = route_geometry; - } - if (config.instructions) - { - JSON::Array json_route_instructions; - BuildTextualDescription(description_factory, - json_route_instructions, - raw_route.shortest_path_length, - shortest_path_segments); - json_result.values["route_instructions"] = json_route_instructions; - } - description_factory.BuildRouteSummary(description_factory.get_entire_length(), - raw_route.shortest_path_length); - JSON::Object json_route_summary; - json_route_summary.values["total_distance"] = description_factory.summary.distance; - json_route_summary.values["total_time"] = description_factory.summary.duration; - json_route_summary.values["start_point"] = - facade->GetEscapedNameForNameID(description_factory.summary.source_name_id); - json_route_summary.values["end_point"] = - facade->GetEscapedNameForNameID(description_factory.summary.target_name_id); - json_result.values["route_summary"] = json_route_summary; - - BOOST_ASSERT(!raw_route.segment_end_coordinates.empty()); - - JSON::Array json_via_points_array; - JSON::Array json_first_coordinate; - json_first_coordinate.values.push_back( - raw_route.segment_end_coordinates.front().source_phantom.location.lat / - COORDINATE_PRECISION); - json_first_coordinate.values.push_back( - raw_route.segment_end_coordinates.front().source_phantom.location.lon / - COORDINATE_PRECISION); - json_via_points_array.values.push_back(json_first_coordinate); - for (const PhantomNodes &nodes : raw_route.segment_end_coordinates) - { - std::string tmp; - JSON::Array json_coordinate; - json_coordinate.values.push_back(nodes.target_phantom.location.lat / - COORDINATE_PRECISION); - json_coordinate.values.push_back(nodes.target_phantom.location.lon / - COORDINATE_PRECISION); - json_via_points_array.values.push_back(json_coordinate); - } - json_result.values["via_points"] = json_via_points_array; - - JSON::Array json_via_indices_array; - - std::vector const &shortest_leg_end_indices = description_factory.GetViaIndices(); - json_via_indices_array.values.insert(json_via_indices_array.values.end(), - shortest_leg_end_indices.begin(), - shortest_leg_end_indices.end()); - json_result.values["via_indices"] = json_via_indices_array; - - // only one alternative route is computed at this time, so this is hardcoded - if (INVALID_EDGE_WEIGHT != raw_route.alternative_path_length) - { - json_result.values["found_alternative"] = JSON::True(); - BOOST_ASSERT(!raw_route.alt_source_traversed_in_reverse.empty()); - alternate_description_factory.SetStartSegment( - raw_route.segment_end_coordinates.front().source_phantom, - raw_route.alt_source_traversed_in_reverse.front()); - // Get all the coordinates for the computed route - for (const PathData &path_data : raw_route.unpacked_alternative) - { - current = facade->GetCoordinateOfNode(path_data.node); - alternate_description_factory.AppendSegment(current, path_data); - } - alternate_description_factory.SetEndSegment( - raw_route.segment_end_coordinates.back().target_phantom, - raw_route.alt_source_traversed_in_reverse.back()); - alternate_description_factory.Run(facade, config.zoom_level); - - if (config.geometry) - { - JSON::Value alternate_geometry_string = - alternate_description_factory.AppendGeometryString(config.encode_geometry); - JSON::Array json_alternate_geometries_array; - json_alternate_geometries_array.values.push_back(alternate_geometry_string); - json_result.values["alternative_geometries"] = json_alternate_geometries_array; - } - // Generate instructions for each alternative (simulated here) - JSON::Array json_alt_instructions; - JSON::Array json_current_alt_instructions; - if (config.instructions) - { - BuildTextualDescription(alternate_description_factory, - json_current_alt_instructions, - raw_route.alternative_path_length, - alternative_path_segments); - json_alt_instructions.values.push_back(json_current_alt_instructions); - json_result.values["alternative_instructions"] = json_alt_instructions; - } - alternate_description_factory.BuildRouteSummary( - alternate_description_factory.get_entire_length(), raw_route.alternative_path_length); - - JSON::Object json_alternate_route_summary; - JSON::Array json_alternate_route_summary_array; - json_alternate_route_summary.values["total_distance"] = - alternate_description_factory.summary.distance; - json_alternate_route_summary.values["total_time"] = - alternate_description_factory.summary.duration; - json_alternate_route_summary.values["start_point"] = facade->GetEscapedNameForNameID( - alternate_description_factory.summary.source_name_id); - json_alternate_route_summary.values["end_point"] = facade->GetEscapedNameForNameID( - alternate_description_factory.summary.target_name_id); - json_alternate_route_summary_array.values.push_back(json_alternate_route_summary); - json_result.values["alternative_summaries"] = json_alternate_route_summary_array; - - std::vector const &alternate_leg_end_indices = - alternate_description_factory.GetViaIndices(); - JSON::Array json_altenative_indices_array; - json_altenative_indices_array.values.insert(json_altenative_indices_array.values.end(), - alternate_leg_end_indices.begin(), - alternate_leg_end_indices.end()); - json_result.values["alternative_indices"] = json_altenative_indices_array; - } - else - { - json_result.values["found_alternative"] = JSON::False(); - } - - // Get Names for both routes - RouteNames route_names = - GenerateRouteNames(shortest_path_segments, alternative_path_segments, facade); - JSON::Array json_route_names; - json_route_names.values.push_back(route_names.shortest_path_name_1); - json_route_names.values.push_back(route_names.shortest_path_name_2); - json_result.values["route_name"] = json_route_names; - - if (INVALID_EDGE_WEIGHT != raw_route.alternative_path_length) - { - JSON::Array json_alternate_names_array; - JSON::Array json_alternate_names; - json_alternate_names.values.push_back(route_names.alternative_path_name_1); - json_alternate_names.values.push_back(route_names.alternative_path_name_2); - json_alternate_names_array.values.push_back(json_alternate_names); - json_result.values["alternative_names"] = json_alternate_names_array; - } - - JSON::Object json_hint_object; - json_hint_object.values["checksum"] = facade->GetCheckSum(); - JSON::Array json_location_hint_array; - std::string hint; - for (const auto i : osrm::irange(0, raw_route.segment_end_coordinates.size())) - { - ObjectEncoder::EncodeToBase64(raw_route.segment_end_coordinates[i].source_phantom, hint); - json_location_hint_array.values.push_back(hint); - } - ObjectEncoder::EncodeToBase64(raw_route.segment_end_coordinates.back().target_phantom, hint); - json_location_hint_array.values.push_back(hint); - json_hint_object.values["locations"] = json_location_hint_array; - json_result.values["hint_data"] = json_hint_object; - - // render the content to the output array - TIMER_START(route_render); - JSON::render(reply.content, json_result); - TIMER_STOP(route_render); - SimpleLogger().Write(logDEBUG) << "rendering took: " << TIMER_MSEC(route_render); - } - - // TODO: reorder parameters - inline void BuildTextualDescription(DescriptionFactory &description_factory, - JSON::Array &json_instruction_array, - const int route_length, - std::vector &route_segments_list) - { - // Segment information has following format: - //["instruction id","streetname",length,position,time,"length","earth_direction",azimuth] - unsigned necessary_segments_running_index = 0; - round_about.leave_at_exit = 0; - round_about.name_id = 0; - std::string temp_dist, temp_length, temp_duration, temp_bearing, temp_instruction; - - // Fetch data from Factory and generate a string from it. - for (const SegmentInformation &segment : description_factory.path_description) - { - JSON::Array json_instruction_row; - TurnInstruction current_instruction = segment.turn_instruction; - entered_restricted_area_count += (current_instruction != segment.turn_instruction); - if (TurnInstructionsClass::TurnIsNecessary(current_instruction)) - { - if (TurnInstruction::EnterRoundAbout == current_instruction) - { - round_about.name_id = segment.name_id; - round_about.start_index = necessary_segments_running_index; - } - else - { - std::string current_turn_instruction; - if (TurnInstruction::LeaveRoundAbout == current_instruction) - { - temp_instruction = - cast::integral_to_string(cast::enum_to_underlying(TurnInstruction::EnterRoundAbout)); - current_turn_instruction += temp_instruction; - current_turn_instruction += "-"; - temp_instruction = cast::integral_to_string(round_about.leave_at_exit + 1); - current_turn_instruction += temp_instruction; - round_about.leave_at_exit = 0; - } - else - { - temp_instruction = cast::integral_to_string(cast::enum_to_underlying(current_instruction)); - current_turn_instruction += temp_instruction; - } - json_instruction_row.values.push_back(current_turn_instruction); - - json_instruction_row.values.push_back( - facade->GetEscapedNameForNameID(segment.name_id)); - json_instruction_row.values.push_back(std::round(segment.length)); - json_instruction_row.values.push_back(necessary_segments_running_index); - json_instruction_row.values.push_back(round(segment.duration / 10)); - json_instruction_row.values.push_back( - cast::integral_to_string(static_cast(segment.length)) + "m"); - const double bearing_value = (segment.bearing / 10.); - json_instruction_row.values.push_back(Bearing::Get(bearing_value)); - json_instruction_row.values.push_back( - static_cast(round(bearing_value))); - json_instruction_row.values.push_back(segment.travel_mode); - - route_segments_list.emplace_back( - segment.name_id, - static_cast(segment.length), - static_cast(route_segments_list.size())); - json_instruction_array.values.push_back(json_instruction_row); - } - } - else if (TurnInstruction::StayOnRoundAbout == current_instruction) - { - ++round_about.leave_at_exit; - } - if (segment.necessary) - { - ++necessary_segments_running_index; - } - } - - JSON::Array json_last_instruction_row; - temp_instruction = cast::integral_to_string(cast::enum_to_underlying(TurnInstruction::ReachedYourDestination)); - json_last_instruction_row.values.push_back(temp_instruction); - json_last_instruction_row.values.push_back(""); - json_last_instruction_row.values.push_back(0); - json_last_instruction_row.values.push_back(necessary_segments_running_index - 1); - json_last_instruction_row.values.push_back(0); - json_last_instruction_row.values.push_back("0m"); - json_last_instruction_row.values.push_back(Bearing::Get(0.0)); - json_last_instruction_row.values.push_back(0.); - json_instruction_array.values.push_back(json_last_instruction_row); - } -}; - -#endif /* JSON_DESCRIPTOR_HPP */ +/* + +Copyright (c) 2014, Project OSRM, Dennis Luxen, others +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. + +*/ + +#ifndef JSON_DESCRIPTOR_HPP +#define JSON_DESCRIPTOR_HPP + +#include "descriptor_base.hpp" +#include "description_factory.hpp" +#include "../algorithms/object_encoder.hpp" +#include "../algorithms/route_name_extraction.hpp" +#include "../data_structures/json_container.hpp" +#include "../data_structures/segment_information.hpp" +#include "../data_structures/turn_instructions.hpp" +#include "../Util/bearing.hpp" +#include "../Util/integer_range.hpp" +#include "../Util/json_renderer.hpp" +#include "../Util/simple_logger.hpp" +#include "../Util/StringUtil.h" +#include "../Util/timing_util.hpp" + +#include + +#include + +template class JSONDescriptor final : public BaseDescriptor +{ + private: + DataFacadeT *facade; + DescriptorConfig config; + DescriptionFactory description_factory, alternate_description_factory; + FixedPointCoordinate current; + unsigned entered_restricted_area_count; + struct RoundAbout + { + RoundAbout() : start_index(INT_MAX), name_id(INVALID_NAMEID), leave_at_exit(INT_MAX) {} + int start_index; + unsigned name_id; + int leave_at_exit; + } round_about; + + struct Segment + { + Segment() : name_id(INVALID_NAMEID), length(-1), position(0) {} + Segment(unsigned n, int l, unsigned p) : name_id(n), length(l), position(p) {} + unsigned name_id; + int length; + unsigned position; + }; + std::vector shortest_path_segments, alternative_path_segments; + ExtractRouteNames GenerateRouteNames; + + public: + explicit JSONDescriptor(DataFacadeT *facade) : facade(facade), entered_restricted_area_count(0) {} + + void SetConfig(const DescriptorConfig &c) final { config = c; } + + unsigned DescribeLeg(const std::vector route_leg, + const PhantomNodes &leg_phantoms, + const bool target_traversed_in_reverse, + const bool is_via_leg) + { + unsigned added_element_count = 0; + // Get all the coordinates for the computed route + FixedPointCoordinate current_coordinate; + for (const PathData &path_data : route_leg) + { + current_coordinate = facade->GetCoordinateOfNode(path_data.node); + description_factory.AppendSegment(current_coordinate, path_data); + ++added_element_count; + } + description_factory.SetEndSegment( + leg_phantoms.target_phantom, target_traversed_in_reverse, is_via_leg); + ++added_element_count; + BOOST_ASSERT((route_leg.size() + 1) == added_element_count); + return added_element_count; + } + + void Run(const RawRouteData &raw_route, http::Reply &reply) final + { + JSON::Object json_result; + if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length) + { + // We do not need to do much, if there is no route ;-) + json_result.values["status"] = 207; + json_result.values["status_message"] = "Cannot find route between points"; + JSON::render(reply.content, json_result); + return; + } + + // check if first segment is non-zero + std::string road_name = facade->GetEscapedNameForNameID( + raw_route.segment_end_coordinates.front().source_phantom.name_id); + + BOOST_ASSERT(raw_route.unpacked_path_segments.size() == + raw_route.segment_end_coordinates.size()); + + description_factory.SetStartSegment( + raw_route.segment_end_coordinates.front().source_phantom, + raw_route.source_traversed_in_reverse.front()); + json_result.values["status"] = 0; + json_result.values["status_message"] = "Found route between points"; + + // for each unpacked segment add the leg to the description + for (const auto i : osrm::irange(0, raw_route.unpacked_path_segments.size())) + { +#ifndef NDEBUG + const int added_segments = +#endif + DescribeLeg(raw_route.unpacked_path_segments[i], + raw_route.segment_end_coordinates[i], + raw_route.target_traversed_in_reverse[i], + raw_route.is_via_leg(i)); + BOOST_ASSERT(0 < added_segments); + } + description_factory.Run(facade, config.zoom_level); + + if (config.geometry) + { + JSON::Value route_geometry = + description_factory.AppendGeometryString(config.encode_geometry); + json_result.values["route_geometry"] = route_geometry; + } + if (config.instructions) + { + JSON::Array json_route_instructions; + BuildTextualDescription(description_factory, + json_route_instructions, + raw_route.shortest_path_length, + shortest_path_segments); + json_result.values["route_instructions"] = json_route_instructions; + } + description_factory.BuildRouteSummary(description_factory.get_entire_length(), + raw_route.shortest_path_length); + JSON::Object json_route_summary; + json_route_summary.values["total_distance"] = description_factory.summary.distance; + json_route_summary.values["total_time"] = description_factory.summary.duration; + json_route_summary.values["start_point"] = + facade->GetEscapedNameForNameID(description_factory.summary.source_name_id); + json_route_summary.values["end_point"] = + facade->GetEscapedNameForNameID(description_factory.summary.target_name_id); + json_result.values["route_summary"] = json_route_summary; + + BOOST_ASSERT(!raw_route.segment_end_coordinates.empty()); + + JSON::Array json_via_points_array; + JSON::Array json_first_coordinate; + json_first_coordinate.values.push_back( + raw_route.segment_end_coordinates.front().source_phantom.location.lat / + COORDINATE_PRECISION); + json_first_coordinate.values.push_back( + raw_route.segment_end_coordinates.front().source_phantom.location.lon / + COORDINATE_PRECISION); + json_via_points_array.values.push_back(json_first_coordinate); + for (const PhantomNodes &nodes : raw_route.segment_end_coordinates) + { + std::string tmp; + JSON::Array json_coordinate; + json_coordinate.values.push_back(nodes.target_phantom.location.lat / + COORDINATE_PRECISION); + json_coordinate.values.push_back(nodes.target_phantom.location.lon / + COORDINATE_PRECISION); + json_via_points_array.values.push_back(json_coordinate); + } + json_result.values["via_points"] = json_via_points_array; + + JSON::Array json_via_indices_array; + + std::vector const &shortest_leg_end_indices = description_factory.GetViaIndices(); + json_via_indices_array.values.insert(json_via_indices_array.values.end(), + shortest_leg_end_indices.begin(), + shortest_leg_end_indices.end()); + json_result.values["via_indices"] = json_via_indices_array; + + // only one alternative route is computed at this time, so this is hardcoded + if (INVALID_EDGE_WEIGHT != raw_route.alternative_path_length) + { + json_result.values["found_alternative"] = JSON::True(); + BOOST_ASSERT(!raw_route.alt_source_traversed_in_reverse.empty()); + alternate_description_factory.SetStartSegment( + raw_route.segment_end_coordinates.front().source_phantom, + raw_route.alt_source_traversed_in_reverse.front()); + // Get all the coordinates for the computed route + for (const PathData &path_data : raw_route.unpacked_alternative) + { + current = facade->GetCoordinateOfNode(path_data.node); + alternate_description_factory.AppendSegment(current, path_data); + } + alternate_description_factory.SetEndSegment( + raw_route.segment_end_coordinates.back().target_phantom, + raw_route.alt_source_traversed_in_reverse.back()); + alternate_description_factory.Run(facade, config.zoom_level); + + if (config.geometry) + { + JSON::Value alternate_geometry_string = + alternate_description_factory.AppendGeometryString(config.encode_geometry); + JSON::Array json_alternate_geometries_array; + json_alternate_geometries_array.values.push_back(alternate_geometry_string); + json_result.values["alternative_geometries"] = json_alternate_geometries_array; + } + // Generate instructions for each alternative (simulated here) + JSON::Array json_alt_instructions; + JSON::Array json_current_alt_instructions; + if (config.instructions) + { + BuildTextualDescription(alternate_description_factory, + json_current_alt_instructions, + raw_route.alternative_path_length, + alternative_path_segments); + json_alt_instructions.values.push_back(json_current_alt_instructions); + json_result.values["alternative_instructions"] = json_alt_instructions; + } + alternate_description_factory.BuildRouteSummary( + alternate_description_factory.get_entire_length(), raw_route.alternative_path_length); + + JSON::Object json_alternate_route_summary; + JSON::Array json_alternate_route_summary_array; + json_alternate_route_summary.values["total_distance"] = + alternate_description_factory.summary.distance; + json_alternate_route_summary.values["total_time"] = + alternate_description_factory.summary.duration; + json_alternate_route_summary.values["start_point"] = facade->GetEscapedNameForNameID( + alternate_description_factory.summary.source_name_id); + json_alternate_route_summary.values["end_point"] = facade->GetEscapedNameForNameID( + alternate_description_factory.summary.target_name_id); + json_alternate_route_summary_array.values.push_back(json_alternate_route_summary); + json_result.values["alternative_summaries"] = json_alternate_route_summary_array; + + std::vector const &alternate_leg_end_indices = + alternate_description_factory.GetViaIndices(); + JSON::Array json_altenative_indices_array; + json_altenative_indices_array.values.insert(json_altenative_indices_array.values.end(), + alternate_leg_end_indices.begin(), + alternate_leg_end_indices.end()); + json_result.values["alternative_indices"] = json_altenative_indices_array; + } + else + { + json_result.values["found_alternative"] = JSON::False(); + } + + // Get Names for both routes + RouteNames route_names = + GenerateRouteNames(shortest_path_segments, alternative_path_segments, facade); + JSON::Array json_route_names; + json_route_names.values.push_back(route_names.shortest_path_name_1); + json_route_names.values.push_back(route_names.shortest_path_name_2); + json_result.values["route_name"] = json_route_names; + + if (INVALID_EDGE_WEIGHT != raw_route.alternative_path_length) + { + JSON::Array json_alternate_names_array; + JSON::Array json_alternate_names; + json_alternate_names.values.push_back(route_names.alternative_path_name_1); + json_alternate_names.values.push_back(route_names.alternative_path_name_2); + json_alternate_names_array.values.push_back(json_alternate_names); + json_result.values["alternative_names"] = json_alternate_names_array; + } + + JSON::Object json_hint_object; + json_hint_object.values["checksum"] = facade->GetCheckSum(); + JSON::Array json_location_hint_array; + std::string hint; + for (const auto i : osrm::irange(0, raw_route.segment_end_coordinates.size())) + { + ObjectEncoder::EncodeToBase64(raw_route.segment_end_coordinates[i].source_phantom, hint); + json_location_hint_array.values.push_back(hint); + } + ObjectEncoder::EncodeToBase64(raw_route.segment_end_coordinates.back().target_phantom, hint); + json_location_hint_array.values.push_back(hint); + json_hint_object.values["locations"] = json_location_hint_array; + json_result.values["hint_data"] = json_hint_object; + + // render the content to the output array + TIMER_START(route_render); + JSON::render(reply.content, json_result); + TIMER_STOP(route_render); + SimpleLogger().Write(logDEBUG) << "rendering took: " << TIMER_MSEC(route_render); + } + + // TODO: reorder parameters + inline void BuildTextualDescription(DescriptionFactory &description_factory, + JSON::Array &json_instruction_array, + const int route_length, + std::vector &route_segments_list) + { + // Segment information has following format: + //["instruction id","streetname",length,position,time,"length","earth_direction",azimuth] + unsigned necessary_segments_running_index = 0; + round_about.leave_at_exit = 0; + round_about.name_id = 0; + std::string temp_dist, temp_length, temp_duration, temp_bearing, temp_instruction; + + // Fetch data from Factory and generate a string from it. + for (const SegmentInformation &segment : description_factory.path_description) + { + JSON::Array json_instruction_row; + TurnInstruction current_instruction = segment.turn_instruction; + entered_restricted_area_count += (current_instruction != segment.turn_instruction); + if (TurnInstructionsClass::TurnIsNecessary(current_instruction)) + { + if (TurnInstruction::EnterRoundAbout == current_instruction) + { + round_about.name_id = segment.name_id; + round_about.start_index = necessary_segments_running_index; + } + else + { + std::string current_turn_instruction; + if (TurnInstruction::LeaveRoundAbout == current_instruction) + { + temp_instruction = + cast::integral_to_string(cast::enum_to_underlying(TurnInstruction::EnterRoundAbout)); + current_turn_instruction += temp_instruction; + current_turn_instruction += "-"; + temp_instruction = cast::integral_to_string(round_about.leave_at_exit + 1); + current_turn_instruction += temp_instruction; + round_about.leave_at_exit = 0; + } + else + { + temp_instruction = cast::integral_to_string(cast::enum_to_underlying(current_instruction)); + current_turn_instruction += temp_instruction; + } + json_instruction_row.values.push_back(current_turn_instruction); + + json_instruction_row.values.push_back( + facade->GetEscapedNameForNameID(segment.name_id)); + json_instruction_row.values.push_back(std::round(segment.length)); + json_instruction_row.values.push_back(necessary_segments_running_index); + json_instruction_row.values.push_back(round(segment.duration / 10)); + json_instruction_row.values.push_back( + cast::integral_to_string(static_cast(segment.length)) + "m"); + const double bearing_value = (segment.bearing / 10.); + json_instruction_row.values.push_back(Bearing::Get(bearing_value)); + json_instruction_row.values.push_back( + static_cast(round(bearing_value))); + json_instruction_row.values.push_back(segment.travel_mode); + + route_segments_list.emplace_back( + segment.name_id, + static_cast(segment.length), + static_cast(route_segments_list.size())); + json_instruction_array.values.push_back(json_instruction_row); + } + } + else if (TurnInstruction::StayOnRoundAbout == current_instruction) + { + ++round_about.leave_at_exit; + } + if (segment.necessary) + { + ++necessary_segments_running_index; + } + } + + JSON::Array json_last_instruction_row; + temp_instruction = cast::integral_to_string(cast::enum_to_underlying(TurnInstruction::ReachedYourDestination)); + json_last_instruction_row.values.push_back(temp_instruction); + json_last_instruction_row.values.push_back(""); + json_last_instruction_row.values.push_back(0); + json_last_instruction_row.values.push_back(necessary_segments_running_index - 1); + json_last_instruction_row.values.push_back(0); + json_last_instruction_row.values.push_back("0m"); + json_last_instruction_row.values.push_back(Bearing::Get(0.0)); + json_last_instruction_row.values.push_back(0.); + json_instruction_array.values.push_back(json_last_instruction_row); + } +}; + +#endif /* JSON_DESCRIPTOR_HPP */ diff --git a/extractor/extractor_callbacks.cpp b/extractor/extractor_callbacks.cpp index 87e4f4f0b..7ab0fc409 100644 --- a/extractor/extractor_callbacks.cpp +++ b/extractor/extractor_callbacks.cpp @@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/container.hpp" #include "../Util/simple_logger.hpp" -#include +#include #include #include diff --git a/extractor/internal_extractor_edge.hpp b/extractor/internal_extractor_edge.hpp index ffd2d4a36..4060634c2 100644 --- a/extractor/internal_extractor_edge.hpp +++ b/extractor/internal_extractor_edge.hpp @@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + struct InternalExtractorEdge { InternalExtractorEdge() diff --git a/plugins/distance_table.hpp b/plugins/distance_table.hpp index 6ef90a5b8..050287980 100644 --- a/plugins/distance_table.hpp +++ b/plugins/distance_table.hpp @@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin_base.hpp" #include "../algorithms/object_encoder.hpp" -#include "../data_structures/json_container.hpp" #include "../data_structures/query_edge.hpp" #include "../data_structures/search_engine.hpp" #include "../descriptors/descriptor_base.hpp" @@ -40,6 +39,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/string_util.hpp" #include "../Util/timing_util.hpp" +#include + #include #include diff --git a/plugins/hello_world.hpp b/plugins/hello_world.hpp index c8b07b081..b65231db8 100644 --- a/plugins/hello_world.hpp +++ b/plugins/hello_world.hpp @@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/cast.hpp" #include "../Util/json_renderer.hpp" +#include + #include class HelloWorldPlugin final : public BasePlugin diff --git a/plugins/locate.hpp b/plugins/locate.hpp index 6171395c4..ee2ddd1c0 100644 --- a/plugins/locate.hpp +++ b/plugins/locate.hpp @@ -30,10 +30,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin_base.hpp" -#include "../data_structures/json_container.hpp" #include "../Util/json_renderer.hpp" #include "../Util/string_util.hpp" +#include + #include // locates the nearest node in the road network for a given coordinate. diff --git a/plugins/nearest.hpp b/plugins/nearest.hpp index ac1079be4..a8a4dc9fe 100644 --- a/plugins/nearest.hpp +++ b/plugins/nearest.hpp @@ -30,11 +30,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin_base.hpp" -#include "../data_structures/json_container.hpp" #include "../data_structures/phantom_node.hpp" #include "../Util/integer_range.hpp" #include "../Util/json_renderer.hpp" +#include + #include /* diff --git a/plugins/plugin_base.hpp b/plugins/plugin_base.hpp index bb23a4d57..10f41e54c 100644 --- a/plugins/plugin_base.hpp +++ b/plugins/plugin_base.hpp @@ -28,9 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef BASEPLUGIN_H_ #define BASEPLUGIN_H_ -#include -#include -#include +// remove +#include "../Server/Http/Reply.h" + +#include +#include #include #include diff --git a/plugins/timestamp.hpp b/plugins/timestamp.hpp index acdf32e7c..80d9deda5 100644 --- a/plugins/timestamp.hpp +++ b/plugins/timestamp.hpp @@ -30,9 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin_base.hpp" -#include "../data_structures/json_container.hpp" #include "../Util/json_renderer.hpp" +#include + #include template class TimestampPlugin final : public BasePlugin diff --git a/plugins/viaroute.hpp b/plugins/viaroute.hpp index 236ee395a..883dc6480 100644 --- a/plugins/viaroute.hpp +++ b/plugins/viaroute.hpp @@ -40,6 +40,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/make_unique.hpp" #include "../Util/simple_logger.hpp" +#include + #include #include