From cdcddc8ddb02b74751737c0abedca7ff450e6500 Mon Sep 17 00:00:00 2001 From: antao Date: Wed, 5 Jun 2019 09:28:39 +0800 Subject: [PATCH] Modify containers of AOP --- drogon_ctl/version.cc | 8 ++++---- lib/inc/drogon/CacheMap.h | 18 +++++++++--------- lib/src/HttpAppFrameworkImpl.h | 16 ++++++++-------- lib/src/HttpControllersRouter.h | 22 +++++++++++----------- lib/src/HttpRequestImpl.cc | 9 ++++++--- lib/src/HttpSimpleControllersRouter.h | 22 +++++++++++----------- 6 files changed, 49 insertions(+), 46 deletions(-) diff --git a/drogon_ctl/version.cc b/drogon_ctl/version.cc index 07f6e2a7..06db90fb 100644 --- a/drogon_ctl/version.cc +++ b/drogon_ctl/version.cc @@ -29,9 +29,9 @@ static const char banner[] = void version::handleCommand(std::vector ¶meters) { std::cout << banner << std::endl; - std::cout << "drogon ctl tools" << std::endl; - std::cout << "version:" << VERSION << std::endl; - std::cout << "git commit:" << VERSION_MD5 << std::endl; - std::cout << "compile config:" << compileFlags << " " << includeDirs + std::cout << "A utility for drogon" << std::endl; + std::cout << "Version:" << VERSION << std::endl; + std::cout << "Git commit:" << VERSION_MD5 << std::endl; + std::cout << "Compile config:" << compileFlags << " " << includeDirs << std::endl; } diff --git a/lib/inc/drogon/CacheMap.h b/lib/inc/drogon/CacheMap.h index 66c1abc7..e04c78df 100644 --- a/lib/inc/drogon/CacheMap.h +++ b/lib/inc/drogon/CacheMap.h @@ -62,15 +62,15 @@ class CacheMap public: /// constructor /** - * @param loop - * eventloop pointer - * @param tickInterval - * second - * @param wheelsNum - * number of wheels - * @param bucketsNumPerWheel - * buckets number per wheel - * The max delay of the CacheMap is about + * @param loop + * eventloop pointer + * @param tickInterval + * second + * @param wheelsNum + * number of wheels + * @param bucketsNumPerWheel + * buckets number per wheel + * The max delay of the CacheMap is about * tickInterval*(bucketsNumPerWheel^wheelsNum) seconds. */ CacheMap(trantor::EventLoop *loop, diff --git a/lib/src/HttpAppFrameworkImpl.h b/lib/src/HttpAppFrameworkImpl.h index e26c8fa7..7772922d 100644 --- a/lib/src/HttpAppFrameworkImpl.h +++ b/lib/src/HttpAppFrameworkImpl.h @@ -152,7 +152,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework AdviceCallback &&, AdviceChainCallback &&)> &advice) override { - _postRoutingAdvices.emplace_front(advice); + _postRoutingAdvices.emplace_back(advice); } virtual void registerPreHandlingAdvice( const std::function &advice) override { - _postRoutingObservers.emplace_front(advice); + _postRoutingObservers.emplace_back(advice); } virtual void registerPreHandlingAdvice( const std::function &advice) override @@ -181,7 +181,7 @@ class HttpAppFrameworkImpl : public HttpAppFramework const std::function &advice) override { - _postHandlingAdvices.emplace_front(advice); + _postHandlingAdvices.emplace_back(advice); } virtual void enableSession(const size_t timeout = 0) override @@ -453,21 +453,21 @@ class HttpAppFrameworkImpl : public HttpAppFramework AdviceCallback &&, AdviceChainCallback &&)>> _preRoutingAdvices; - std::deque> + std::vector> _postRoutingAdvices; std::vector> _preHandlingAdvices; - std::deque< + std::vector< std::function> _postHandlingAdvices; std::vector> _preRoutingObservers; - std::deque> + std::vector> _postRoutingObservers; std::vector> _preHandlingObservers; diff --git a/lib/src/HttpControllersRouter.h b/lib/src/HttpControllersRouter.h index 391822f4..a5444716 100644 --- a/lib/src/HttpControllersRouter.h +++ b/lib/src/HttpControllersRouter.h @@ -35,11 +35,11 @@ class HttpControllersRouter : public trantor::NonCopyable public: HttpControllersRouter( StaticFileRouter &router, - const std::deque> + const std::vector> &postRoutingAdvices, - const std::deque> + const std::vector> &postRoutingObservers, const std::vector> &preHandlingObservers, - const std::deque> + const std::vector> &postHandlingAdvices) : _fileRouter(router), _postRoutingAdvices(postRoutingAdvices), @@ -98,19 +98,19 @@ class HttpControllersRouter : public trantor::NonCopyable std::mutex _ctrlMutex; std::regex _ctrlRegex; - const std::deque> + const std::vector> &_postRoutingAdvices; const std::vector> &_preHandlingAdvices; - const std::deque> + const std::vector> &_postRoutingObservers; const std::vector> &_preHandlingObservers; - const std::deque< + const std::vector< std::function> &_postHandlingAdvices; diff --git a/lib/src/HttpRequestImpl.cc b/lib/src/HttpRequestImpl.cc index c086e869..c3409dfc 100644 --- a/lib/src/HttpRequestImpl.cc +++ b/lib/src/HttpRequestImpl.cc @@ -372,13 +372,16 @@ HttpRequestPtr HttpRequest::newHttpFormPostRequest() HttpRequestPtr HttpRequest::newHttpJsonRequest(const Json::Value &data) { + static std::once_flag once; + static Json::StreamWriterBuilder builder; + std::call_once(once, []() { + builder["commentStyle"] = "None"; + builder["indentation"] = ""; + }); auto req = std::make_shared(nullptr); req->setMethod(drogon::Get); req->setVersion(drogon::HttpRequest::kHttp11); req->_contentType = CT_APPLICATION_JSON; - Json::StreamWriterBuilder builder; - builder["commentStyle"] = "None"; - builder["indentation"] = ""; req->setContent(writeString(builder, data)); return req; } diff --git a/lib/src/HttpSimpleControllersRouter.h b/lib/src/HttpSimpleControllersRouter.h index 9e78b7cd..e6b86fe3 100644 --- a/lib/src/HttpSimpleControllersRouter.h +++ b/lib/src/HttpSimpleControllersRouter.h @@ -35,11 +35,11 @@ class HttpSimpleControllersRouter : public trantor::NonCopyable public: HttpSimpleControllersRouter( HttpControllersRouter &httpCtrlRouter, - const std::deque> + const std::vector> &postRoutingAdvices, - const std::deque> + const std::vector> &postRoutingObservers, const std::vector> &preHandlingObservers, - const std::deque> + const std::vector> &postHandlingAdvices) : _httpCtrlsRouter(httpCtrlRouter), _postRoutingAdvices(postRoutingAdvices), @@ -74,20 +74,20 @@ class HttpSimpleControllersRouter : public trantor::NonCopyable private: HttpControllersRouter &_httpCtrlsRouter; - const std::deque> + const std::vector> &_postRoutingAdvices; const std::vector> &_preHandlingAdvices; - const std::deque> + const std::vector> &_postRoutingObservers; const std::vector> &_preHandlingObservers; - const std::deque< + const std::vector< std::function> &_postHandlingAdvices; struct CtrlBinder