From 3f69aafec86607ba2e7c829c20ec05554cb5acf0 Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Wed, 6 Jun 2018 18:29:05 +0800 Subject: [PATCH] create api controller command,not complete yet --- drogon_ctl/create_controller.cc | 40 +++++++++++++++++++++++++++- drogon_ctl/create_controller.h | 6 ++++- examples/static_link_example/main.cc | 4 +-- lib/inc/drogon/HttpAppFramework.h | 28 +++---------------- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/drogon_ctl/create_controller.cc b/drogon_ctl/create_controller.cc index 14dda28c..24169cd4 100755 --- a/drogon_ctl/create_controller.cc +++ b/drogon_ctl/create_controller.cc @@ -150,7 +150,45 @@ void create_controller::newSimpleControllerSourceFile(std::ofstream &file,const file<<" //write your application logic here\n"; file<<"}"; } -void create_controller::createApiController(std::vector &apiPaths) +void create_controller::createApiController(std::vector &apiClasses) +{ + for(auto iter=apiClasses.begin();iter!=apiClasses.end();iter++) + { + if ((*iter)[0] == '-') + { + std::cout< &ctlNames,const std::string &namespaceName=""); void createSimpleController(const std::string &ctlName,const std::string &namespaceName=""); - void createApiController(std::vector &apiPaths); + void createApiController(std::vector &apiClasses); + void createApiController(const std::string &className); void newSimpleControllerHeaderFile(std::ofstream &file,const std::string &ctlName,const std::string &namespaceName=""); void newSimpleControllerSourceFile(std::ofstream &file,const std::string &ctlName,const std::string &namespaceName=""); + void newApiControllerHeaderFile(std::ofstream &file,const std::string &className); + void newApiControllerSourceFile(std::ofstream &file,const std::string &className); + }; } diff --git a/examples/static_link_example/main.cc b/examples/static_link_example/main.cc index 1cb919a9..fa280ee6 100755 --- a/examples/static_link_example/main.cc +++ b/examples/static_link_example/main.cc @@ -70,12 +70,12 @@ int main() B b; //functor - drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle3","",b); + drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle3","/{1}/{2}",b); A tmp; std::function&,int,const std::string &,const std::string &,int)> func=std::bind(&A::handle,&tmp,_1,_2,_3,_4,_5,_6); - //std::function + //api example for std::function drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle4","",func); LOG_DEBUG<::value) - { - //out of std::bind -// typedef decltype(&std::remove_reference::type::operator ()) OperType; -// binder=std::make_shared< -// HttpApiBinder -// >(std::forward(function)); - } - else - { - binder=std::make_shared< - HttpApiBinder - >(std::forward(function)); - } + binder=std::make_shared< + HttpApiBinder + >(std::forward(function)); instance().registerHttpApiController(pathName,parameterPattern,binder,filters); } -// template -// static void registerHttpApiBind(const std::string &pathName, -// const std::string ¶meterPattern, -// const std::function & function, -// const std::vector &filters=std::vector()) -// { -// HttpApiBinderBasePtr binder=std::make_shared< -// HttpApiBinder -// >(std::forward(function)); -// instance().registerHttpApiController(pathName,parameterPattern,binder,filters); -// } virtual void enableSession(const size_t timeout=0)=0; virtual void disableSession()=0; };