92 lines
3.1 KiB
C++
92 lines
3.1 KiB
C++
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
#ifndef ENGINE_API_BASE_API_HPP
|
|
#define ENGINE_API_BASE_API_HPP
|
|
|
|
#include "engine/api/base_parameters.hpp"
|
|
#include "engine/datafacade/datafacade_base.hpp"
|
|
|
|
#include "engine/api/json_factory.hpp"
|
|
#include "engine/hint.hpp"
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
#include <vector>
|
|
|
|
namespace osrm
|
|
{
|
|
namespace engine
|
|
{
|
|
namespace api
|
|
{
|
|
|
|
class BaseAPI
|
|
{
|
|
public:
|
|
BaseAPI(const datafacade::BaseDataFacade &facade_, const BaseParameters ¶meters_)
|
|
: facade(facade_), parameters(parameters_)
|
|
{
|
|
}
|
|
|
|
util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
|
|
{
|
|
BOOST_ASSERT(parameters.coordinates.size() > 0);
|
|
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
|
|
|
|
util::json::Array waypoints;
|
|
waypoints.values.resize(parameters.coordinates.size());
|
|
waypoints.values[0] = MakeWaypoint(parameters.coordinates.front(),
|
|
segment_end_coordinates.front().source_phantom);
|
|
|
|
auto coord_iter = std::next(parameters.coordinates.begin());
|
|
auto out_iter = std::next(waypoints.values.begin());
|
|
for (const auto &phantoms : segment_end_coordinates)
|
|
{
|
|
*out_iter++ = MakeWaypoint(*coord_iter++, phantoms.target_phantom);
|
|
}
|
|
return waypoints;
|
|
}
|
|
|
|
protected:
|
|
util::json::Object MakeWaypoint(const util::Coordinate input_coordinate,
|
|
const PhantomNode &phantom) const
|
|
{
|
|
return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id),
|
|
Hint{input_coordinate, phantom, facade.GetCheckSum()});
|
|
}
|
|
|
|
const datafacade::BaseDataFacade &facade;
|
|
const BaseParameters ¶meters;
|
|
};
|
|
|
|
} // ns api
|
|
} // ns engine
|
|
} // ns osrm
|
|
|
|
#endif
|