Address PR comments
Renamed lua_function_exists and removes unused print function
This commit is contained in:
parent
a781c36876
commit
38db495879
@ -60,7 +60,7 @@ struct RouteParameters : public BaseParameters
|
|||||||
const bool alternatives_,
|
const bool alternatives_,
|
||||||
const GeometriesType geometries_,
|
const GeometriesType geometries_,
|
||||||
const OverviewType overview_,
|
const OverviewType overview_,
|
||||||
boost::optional<bool> uturns_,
|
const boost::optional<bool> uturns_,
|
||||||
Args... args_)
|
Args... args_)
|
||||||
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
|
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
|
||||||
geometries{geometries_}, overview{overview_}, uturns{uturns_}
|
geometries{geometries_}, overview{overview_}, uturns{uturns_}
|
||||||
|
@ -40,7 +40,7 @@ namespace osrm
|
|||||||
namespace extractor
|
namespace extractor
|
||||||
{
|
{
|
||||||
|
|
||||||
class ProfileProperties;
|
struct ProfileProperties;
|
||||||
|
|
||||||
class Extractor
|
class Extractor
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,6 @@ class GraphCompressor
|
|||||||
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;
|
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphCompressor();
|
|
||||||
|
|
||||||
void Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
void Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
||||||
const std::unordered_set<NodeID> &traffic_lights,
|
const std::unordered_set<NodeID> &traffic_lights,
|
||||||
RestrictionMap &restriction_map,
|
RestrictionMap &restriction_map,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef PROFILE_PROPERTIES_HPP
|
#ifndef PROFILE_PROPERTIES_HPP
|
||||||
#define PROFILE_PROPERTIES_HPP
|
#define PROFILE_PROPERTIES_HPP
|
||||||
|
|
||||||
|
#include <boost/numeric/conversion/cast.hpp>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace extractor
|
namespace extractor
|
||||||
@ -20,7 +22,7 @@ struct ProfileProperties
|
|||||||
|
|
||||||
void SetUturnPenalty(const double u_turn_penalty_)
|
void SetUturnPenalty(const double u_turn_penalty_)
|
||||||
{
|
{
|
||||||
u_turn_penalty = static_cast<int>(u_turn_penalty_ * 10.);
|
u_turn_penalty = boost::numeric_cast<int>(u_turn_penalty_ * 10.);
|
||||||
}
|
}
|
||||||
|
|
||||||
double GetTrafficSignalPenalty() const
|
double GetTrafficSignalPenalty() const
|
||||||
@ -30,7 +32,7 @@ struct ProfileProperties
|
|||||||
|
|
||||||
void SetTrafficSignalPenalty(const double traffic_signal_penalty_)
|
void SetTrafficSignalPenalty(const double traffic_signal_penalty_)
|
||||||
{
|
{
|
||||||
traffic_signal_penalty = static_cast<int>(traffic_signal_penalty_ * 10.);
|
traffic_signal_penalty = boost::numeric_cast<int>(traffic_signal_penalty_ * 10.);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! penalty to cross a traffic light in deci-seconds
|
//! penalty to cross a traffic light in deci-seconds
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "extractor/profile_properties.hpp"
|
#include "extractor/profile_properties.hpp"
|
||||||
#include "extractor/raster_source.hpp"
|
#include "extractor/raster_source.hpp"
|
||||||
|
|
||||||
|
#include "util/lua_util.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -28,12 +30,9 @@ class ScriptingEnvironment
|
|||||||
public:
|
public:
|
||||||
struct Context
|
struct Context
|
||||||
{
|
{
|
||||||
Context();
|
|
||||||
~Context();
|
|
||||||
|
|
||||||
ProfileProperties properties;
|
ProfileProperties properties;
|
||||||
SourceContainer sources;
|
SourceContainer sources;
|
||||||
lua_State *state;
|
util::LuaState state;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ScriptingEnvironment(const std::string &file_name);
|
explicit ScriptingEnvironment(const std::string &file_name);
|
||||||
@ -47,7 +46,7 @@ class ScriptingEnvironment
|
|||||||
void InitContext(Context &context);
|
void InitContext(Context &context);
|
||||||
std::mutex init_mutex;
|
std::mutex init_mutex;
|
||||||
std::string file_name;
|
std::string file_name;
|
||||||
tbb::enumerable_thread_specific<std::shared_ptr<Context>> script_contexts;
|
tbb::enumerable_thread_specific<std::unique_ptr<Context>> script_contexts;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,19 @@ namespace osrm
|
|||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T> void LUA_print(T output) { std::cout << "[LUA] " << output << std::endl; }
|
struct LuaState
|
||||||
|
{
|
||||||
|
LuaState() : handle{::luaL_newstate(), &::lua_close} { luaL_openlibs(*this); }
|
||||||
|
|
||||||
|
operator lua_State *() { return handle.get(); }
|
||||||
|
operator lua_State const *() const { return handle.get(); }
|
||||||
|
|
||||||
|
using handle_type = std::unique_ptr<lua_State, decltype(&::lua_close)>;
|
||||||
|
handle_type handle;
|
||||||
|
};
|
||||||
|
|
||||||
// Check if the lua function <name> is defined
|
// Check if the lua function <name> is defined
|
||||||
inline bool lua_function_exists(lua_State *lua_state, const char *name)
|
inline bool luaFunctionExists(lua_State *lua_state, const char *name)
|
||||||
{
|
{
|
||||||
luabind::object globals_table = luabind::globals(lua_state);
|
luabind::object globals_table = luabind::globals(lua_state);
|
||||||
luabind::object lua_function = globals_table[name];
|
luabind::object lua_function = globals_table[name];
|
||||||
|
@ -278,7 +278,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
|||||||
util::SimpleLogger().Write() << "generating edge-expanded edges";
|
util::SimpleLogger().Write() << "generating edge-expanded edges";
|
||||||
|
|
||||||
BOOST_ASSERT(lua_state != nullptr);
|
BOOST_ASSERT(lua_state != nullptr);
|
||||||
const bool use_turn_function = util::lua_function_exists(lua_state, "turn_function");
|
const bool use_turn_function = util::luaFunctionExists(lua_state, "turn_function");
|
||||||
|
|
||||||
std::size_t node_based_edge_counter = 0;
|
std::size_t node_based_edge_counter = 0;
|
||||||
std::size_t original_edges_counter = 0;
|
std::size_t original_edges_counter = 0;
|
||||||
@ -454,7 +454,7 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
|
|||||||
{
|
{
|
||||||
// call lua profile to compute turn penalty
|
// call lua profile to compute turn penalty
|
||||||
double penalty = luabind::call_function<double>(lua_state, "turn_function", 180. - angle);
|
double penalty = luabind::call_function<double>(lua_state, "turn_function", 180. - angle);
|
||||||
return static_cast<int>(penalty);
|
return boost::numeric_cast<int>(penalty);
|
||||||
}
|
}
|
||||||
catch (const luabind::error &er)
|
catch (const luabind::error &er)
|
||||||
{
|
{
|
||||||
|
@ -288,7 +288,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
|||||||
const auto all_edges_list_end_ = all_edges_list.end();
|
const auto all_edges_list_end_ = all_edges_list.end();
|
||||||
const auto all_nodes_list_end_ = all_nodes_list.end();
|
const auto all_nodes_list_end_ = all_nodes_list.end();
|
||||||
|
|
||||||
auto has_segment_function = util::lua_function_exists(segment_state, "segment_function");
|
const auto has_segment_function = util::luaFunctionExists(segment_state, "segment_function");
|
||||||
|
|
||||||
while (edge_iterator != all_edges_list_end_ && node_iterator != all_nodes_list_end_)
|
while (edge_iterator != all_edges_list_end_ && node_iterator != all_nodes_list_end_)
|
||||||
{
|
{
|
||||||
|
@ -111,7 +111,7 @@ int Extractor::run()
|
|||||||
auto& main_context = scripting_environment.GetContex();
|
auto& main_context = scripting_environment.GetContex();
|
||||||
|
|
||||||
// setup raster sources
|
// setup raster sources
|
||||||
if (util::lua_function_exists(main_context.state, "source_function"))
|
if (util::luaFunctionExists(main_context.state, "source_function"))
|
||||||
{
|
{
|
||||||
luabind::call_function<void>(main_context.state, "source_function");
|
luabind::call_function<void>(main_context.state, "source_function");
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,6 @@ namespace osrm
|
|||||||
namespace extractor
|
namespace extractor
|
||||||
{
|
{
|
||||||
|
|
||||||
GraphCompressor::GraphCompressor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
||||||
const std::unordered_set<NodeID> &traffic_lights,
|
const std::unordered_set<NodeID> &traffic_lights,
|
||||||
RestrictionMap &restriction_map,
|
RestrictionMap &restriction_map,
|
||||||
|
@ -44,7 +44,7 @@ RestrictionParser::RestrictionParser(lua_State *lua_state, const ProfileProperti
|
|||||||
|
|
||||||
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
|
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
|
||||||
{
|
{
|
||||||
if (util::lua_function_exists(lua_state, "get_exceptions"))
|
if (util::luaFunctionExists(lua_state, "get_exceptions"))
|
||||||
{
|
{
|
||||||
luabind::set_pcall_callback(&luaErrorCallback);
|
luabind::set_pcall_callback(&luaErrorCallback);
|
||||||
// get list of turn restriction exceptions
|
// get list of turn restriction exceptions
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "extractor/raster_source.hpp"
|
#include "extractor/raster_source.hpp"
|
||||||
#include "extractor/profile_properties.hpp"
|
#include "extractor/profile_properties.hpp"
|
||||||
#include "util/lua_util.hpp"
|
#include "util/lua_util.hpp"
|
||||||
|
#include "util/make_unique.hpp"
|
||||||
#include "util/exception.hpp"
|
#include "util/exception.hpp"
|
||||||
#include "util/simple_logger.hpp"
|
#include "util/simple_logger.hpp"
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
@ -52,10 +53,6 @@ int luaErrorCallback(lua_State *state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptingEnvironment::Context::Context() : state(luaL_newstate()) {}
|
|
||||||
|
|
||||||
ScriptingEnvironment::Context::~Context() { lua_close(state); }
|
|
||||||
|
|
||||||
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name)
|
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name)
|
||||||
{
|
{
|
||||||
util::SimpleLogger().Write() << "Using script " << file_name;
|
util::SimpleLogger().Write() << "Using script " << file_name;
|
||||||
@ -73,8 +70,7 @@ void ScriptingEnvironment::InitContext(ScriptingEnvironment::Context &context)
|
|||||||
|
|
||||||
// Add our function to the state's global scope
|
// Add our function to the state's global scope
|
||||||
luabind::module(context.state)
|
luabind::module(context.state)
|
||||||
[luabind::def("print", util::LUA_print<std::string>),
|
[luabind::def("durationIsValid", durationIsValid),
|
||||||
luabind::def("durationIsValid", durationIsValid),
|
|
||||||
luabind::def("parseDuration", parseDuration),
|
luabind::def("parseDuration", parseDuration),
|
||||||
luabind::class_<TravelMode>("mode")
|
luabind::class_<TravelMode>("mode")
|
||||||
.enum_("enums")[luabind::value("inaccessible", TRAVEL_MODE_INACCESSIBLE),
|
.enum_("enums")[luabind::value("inaccessible", TRAVEL_MODE_INACCESSIBLE),
|
||||||
@ -176,8 +172,7 @@ ScriptingEnvironment::Context &ScriptingEnvironment::GetContex()
|
|||||||
auto &ref = script_contexts.local(initialized);
|
auto &ref = script_contexts.local(initialized);
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Context> state = std::make_shared<Context>();
|
ref = util::make_unique<Context>();
|
||||||
ref = state;
|
|
||||||
InitContext(*ref);
|
InitContext(*ref);
|
||||||
}
|
}
|
||||||
luabind::set_pcall_callback(&luaErrorCallback);
|
luabind::set_pcall_callback(&luaErrorCallback);
|
||||||
|
@ -103,6 +103,7 @@ class MockDataFacadeT final : public osrm::engine::datafacade::BaseDataFacade<Ed
|
|||||||
std::string get_name_for_id(const unsigned /* name_id */) const { return ""; }
|
std::string get_name_for_id(const unsigned /* name_id */) const { return ""; }
|
||||||
std::size_t GetCoreSize() const { return 0; }
|
std::size_t GetCoreSize() const { return 0; }
|
||||||
std::string GetTimestamp() const { return ""; }
|
std::string GetTimestamp() const { return ""; }
|
||||||
|
bool GetUTurnsDefault() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
using MockDataFacade = MockDataFacadeT<contractor::QueryEdge::EdgeData>;
|
using MockDataFacade = MockDataFacadeT<contractor::QueryEdge::EdgeData>;
|
||||||
|
Loading…
Reference in New Issue
Block a user