cppcms::url_dispatcher Class Reference

This class is used to glue between member function of application class and urls. More...

`#include <cppcms/url_dispatcher.h>`

Inheritance diagram for cppcms::url_dispatcher:

## Public Types

typedef booster::function< void()> | handler
typedef booster::function < void(std::string)> | handler1
typedef booster::function < void(std::string, std::string)> | handler2
typedef booster::function < void(std::string, std::string, std::string)> | handler3
typedef booster::function < void(std::string, std::string, std::string, std::string)> | handler4

## Public Member Functions

void | assign (std::string const &regex, handler handler)
void | assign (std::string const &regex, handler1 handler, int exp1)
void | assign (std::string const &regex, handler2 handler, int exp1, int exp2)
void | assign (std::string const &regex, handler3 handler, int exp1, int exp2, int exp3)
void | assign (std::string const &regex, handler4 handler, int exp1, int exp2, int exp3, int exp4)
bool | dispatch (std::string url)
template<typename C >
void | assign (std::string const &regex, void(C::*member)(), C *object)
template<typename C >
void | assign (std::string const &regex, void(C::*member)(std::string), C *object, int e1)
template<typename C >
void | assign (std::string const &regex, void(C::*member)(std::string, std::string), C *object, int e1, int e2)
template<typename C >
void | assign (std::string const &regex, void(C::*member)(std::string, std::string, std::string), C *object, int e1, int e2, int e3)
template<typename C >
void | assign (std::string const &regex, void(C::*member)(std::string, std::string, std::string, std::string), C *object, int e1, int e2, int e3, int e4)
void | mount (std::string const &match, application &app, int part)

## Detailed Description

This class is used to glue between member function of application class and urls.

This class is used in context of cppcms::application with its url member function. It uses regular expression to bind between url and callbacks that actually process the request. It also allows mount sub-applications to the root of the primary application. For example:

class my_web_project : public cppcms::application {
users_app users_;
void display_page(std::string)
...
public:
my_web_project() {
url().assign("^/page/(\\d+)/?$",bind1st(mem_fun(&my_web_project::display_page),this),1);
...

## Member Function Documentation

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | handler | handler
| ) |  |

Assign handler to pattern regex thus if URL that matches this pattern requested, handler is called

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | handler1 | handler,
|  | int | exp1
| ) |  |

Assign handler to pattern regex thus if URL that matches this pattern requested, handler is called with first parameters the string that was matched at position exp1.

For example: if regular expression is "^/page/(\\d+)/(\\w+)$" , exp1=2, and the url is "/page/13/to_be_or_not", then handler would be called with "to_be_or_not" as its first parameter

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | handler2 | handler,
|  | int | exp1,
|  | int | exp2
| ) |  |

Assign handler to pattern regex thus if URL that matches this pattern requested, handler is called with 1st and 2nd parameters the string that was matched at position exp1 and exp2

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | handler3 | handler,
|  | int | exp1,
|  | int | exp2,
|  | int | exp3
| ) |  |

Assign handler to pattern regex thus if URL that matches this pattern requested, handler is called with 1st, 2nd and 3rd parameters the string that was matched at position exp1, exp2 and exp2

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | handler4 | handler,
|  | int | exp1,
|  | int | exp2,
|  | int | exp3,
|  | int | exp4
| ) |  |

Assign handler to pattern regex thus if URL that matches this pattern requested, handler is called with 1st, 2nd, 3rd and 4th parameters the string that was matched at position exp1, exp2, exp3 and exp4

template<typename C >

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | void(C::*)() | member,
|  | C * | object
| ) |  |

inline

This template function is a shortcut to assign(regex,callback). It allows assignment of member function of an object with signature void handler() as simple as assign(expr,&bar::foo,this);

In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application

template<typename C >

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | void(C::*)(std::string) | member,
|  | C * | object,
|  | int | e1
| ) |  |

inline

This template function is a shortcut to assign(regex,callback,int). It allows assignment of member function of an object with signature void handler(string)

In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application

template<typename C >

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | void(C::*)(std::string, std::string) | member,
|  | C * | object,
|  | int | e1,
|  | int | e2
| ) |  |

inline

This template function is a shortcut to assign(regex,callback,int,int). It allows assignment of member function of an object with signature void handler(string,string)

In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application

template<typename C >

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | void(C::*)(std::string, std::string, std::string) | member,
|  | C * | object,
|  | int | e1,
|  | int | e2,
|  | int | e3
| ) |  |

inline

This template function is a shortcut to assign(regex,callback,int,int,int). It allows assignment of member function of an object with signature void handler(string,string,string)

In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application

template<typename C >

void cppcms::url_dispatcher::assign | ( | std::string const & | regex,
|  | void(C::*)(std::string, std::string, std::string, std::string) | member,
|  | C * | object,
|  | int | e1,
|  | int | e2,
|  | int | e3,
|  | int | e4
| ) |  |

inline

This template function is a shortcut to assign(regex,callback,int,int,int,int). It allows assignment of member function of an object with signature void handler(string,string,string,string)

In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application

bool cppcms::url_dispatcher::dispatch | ( | std::string | url | ) |

Try to find match between url and registered handlers and applications. If the match was found, it returns the method, how handler should bd dispatched synchronous or asynchronous, meaning the handler would be executed in thread pool or in the main non-blocking loop

void cppcms::url_dispatcher::mount | ( | std::string const & | match,
|  | application & | app,
|  | int | part
| ) |  |

Mount a sub application app to the URL dispatcher, using regular expression match.

When mounted the URL is checked against match expression and then calls app.main(substr) where substr is the matched subexpression part. For example:

dispatcher().mount("/formums((/.*)?)",forums,1);

For example: for url /forums/page/3 it would call `forums::main` with value "/page/3"

The documentation for this class was generated from the following file:

- cppcms/url_dispatcher.h