Add some comments

This commit is contained in:
antao 2019-02-12 13:18:59 +08:00
parent a44a0fc3e8
commit 2d3ff02e03
5 changed files with 30 additions and 1 deletions

View File

@ -360,4 +360,5 @@ class CacheMap
}
}
};
} // namespace drogon

View File

@ -111,10 +111,25 @@ class HttpRequest
virtual void setContentTypeCodeAndCharacterSet(ContentType type, const std::string &charSet = "utf-8") = 0;
virtual ContentType getContentTypeCode() = 0;
/// Create a request object.
/// The following methods are a series of factory methods that help users create request objects.
/// Create a normal request with http method Get and version Http1.1.
static HttpRequestPtr newHttpRequest();
/// Create a http request with:
/// Method: Get
/// Version: Http1.1
/// Content type: application/json, the @param data will be serialized into the content of the request.
static HttpRequestPtr newHttpJsonRequest(const Json::Value &data);
/// Create a http request with:
/// Method: Post
/// Version: Http1.1
/// Content type: application/x-www-form-urlencoded
static HttpRequestPtr newHttpFormPostRequest();
/// Create a http file upload request with:
/// Method: Post
/// Version: Http1.1
/// Content type: multipart/form-data
/// The @param files represents pload files which will be transferred to the server via the multipart/form-data format
static HttpRequestPtr newFileUploadRequest(const std::vector<UploadFile> &files);
virtual ~HttpRequest() {}
};

View File

@ -30,6 +30,7 @@
}
namespace drogon
{
class HttpSimpleControllerBase : public virtual DrObjectBase
{
public:

View File

@ -22,6 +22,7 @@
namespace drogon
{
class HttpViewBase : virtual public DrObjectBase
{
public:
@ -33,4 +34,5 @@ class HttpViewBase : virtual public DrObjectBase
protected:
virtual HttpResponsePtr genHttpResponse(const HttpViewData &) = 0;
};
} // namespace drogon

View File

@ -27,9 +27,11 @@
typedef std::unordered_map<std::string, any> ViewDataMap;
namespace drogon
{
/// This class represents the data set displayed in views.
class HttpViewData
{
public:
/// The function template is used to get an item in the data set by the @param key.
template <typename T>
const T get(const std::string &key, T &&nullVal = T()) const
{
@ -47,6 +49,8 @@ class HttpViewData
}
return nullVal;
}
/// Insert an item identified by the @param key into the data set;
void insert(const std::string &key, any &&obj)
{
viewData_[key] = std::move(obj);
@ -55,6 +59,8 @@ class HttpViewData
{
viewData_[key] = obj;
}
/// Insert an item identified by the @param key into the data set; The item will be converted to a string.
template <typename T>
void insertAsString(const std::string &key, T &&val)
{
@ -62,6 +68,8 @@ class HttpViewData
ss << val;
viewData_[key] = ss.str();
}
/// Insert a formated string identified by the @param key.
void insertFormattedString(const std::string &key,
const char *format, ...)
{
@ -105,6 +113,7 @@ class HttpViewData
viewData_[key] = std::move(strBuffer);
}
/// Get the 'any' object by the @param key.
any &operator[](const std::string &key) const
{
return viewData_[key];
@ -113,4 +122,5 @@ class HttpViewData
protected:
mutable ViewDataMap viewData_;
};
} // namespace drogon