2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20#ifndef ATTRIBUTEINJECTOR_H
21#define ATTRIBUTEINJECTOR_H
23#ifndef DOXYGEN_SHOULD_SKIP_THIS
38 for (
unsigned i = 0; i != N; ++i) {
55 template <InjectableAttribute Attribute>
72 template <InjectableAttribute Attribute>
73 constexpr bool setAttribute(
const Attribute& attribute,
bool overwrite =
false) {
74 bool inserted =
false;
76 if (!
this->attribute || overwrite) {
77 attributeType =
typeid(Attribute).name();
78 this->attribute = std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
85 template <InjectableAttribute Attribute>
86 constexpr bool setAttribute(
const Attribute&& attribute,
bool overwrite =
false) {
87 bool inserted =
false;
89 if (!
this->attribute || overwrite) {
90 attributeType =
typeid(Attribute).name();
91 this->attribute = std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
98 template <InjectableAttribute Attribute>
99 constexpr bool getAttribute(
const std::function<
void(Attribute&)>& onFound)
const {
100 const bool found =
false;
102 if (attribute !=
nullptr && attributeType ==
typeid(Attribute).name()) {
103 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(attribute));
109 template <InjectableAttribute Attribute>
110 constexpr void getAttribute(
const std::function<
void(Attribute&)>& onFound,
111 const std::function<
void(
const std::string&)>& onNotFound)
const {
112 if (attribute !=
nullptr && attributeType ==
typeid(Attribute).name()) {
113 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(attribute));
115 onNotFound(std::string(
typeid(Attribute).name()));
126 template <InjectableAttribute Attribute,
fixed_string key =
"">
127 constexpr bool setAttribute(
const Attribute& attribute,
const std::string& subKey =
"",
bool overwrite =
false) {
128 bool inserted =
false;
130 if (attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
131 attributes[
typeid(Attribute).name() + std::string(key) + subKey] =
132 std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
139 template <InjectableAttribute Attribute,
fixed_string key =
"">
140 constexpr bool setAttribute(
const Attribute&& attribute,
const std::string& subKey =
"",
bool overwrite =
false) {
141 bool inserted =
false;
143 if (attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
144 attributes[
typeid(Attribute).name() + std::string(key) + subKey] =
145 std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
152 template <InjectableAttribute Attribute,
fixed_string key =
"">
154 bool deleted = attributes.erase(
typeid(Attribute).name() + std::string(key) + subKey) > 0;
159 template <InjectableAttribute Attribute,
fixed_string key =
"">
161 bool found = attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) != attributes.end();
166 template <InjectableAttribute Attribute,
fixed_string key =
"">
167 bool getAttribute(
const std::function<
void(Attribute&)>& onFound,
const std::string& subKey =
"")
const {
170 std::map<std::string, std::shared_ptr<
void>>::const_iterator it =
171 attributes.find(
typeid(Attribute).name() + std::string(key) + subKey);
173 if (it != attributes.end()) {
176 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
182 template <InjectableAttribute Attribute,
fixed_string key =
"">
183 void getAttribute(
const std::function<
void(Attribute&)>& onFound,
184 const std::function<
void(
const std::string&)>& onNotFound,
185 const std::string& subKey =
"")
const {
186 std::map<std::string, std::shared_ptr<
void>>::const_iterator it =
187 attributes.find(
typeid(Attribute).name() + std::string(key) + subKey);
189 if (it != attributes.end()) {
190 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
192 onNotFound(std::string(
typeid(Attribute).name()) + std::string(key) + subKey);
#define DECLARE_ROUTER_REQUESTMETHOD(METHOD)
#define APPLICATION(req, res)
void next(const std::string &how) const
const std::shared_ptr< Request > & getRequest()
Controller(const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
std::shared_ptr< Response > response
Controller(const Controller &controller)
void setCurrentRoute(Route *currentRoute)
void setRootRoute(RootRoute *rootRoute)
std::shared_ptr< Request > request
bool dispatchNext(const std::string &parentMountPath)
Controller & operator=(const Controller &controller) noexcept
const std::shared_ptr< Response > & getResponse()
void operator()(const std::string &how="") const
Next(Controller &controller)
web::http::CiStringMap< std::string > cookies
Request(Request &&) noexcept=delete
const std::string & cookie(const std::string &key) const
Request & operator=(Request &&) noexcept=delete
const std::string & get(const std::string &key, int i=0) const
web::http::CiStringMap< std::string > queries
Request(const std::shared_ptr< web::http::server::Request > &request) noexcept
std::shared_ptr< web::http::server::Request > requestBase
Request(Request &)=delete
const std::string & query(const std::string &key) const
web::http::CiStringMap< std::string > headers
const std::string & param(const std::string &id, const std::string &fallBack="")
Request & operator=(Request &)=delete
Route & head(const Router &router) const
Route & all(const Router &router) const
Route & options(const Router &router) const
Route & connect(const Router &router) const
Route & post(const Router &router) const
Route & del(const Router &router) const
Router(const Router &)=default
Route & use(const Router &router) const
Route & get(const Router &router) const
Route & trace(const Router &router) const
Route & patch(const Router &router) const
void laxRouting(bool strict=false)
Route & put(const Router &router) const
std::shared_ptr< RootRoute > rootRoute
WebAppT(const std::string &name, const Router &router)
WebAppT(const std::string &name)
static void init(int argc, char *argv[])
static core::TickStatus tick(const utils::Timeval &timeOut=0)
static core::State state()
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
WebApp(const Router &router)
constexpr AttributeProxy(const Attribute &attribute)
constexpr Attribute & operator*()
constexpr bool setAttribute(const Attribute &&attribute, const std::string &subKey="", bool overwrite=false)
constexpr bool hasAttribute(const std::string &subKey="") const
constexpr bool delAttribute(const std::string &subKey="")
bool getAttribute(const std::function< void(Attribute &)> &onFound, const std::string &subKey="") const
constexpr bool setAttribute(const Attribute &attribute, const std::string &subKey="", bool overwrite=false)
std::string attributeType
constexpr bool setAttribute(const Attribute &attribute, bool overwrite=false)
constexpr bool setAttribute(const Attribute &&attribute, bool overwrite=false)
std::shared_ptr< void > attribute
constexpr bool getAttribute(const std::function< void(Attribute &)> &onFound) const
int main(int argc, char *argv[])
fixed_string(char const (&)[N]) -> fixed_string< N - 1 >
auto operator<=>(const fixed_string &) const =default
constexpr fixed_string(char const *s)
constexpr operator char const *() const