From da3c664011cde05ac0dd40c0ad701973f4d233ce Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 26 Jan 2016 08:01:31 +0100 Subject: [PATCH] Get rid of macros --- mongoose/Controller.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mongoose/Controller.h b/mongoose/Controller.h index 364c8a7f05..f7713b6231 100644 --- a/mongoose/Controller.h +++ b/mongoose/Controller.h @@ -11,12 +11,6 @@ using namespace std; -#define addRoute(httpMethod, url, controllerType, method) \ - registerRoute(httpMethod, url, new RequestHandler(this, &controllerType::method )); - -#define addRouteResponse(httpMethod, url, controllerType, method, responseType) \ - registerRoute(httpMethod, url, new RequestHandler(this, &controllerType::method )); - /** * A controller is a module that respond to requests * @@ -146,6 +140,16 @@ namespace Mongoose virtual bool handles(string method, string url); vector getUrls(); + template + void addRoute(const std::string& httpMethod, const std::string& url, void (C::*func)(Request&, StreamResponse&)){ + registerRoute(httpMethod, url, new RequestHandler(static_cast(this), func)); + } + + template + void addRouteResponse(const std::string& httpMethod, const std::string& url, void (C::*func)(Request&, R&)){ + registerRoute(httpMethod, url, new RequestHandler(static_cast(this), func)); + } + protected: Sessions *sessions; Server *server;