2016-01-07 13:19:55 -05:00
|
|
|
#ifndef ENGINE_HPP
|
|
|
|
#define ENGINE_HPP
|
2013-12-13 12:32:24 -05:00
|
|
|
|
2016-10-14 09:55:21 -04:00
|
|
|
#include "engine/api/match_parameters.hpp"
|
|
|
|
#include "engine/api/nearest_parameters.hpp"
|
|
|
|
#include "engine/api/route_parameters.hpp"
|
|
|
|
#include "engine/api/table_parameters.hpp"
|
|
|
|
#include "engine/api/tile_parameters.hpp"
|
|
|
|
#include "engine/api/trip_parameters.hpp"
|
|
|
|
#include "engine/data_watchdog.hpp"
|
2017-01-18 07:44:17 -05:00
|
|
|
#include "engine/datafacade/contiguous_block_allocator.hpp"
|
2017-01-09 15:40:33 -05:00
|
|
|
#include "engine/datafacade_provider.hpp"
|
|
|
|
#include "engine/engine_config.hpp"
|
2016-10-14 09:55:21 -04:00
|
|
|
#include "engine/engine_config.hpp"
|
|
|
|
#include "engine/plugins/match.hpp"
|
|
|
|
#include "engine/plugins/nearest.hpp"
|
|
|
|
#include "engine/plugins/table.hpp"
|
|
|
|
#include "engine/plugins/tile.hpp"
|
|
|
|
#include "engine/plugins/trip.hpp"
|
|
|
|
#include "engine/plugins/viaroute.hpp"
|
2017-01-09 15:40:33 -05:00
|
|
|
#include "engine/routing_algorithms.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/status.hpp"
|
2016-12-06 15:30:46 -05:00
|
|
|
#include "util/exception.hpp"
|
|
|
|
#include "util/exception_utils.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "util/json_container.hpp"
|
2015-01-08 08:49:10 -05:00
|
|
|
|
2014-10-08 13:30:42 -04:00
|
|
|
#include <memory>
|
2014-05-09 12:40:07 -04:00
|
|
|
#include <string>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
2016-10-06 19:51:34 -04:00
|
|
|
|
2017-01-09 15:40:33 -05:00
|
|
|
class EngineInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~EngineInterface(){};
|
|
|
|
virtual Status Route(const api::RouteParameters ¶meters,
|
|
|
|
util::json::Object &result) const = 0;
|
|
|
|
virtual Status Table(const api::TableParameters ¶meters,
|
|
|
|
util::json::Object &result) const = 0;
|
|
|
|
virtual Status Nearest(const api::NearestParameters ¶meters,
|
|
|
|
util::json::Object &result) const = 0;
|
|
|
|
virtual Status Trip(const api::TripParameters ¶meters,
|
|
|
|
util::json::Object &result) const = 0;
|
|
|
|
virtual Status Match(const api::MatchParameters ¶meters,
|
|
|
|
util::json::Object &result) const = 0;
|
|
|
|
virtual Status Tile(const api::TileParameters ¶meters, std::string &result) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AlgorithmT> class Engine final : public EngineInterface
|
2014-05-07 10:17:14 -04:00
|
|
|
{
|
|
|
|
public:
|
2017-01-09 15:40:33 -05:00
|
|
|
explicit Engine(const EngineConfig &config)
|
|
|
|
: route_plugin(config.max_locations_viaroute), //
|
|
|
|
table_plugin(config.max_locations_distance_table), //
|
|
|
|
nearest_plugin(config.max_results_nearest), //
|
|
|
|
trip_plugin(config.max_locations_trip), //
|
|
|
|
match_plugin(config.max_locations_map_matching), //
|
|
|
|
tile_plugin() //
|
|
|
|
|
|
|
|
{
|
|
|
|
if (config.use_shared_memory)
|
|
|
|
{
|
|
|
|
facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
facade_provider =
|
|
|
|
std::make_unique<ImmutableProvider<AlgorithmT>>(config.storage_config);
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 15:56:27 -05:00
|
|
|
|
2016-10-14 09:55:21 -04:00
|
|
|
Engine(Engine &&) noexcept = delete;
|
|
|
|
Engine &operator=(Engine &&) noexcept = delete;
|
2016-02-17 15:56:27 -05:00
|
|
|
|
2016-10-14 09:55:21 -04:00
|
|
|
Engine(const Engine &) = delete;
|
|
|
|
Engine &operator=(const Engine &) = delete;
|
2017-01-09 15:40:33 -05:00
|
|
|
virtual ~Engine(){};
|
Takes care of proper special member generation globally, fixes #1689
Phew, a lot of classes were affected by this. The rationale for the
changes are as follows:
- When a type X declares any constructor, the default constructor is
not declared, so there is no need for X() = delete there. In fact,
there is brutal difference between those two: deleted members
participate in overload resolution, but not-declared members do not!
- When a type X wants to be non-copyable (e.g. to be only movable, like
threads, unique_ptrs, and so on), you can either do it by inheriting
from boost::noncopyable (the old way), or better declare both (!) the
copy constructor _and_ the copy assignment operator as deleted:
X(X const&) = delete;
X& operator=(X const&) = delete;
We had tons of types with deleted copy constructors that were lacking
a corresponding deleted copy assignment operator, making them still
copyable and you wouldn't even notice (read: scary)!
References:
- http://accu.org/content/conf2014/Howard_Hinnant_Accu_2014.pdf
- http://www.boost.org/doc/libs/master/libs/core/doc/html/core/noncopyable.html
Note: I know, I'm quoting Hinnant's extraordinary slides a lot, but
getting the sematic right here is so incredibly important.
2016-01-27 05:20:55 -05:00
|
|
|
|
2017-01-09 15:40:33 -05:00
|
|
|
Status Route(const api::RouteParameters ¶ms,
|
|
|
|
util::json::Object &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return route_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status Table(const api::TableParameters ¶ms,
|
|
|
|
util::json::Object &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return table_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status Nearest(const api::NearestParameters ¶ms,
|
|
|
|
util::json::Object &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return nearest_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status Trip(const api::TripParameters ¶ms, util::json::Object &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return trip_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status Match(const api::MatchParameters ¶ms,
|
|
|
|
util::json::Object &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return match_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status Tile(const api::TileParameters ¶ms, std::string &result) const override final
|
|
|
|
{
|
|
|
|
auto facade = facade_provider->Get();
|
|
|
|
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
|
|
|
|
return tile_plugin.HandleRequest(*facade, algorithms, params, result);
|
|
|
|
}
|
2013-12-13 12:32:24 -05:00
|
|
|
|
2014-05-07 10:17:14 -04:00
|
|
|
private:
|
2017-01-09 15:40:33 -05:00
|
|
|
std::unique_ptr<DataFacadeProvider<AlgorithmT>> facade_provider;
|
|
|
|
mutable SearchEngineData heaps;
|
2017-02-03 10:53:31 -05:00
|
|
|
|
2016-10-14 09:55:21 -04:00
|
|
|
const plugins::ViaRoutePlugin route_plugin;
|
|
|
|
const plugins::TablePlugin table_plugin;
|
|
|
|
const plugins::NearestPlugin nearest_plugin;
|
|
|
|
const plugins::TripPlugin trip_plugin;
|
|
|
|
const plugins::MatchPlugin match_plugin;
|
|
|
|
const plugins::TilePlugin tile_plugin;
|
2013-12-13 12:32:24 -05:00
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
2013-12-13 12:32:24 -05:00
|
|
|
|
2015-01-27 10:35:19 -05:00
|
|
|
#endif // OSRM_IMPL_HPP
|