Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
Public Member Functions | List of all members
Context Class Reference

This class is wrapper for important data (like Response, DB, Middleware etc.), which is needed to handlers. More...

#include <context.h>

Collaboration diagram for Context:
Collaboration graph

Public Member Functions

 Context ()
 
 ~Context ()
 
RequestgetRequest ()
 
ResponsegetResponse ()
 
void setRequest (Request *request)
 
void setResponse (Response *response)
 
void setMiddlewareList (std::vector< Middleware * > *middlewareList)
 
void setPermanentlyRedirect (const char *uri)
 
void setTemporaryRedirect (const char *uri)
 
void setRedirect (const char *uri, int code)
 
MiddlewaregetMiddlewareByNameID (const char *nameID)
 
void emitCloseEvent ()
 
bool isClosed ()
 

Detailed Description

This class is wrapper for important data (like Response, DB, Middleware etc.), which is needed to handlers.

This class collects a data about current request, which was parsed from str, have a pointer to Response object, which will be serialized to client in future (here could be some written data from previous responses), also there are references to all added middleware (you could get some by id) and database, which is ready to perform method exec

Constructor & Destructor Documentation

Context::Context ( )

Constructor create an object of this class: creating Request and Response objects, and setting NULL to db and middlewareList

Context::~Context ( )

Deleting Request, Response and DB objects, if they are not NULL

Member Function Documentation

void Context::emitCloseEvent ( )

Emit signal to stop executing operation. Handler, which used this will be last executed handler in app

Middleware* Context::getMiddlewareByNameID ( const char *  nameID)

Method returns added Middleware by id (in string)

Parameters
nameIDid of middleware, which was set at startup
Returns
object of Middleware (could be inherited)
Request* Context::getRequest ( )

Gives current request

Returns
object of Request class
Response* Context::getResponse ( )

Gives current response. Could be modified by previous handlers

Returns
object of Response class
bool Context::isClosed ( )

Checks, if handlers emitted CloseEvent

Returns
true, if there were emitted close event, false otherwise
void Context::setMiddlewareList ( std::vector< Middleware * > *  middlewareList)

sets vector of Middleware objects, which can be accessed by handlers

Parameters
middlewareListstd::vector of Middleware objects
void Context::setPermanentlyRedirect ( const char *  uri)

Set permanent (code 301) redirect headers to Response

Parameters
uridestination uri, where current request will be redirected
void Context::setRedirect ( const char *  uri,
int  code 
)

Set redirect headers to Response

Parameters
uridestination uri, where current request will be redirected
codehttp code of redirect
void Context::setRequest ( Request request)

Deleting existing Request and setting new one

Parameters
requestobject of Request class (could be inherited)
void Context::setResponse ( Response response)

Deleting existing Response and setting new one

Parameters
responseobject of Response class (could be inherited)
void Context::setTemporaryRedirect ( const char *  uri)

Set temporary (code 302) redirect headers to Response

Parameters
uridestination uri, where current request will be redirected

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