From 8e0d3142bfd3c4932d9c7a9b9fcd517b7a4ec05b Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 25 Oct 2016 08:33:02 +0200 Subject: [PATCH] Added fallback to boost::regex if gcc version<4.9. Fixes #77 --- CMakeLists.txt | 10 +++++++++- server_http.hpp | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe37cc9..86829e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,15 @@ include_directories(.) find_package(Threads REQUIRED) -find_package(Boost 1.53.0 COMPONENTS system thread filesystem date_time REQUIRED) +set(BOOST_COMPONENTS system thread filesystem date_time) +# Late 2017 TODO: remove the following checks and always use std::regex +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_REGEX") + endif() +endif() +find_package(Boost 1.53.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED) include_directories(SYSTEM ${Boost_INCLUDE_DIR}) if(APPLE) diff --git a/server_http.hpp b/server_http.hpp index e7be951..05577a2 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -6,12 +6,20 @@ #include #include -#include #include #include #include #include +// Late 2017 TODO: remove the following checks and always use std::regex +#ifdef USE_BOOST_REGEX +#include +#define REGEX_NS boost +#else +#include +#define REGEX_NS std +#endif + namespace SimpleWeb { template class ServerBase { @@ -75,7 +83,7 @@ namespace SimpleWeb { std::unordered_multimap header; - std::smatch path_match; + REGEX_NS::smatch path_match; std::string remote_endpoint_address; unsigned short remote_endpoint_port; @@ -111,7 +119,7 @@ namespace SimpleWeb { std::function exception_handler; private: - std::vector::Response>, std::shared_ptr::Request>)> > > > > opt_resource; public: @@ -132,7 +140,7 @@ namespace SimpleWeb { it=opt_resource.begin()+(opt_resource.size()-1); it->first=res_method.first; } - it->second.emplace_back(std::regex(res.first), res_method.second); + it->second.emplace_back(REGEX_NS::regex(res.first), res_method.second); } } @@ -335,8 +343,8 @@ namespace SimpleWeb { for(auto& res: opt_resource) { if(request->method==res.first) { for(auto& res_path: res.second) { - std::smatch sm_res; - if(std::regex_match(request->path, sm_res, res_path.first)) { + REGEX_NS::smatch sm_res; + if(REGEX_NS::regex_match(request->path, sm_res, res_path.first)) { request->path_match=std::move(sm_res); write_response(socket, request, res_path.second); return;