From e3244dd649f18b633828247869b7879ccd948a96 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 7 May 2014 16:17:14 +0200 Subject: [PATCH] migrate Library dir to C++11, use fwd decls --- Library/OSRM.h | 27 +++++---- Library/OSRM_impl.cpp | 121 ++++++++++++++++++----------------------- Library/OSRM_impl.h | 33 ++++++----- Tools/simpleclient.cpp | 7 ++- 4 files changed, 88 insertions(+), 100 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index 599a93524..0981a1638 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -28,22 +28,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OSRM_H #define OSRM_H -#include -#include -#include +#include class OSRM_impl; +struct RouteParameters; -class OSRM { -private: - OSRM_impl * OSRM_pimpl_; -public: - explicit OSRM( - const ServerPaths & paths, - const bool use_shared_memory = false - ); +namespace http +{ +class Reply; +} + +class OSRM +{ + private: + OSRM_impl *OSRM_pimpl_; + + public: + explicit OSRM(const ServerPaths &paths, const bool use_shared_memory = false); ~OSRM(); - void RunQuery(RouteParameters & route_parameters, http::Reply & reply); + void RunQuery(RouteParameters &route_parameters, http::Reply &reply); }; #endif // OSRM_H diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 02acbc98a..2df13d6ae 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -41,82 +41,65 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -OSRM_impl::OSRM_impl( const ServerPaths & server_paths, const bool use_shared_memory ) - : - use_shared_memory(use_shared_memory) +OSRM_impl::OSRM_impl(const ServerPaths &server_paths, const bool use_shared_memory) + : use_shared_memory(use_shared_memory) { if (use_shared_memory) { barrier = new SharedBarriers(); - query_data_facade = new SharedDataFacade( ); + query_data_facade = new SharedDataFacade(); } else { - query_data_facade = new InternalDataFacade( - server_paths - ); + query_data_facade = new InternalDataFacade(server_paths); } - //The following plugins handle all requests. - RegisterPlugin( - new HelloWorldPlugin() - ); - RegisterPlugin( - new LocatePlugin >( - query_data_facade - ) - ); - RegisterPlugin( - new NearestPlugin >( - query_data_facade - ) - ); - RegisterPlugin( - new TimestampPlugin >( - query_data_facade - ) - ); - RegisterPlugin( - new ViaRoutePlugin >( - query_data_facade - ) - ); + // The following plugins handle all requests. + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin>(query_data_facade)); + RegisterPlugin(new NearestPlugin>(query_data_facade)); + RegisterPlugin(new TimestampPlugin>(query_data_facade)); + RegisterPlugin(new ViaRoutePlugin>(query_data_facade)); } -OSRM_impl::~OSRM_impl() { - BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) { +OSRM_impl::~OSRM_impl() +{ + for (PluginMap::value_type &plugin_pointer : plugin_map) + { delete plugin_pointer.second; } - if( use_shared_memory ) { + if (use_shared_memory) + { delete barrier; } } -void OSRM_impl::RegisterPlugin(BasePlugin * plugin) { - SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); - if( plugin_map.find(plugin->GetDescriptor()) != plugin_map.end() ) { +void OSRM_impl::RegisterPlugin(BasePlugin *plugin) +{ + SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); + if (plugin_map.find(plugin->GetDescriptor()) != plugin_map.end()) + { delete plugin_map.find(plugin->GetDescriptor())->second; } plugin_map.emplace(plugin->GetDescriptor(), plugin); } -void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { - const PluginMap::const_iterator & iter = plugin_map.find( - route_parameters.service - ); +void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) +{ + const PluginMap::const_iterator &iter = plugin_map.find(route_parameters.service); - if(plugin_map.end() != iter) { + if (plugin_map.end() != iter) + { reply.status = http::Reply::ok; - if( use_shared_memory ) { + if (use_shared_memory) + { // lock update pending - boost::interprocess::scoped_lock< - boost::interprocess::named_mutex - > pending_lock(barrier->pending_update_mutex); + boost::interprocess::scoped_lock pending_lock( + barrier->pending_update_mutex); // lock query - boost::interprocess::scoped_lock< - boost::interprocess::named_mutex - > query_lock(barrier->query_mutex); + boost::interprocess::scoped_lock query_lock( + barrier->query_mutex); // unlock update pending pending_lock.unlock(); @@ -124,44 +107,44 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply // increment query count ++(barrier->number_of_queries); - (static_cast* >(query_data_facade))->CheckAndReloadFacade(); + (static_cast *>(query_data_facade)) + ->CheckAndReloadFacade(); } - iter->second->HandleRequest(route_parameters, reply ); - if( use_shared_memory ) { + iter->second->HandleRequest(route_parameters, reply); + if (use_shared_memory) + { // lock query - boost::interprocess::scoped_lock< - boost::interprocess::named_mutex - > query_lock(barrier->query_mutex); + boost::interprocess::scoped_lock query_lock( + barrier->query_mutex); // decrement query count --(barrier->number_of_queries); - BOOST_ASSERT_MSG( - 0 <= barrier->number_of_queries, - "invalid number of queries" - ); + BOOST_ASSERT_MSG(0 <= barrier->number_of_queries, "invalid number of queries"); // notify all processes that were waiting for this condition - if (0 == barrier->number_of_queries) { + if (0 == barrier->number_of_queries) + { barrier->no_running_queries_condition.notify_all(); } } - } else { + } + else + { reply = http::Reply::StockReply(http::Reply::badRequest); } } // proxy code for compilation firewall -OSRM::OSRM( - const ServerPaths & paths, - const bool use_shared_memory -) : OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory)) { } - -OSRM::~OSRM() { - delete OSRM_pimpl_; +OSRM::OSRM(const ServerPaths &paths, const bool use_shared_memory) + : OSRM_pimpl_(new OSRM_impl(paths, use_shared_memory)) +{ } -void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { +OSRM::~OSRM() { delete OSRM_pimpl_; } + +void OSRM::RunQuery(RouteParameters &route_parameters, http::Reply &reply) +{ OSRM_pimpl_->RunQuery(route_parameters, reply); } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index a96071b54..98df84f71 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -39,27 +39,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include struct SharedBarriers; -template -class BaseDataFacade; +template class BaseDataFacade; -class OSRM_impl : boost::noncopyable { -private: +class OSRM_impl +{ + private: typedef boost::unordered_map PluginMap; -public: - OSRM_impl( - const ServerPaths & paths, - const bool use_shared_memory - ); - virtual ~OSRM_impl(); - void RunQuery(RouteParameters & route_parameters, http::Reply & reply); -private: - void RegisterPlugin(BasePlugin * plugin); + public: + OSRM_impl(const ServerPaths &paths, const bool use_shared_memory); + OSRM_impl(const OSRM_impl &) = delete; + virtual ~OSRM_impl(); + void RunQuery(RouteParameters &route_parameters, http::Reply &reply); + + private: + void RegisterPlugin(BasePlugin *plugin); PluginMap plugin_map; bool use_shared_memory; - SharedBarriers * barrier; - //base class pointer to the objects - BaseDataFacade * query_data_facade; + SharedBarriers *barrier; + // base class pointer to the objects + BaseDataFacade *query_data_facade; }; -#endif //OSRM_IMPL_H +#endif // OSRM_IMPL_H diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index b1a2556ef..fa2b2c22b 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -30,7 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/ProgramOptions.h" #include "../Util/SimpleLogger.h" -#include +#include +#include +#include + #include #include @@ -107,7 +110,7 @@ int main (int argc, const char * argv[]) { //attention: super-inefficient hack below: std::stringstream my_stream; - BOOST_FOREACH(const std::string & line, osrm_reply.content) + for (const std::string & line : osrm_reply.content) { std::cout << line; my_stream << line;