Created
August 30, 2012 03:43
-
-
Save f3nry/3522086 to your computer and use it in GitHub Desktop.
C++ Web Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cppcms/application.h" | |
#include "cppcms/applications_pool.h" | |
#include "cppcms/service.h" | |
#include "cppcms/http_response.h" | |
#include <cppcms/url_dispatcher.h> | |
#include <cppcms/url_mapper.h> | |
#include <iostream> | |
#include "content.h" | |
class Hello : public cppcms::application { | |
public: | |
Hello(cppcms::service &srv) : | |
cppcms::application(srv) | |
{ | |
dispatcher().assign("/", &Hello::all, this); | |
mapper().assign("all", "/"); | |
dispatcher().assign("/odd", &Hello::odd, this); | |
mapper().assign("odd", "/odd"); | |
dispatcher().assign("/even", &Hello::even, this); | |
mapper().assign("even", "/even"); | |
dispatcher().assign("/prime", &Hello::prime, this); | |
mapper().assign("prime", "/prime"); | |
} | |
virtual void prime(); | |
virtual void odd(); | |
virtual void even(); | |
virtual void all(); | |
}; | |
void Hello::prime() { | |
response().out() << "2, 3, 5, 7, ..."; | |
} | |
void Hello::even() { | |
response().out() << "2, 4, 6, 8, 10, ..."; | |
} | |
void Hello::odd() { | |
response().out() << "1, 3, 5, 7, 9, ..."; | |
} | |
void Hello::all() { | |
content::message c; | |
c.text = "HAI!!"; | |
render("message", c); | |
} | |
int main(int argc, char** argv) { | |
try { | |
cppcms::service srv(argc, argv); | |
srv.applications_pool().mount( | |
cppcms::applications_factory<Hello>() | |
); | |
srv.run(); | |
} catch(std::exception const &e) { | |
std::cerr << e.what() << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment