change library interface to expose json container as structure to exchange data
This commit is contained in:
@@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../data_structures/raw_route_data.hpp"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <osrm/json_container.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -77,8 +79,8 @@ template <class DataFacadeT> class BaseDescriptor
|
||||
BaseDescriptor() {}
|
||||
// Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||
virtual ~BaseDescriptor() {}
|
||||
virtual void Run(const RawRouteData &raw_route, http::Reply &reply) = 0;
|
||||
virtual void SetConfig(const DescriptorConfig &config) = 0;
|
||||
virtual void Run(const RawRouteData &, JSON::Object &) = 0;
|
||||
virtual void SetConfig(const DescriptorConfig &) = 0;
|
||||
};
|
||||
|
||||
#endif // DESCRIPTOR_BASE_HPP
|
||||
|
||||
@@ -41,7 +41,7 @@ template <class DataFacadeT> class GPXDescriptor final : public BaseDescriptor<D
|
||||
DescriptorConfig config;
|
||||
DataFacadeT *facade;
|
||||
|
||||
void AddRoutePoint(const FixedPointCoordinate &coordinate, JSON::Array &json_result)
|
||||
void AddRoutePoint(const FixedPointCoordinate &coordinate, JSON::Array &json_route)
|
||||
{
|
||||
JSON::Object json_lat;
|
||||
JSON::Object json_lon;
|
||||
@@ -59,7 +59,7 @@ template <class DataFacadeT> class GPXDescriptor final : public BaseDescriptor<D
|
||||
json_row.values.push_back(json_lon);
|
||||
JSON::Object entry;
|
||||
entry.values["rtept"] = json_row;
|
||||
json_result.values.push_back(entry);
|
||||
json_route.values.push_back(entry);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -67,13 +67,13 @@ template <class DataFacadeT> class GPXDescriptor final : public BaseDescriptor<D
|
||||
|
||||
void SetConfig(const DescriptorConfig &c) final { config = c; }
|
||||
|
||||
void Run(const RawRouteData &raw_route, http::Reply &reply) final
|
||||
void Run(const RawRouteData &raw_route, JSON::Object &json_result) final
|
||||
{
|
||||
JSON::Array json_result;
|
||||
JSON::Array json_route;
|
||||
if (raw_route.shortest_path_length != INVALID_EDGE_WEIGHT)
|
||||
{
|
||||
AddRoutePoint(raw_route.segment_end_coordinates.front().source_phantom.location,
|
||||
json_result);
|
||||
json_route);
|
||||
|
||||
for (const std::vector<PathData> &path_data_vector : raw_route.unpacked_path_segments)
|
||||
{
|
||||
@@ -81,13 +81,14 @@ template <class DataFacadeT> class GPXDescriptor final : public BaseDescriptor<D
|
||||
{
|
||||
const FixedPointCoordinate current_coordinate =
|
||||
facade->GetCoordinateOfNode(path_data.node);
|
||||
AddRoutePoint(current_coordinate, json_result);
|
||||
AddRoutePoint(current_coordinate, json_route);
|
||||
}
|
||||
}
|
||||
AddRoutePoint(raw_route.segment_end_coordinates.back().target_phantom.location,
|
||||
json_result);
|
||||
json_route);
|
||||
}
|
||||
JSON::gpx_render(reply.content, json_result);
|
||||
// JSON::gpx_render(reply.content, json_route);
|
||||
json_result.values["route"] = json_route;
|
||||
}
|
||||
};
|
||||
#endif // GPX_DESCRIPTOR_HPP
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -99,15 +99,14 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
|
||||
return added_element_count;
|
||||
}
|
||||
|
||||
void Run(const RawRouteData &raw_route, http::Reply &reply) final
|
||||
void Run(const RawRouteData &raw_route, JSON::Object &json_result) 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);
|
||||
// JSON::render(reply.content, json_result);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -296,10 +295,10 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
|
||||
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);
|
||||
// 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
|
||||
@@ -356,7 +355,7 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
|
||||
json_instruction_row.values.push_back(
|
||||
cast::integral_to_string(static_cast<unsigned>(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(Azimuth::Get(bearing_value));
|
||||
json_instruction_row.values.push_back(
|
||||
static_cast<unsigned>(round(bearing_value)));
|
||||
json_instruction_row.values.push_back(segment.travel_mode);
|
||||
@@ -386,10 +385,10 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
|
||||
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(Azimuth::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 */
|
||||
#endif /* JSON_DESCRIPTOR_H_ */
|
||||
|
||||
Reference in New Issue
Block a user