17#include <drogon/exports.h>
18#include <trantor/utils/Logger.h>
19#include <trantor/utils/MsgBuffer.h>
22#include <unordered_map>
38 const T &
get(
const std::string &key)
const
40 static const T nullVal = T();
41 auto it = viewData_.find(key);
42 if (it != viewData_.end())
44 if (
typeid(T) == it->second.type())
46 return *(std::any_cast<T>(&(it->second)));
50 LOG_ERROR <<
"Bad type";
57 void insert(
const std::string &key, std::any &&obj)
59 viewData_[key] = std::move(obj);
62 void insert(
const std::string &key,
const std::any &obj)
74 viewData_[key] = ss.str();
80 std::string strBuffer;
81 strBuffer.resize(128);
82 va_list ap, backup_ap;
84 va_copy(backup_ap, ap);
85 auto result = vsnprintf((
char *)strBuffer.data(),
91 (
static_cast<std::string::size_type
>(result) < strBuffer.size()))
93 strBuffer.resize(
static_cast<std::string::size_type
>(result));
103 strBuffer.resize(strBuffer.size() * 2);
107 strBuffer.resize(result + 1);
110 va_copy(backup_ap, ap);
111 result = vsnprintf((
char *)strBuffer.data(),
118 ((std::string::size_type)result < strBuffer.size()))
120 strBuffer.resize(result);
126 viewData_[key] = std::move(strBuffer);
132 return viewData_[key];
145 static std::string
htmlTranslate(
const char *str,
size_t length);
147 static std::string
htmlTranslate(
const std::string_view &str)
152 static bool needTranslation(
const std::string_view &str)
154 for (
auto const &c : str)
171 using ViewDataMap = std::unordered_map<std::string, std::any>;
172 mutable ViewDataMap viewData_;
This class represents the data set displayed in views.
Definition HttpViewData.h:33
const T & get(const std::string &key) const
Definition HttpViewData.h:38
std::any & operator[](const std::string &key) const
Get the 'any' object by the key parameter.
Definition HttpViewData.h:130
void insertAsString(const std::string &key, T &&val)
Definition HttpViewData.h:70
static std::string htmlTranslate(const char *str, size_t length)
Translate some special characters to HTML format.
void insert(const std::string &key, std::any &&obj)
Insert an item identified by the key parameter into the data set;.
Definition HttpViewData.h:57
void insertFormattedString(const std::string &key, const char *format,...)
Insert a formatted string identified by the key parameter.
Definition HttpViewData.h:78
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23