add assign_methods(...) functionality to the FunctionBase
in make_*() methods you can assing your controller methods in such a way:
assign_methods(this,
by_param(L"paramoption", &MyController::MyMethod3),
by_param(L"paramoption1", L"paramoption2", &MyController::MyMethod2),
by_param_post(L"paramoption", L"postoption", &MyController::MyMethod1)
);
This commit is contained in:
@@ -250,6 +250,90 @@ protected:
|
|||||||
|
|
||||||
WinixEzcHelper winix_ezc_helper;
|
WinixEzcHelper winix_ezc_helper;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* in make_*() methods you can assing your controller methods in such a way:
|
||||||
|
* assign_methods(this,
|
||||||
|
* by_param(L"paramoption", &MyController::MyMethod3),
|
||||||
|
* by_param(L"paramoption1", L"paramoption2", &MyController::MyMethod2),
|
||||||
|
* by_param_post(L"paramoption", L"postoption", &MyController::MyMethod1)
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template<typename Controller>
|
||||||
|
struct by_param {
|
||||||
|
const wchar_t * param1;
|
||||||
|
const wchar_t * param2; // can be null
|
||||||
|
void (Controller::*method)();
|
||||||
|
|
||||||
|
by_param(const wchar_t * param1, void (Controller::*method)())
|
||||||
|
{
|
||||||
|
this->param1 = param1;
|
||||||
|
this->param2 = nullptr;
|
||||||
|
this->method = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
by_param(const wchar_t * param1, const wchar_t * param2, void (Controller::*method)())
|
||||||
|
{
|
||||||
|
this->param1 = param1;
|
||||||
|
this->param2 = param2;
|
||||||
|
this->method = method;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Controller>
|
||||||
|
struct by_param_post {
|
||||||
|
const wchar_t * param;
|
||||||
|
const wchar_t * post;
|
||||||
|
void (Controller::*method)();
|
||||||
|
|
||||||
|
by_param_post(const wchar_t * param, const wchar_t * post, void (Controller::*method)())
|
||||||
|
{
|
||||||
|
this->param = param;
|
||||||
|
this->post = post;
|
||||||
|
this->method = method;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ControllerName>
|
||||||
|
void assign_methods_internal(ControllerName * controller)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Controller, typename... AssignMethods>
|
||||||
|
void assign_methods_internal(Controller * controller, const by_param<Controller> & assign_by, AssignMethods... controller_methods)
|
||||||
|
{
|
||||||
|
if( cur->request->IsParam(assign_by.param1) && (!assign_by.param2 || cur->request->IsParam(assign_by.param2)) )
|
||||||
|
{
|
||||||
|
(controller->*assign_by.method)();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assign_methods_internal(controller, controller_methods...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Controller, typename... AssignMethods>
|
||||||
|
void assign_methods_internal(Controller * controller, const by_param_post<Controller> & assign_by, AssignMethods... controller_methods)
|
||||||
|
{
|
||||||
|
if( cur->request->IsParam(assign_by.param) && (cur->request->IsPostVar(assign_by.post)) )
|
||||||
|
{
|
||||||
|
(controller->*assign_by.method)();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assign_methods_internal(controller, controller_methods...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Controller, typename... AssignMethods>
|
||||||
|
void assign_methods(Controller * controller, AssignMethods... controller_methods)
|
||||||
|
{
|
||||||
|
assign_methods_internal(controller, controller_methods...);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user