2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#ifndef ATTRIBUTEINJECTOR_H
43#define ATTRIBUTEINJECTOR_H
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
60 for (
unsigned i = 0; i != N; ++i) {
77 template <InjectableAttribute Attribute>
94 template <InjectableAttribute Attribute>
95 constexpr bool setAttribute(
const Attribute& attribute,
bool overwrite =
false) {
96 bool inserted =
false;
98 if (!
this->attribute || overwrite) {
100 this->attribute = std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
107 template <InjectableAttribute Attribute>
108 constexpr bool setAttribute(
const Attribute&& attribute,
bool overwrite =
false) {
109 bool inserted =
false;
111 if (!
this->attribute || overwrite) {
113 this->attribute = std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
120 template <InjectableAttribute Attribute>
121 constexpr bool getAttribute(
const std::function<
void(Attribute&)>& onFound)
const {
122 const bool found =
false;
124 if (attribute !=
nullptr && attributeType ==
typeid(Attribute).name()) {
125 onFound(**std::static_pointer_cast<
AttributeProxy<Attribute>>(attribute));
131 template <InjectableAttribute Attribute>
132 constexpr void getAttribute(
const std::function<
void(Attribute&)>& onFound,
133 const std::function<
void(
const std::string&)>& onNotFound)
const {
134 if (attribute !=
nullptr && attributeType ==
typeid(Attribute).name()) {
135 onFound(**std::static_pointer_cast<
AttributeProxy<Attribute>>(attribute));
137 onNotFound(std::string(
typeid(Attribute).name()));
148 template <InjectableAttribute Attribute,
fixed_string key =
"">
149 constexpr bool setAttribute(
const Attribute& attribute,
const std::string& subKey =
"",
bool overwrite =
false) {
150 bool inserted =
false;
152 if (attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
153 attributes[
typeid(Attribute).name() + std::string(key) + subKey] =
154 std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
161 template <InjectableAttribute Attribute,
fixed_string key =
"">
162 constexpr bool setAttribute(
const Attribute&& attribute,
const std::string& subKey =
"",
bool overwrite =
false) {
163 bool inserted =
false;
165 if (attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
166 attributes[
typeid(Attribute).name() + std::string(key) + subKey] =
167 std::shared_ptr<
void>(
new AttributeProxy<Attribute>(attribute));
174 template <InjectableAttribute Attribute,
fixed_string key =
"">
175 constexpr bool delAttribute(
const std::string& subKey =
"") {
176 bool deleted = attributes.erase(
typeid(Attribute).name() + std::string(key) + subKey) > 0;
181 template <InjectableAttribute Attribute,
fixed_string key =
"">
182 constexpr bool hasAttribute(
const std::string& subKey =
"")
const {
183 bool found = attributes.find(
typeid(Attribute).name() + std::string(key) + subKey) != attributes.end();
188 template <InjectableAttribute Attribute,
fixed_string key =
"">
189 bool getAttribute(
const std::function<
void(Attribute&)>& onFound,
const std::string& subKey =
"")
const {
192 std::map<std::string, std::shared_ptr<
void>>::const_iterator it =
193 attributes.find(
typeid(Attribute).name() + std::string(key) + subKey);
195 if (it != attributes.end()) {
198 onFound(**std::static_pointer_cast<
AttributeProxy<Attribute>>(it->second));
204 template <InjectableAttribute Attribute,
fixed_string key =
"">
205 void getAttribute(
const std::function<
void(Attribute&)>& onFound,
206 const std::function<
void(
const std::string&)>& onNotFound,
207 const std::string& subKey =
"")
const {
208 std::map<std::string, std::shared_ptr<
void>>::const_iterator it =
209 attributes.find(
typeid(Attribute).name() + std::string(key) + subKey);
211 if (it != attributes.end()) {
212 onFound(**std::static_pointer_cast<
AttributeProxy<Attribute>>(it->second));
214 onNotFound(std::string(
typeid(Attribute).name()) + std::string(key) + subKey);
#define DECLARE_ROUTER_REQUESTMETHOD(METHOD)
bool caseInsensitiveRouting
const std::shared_ptr< Request > & getRequest()
bool setStrictRouting(bool strictRouting)
Controller(const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
bool getStrictRouting() const
bool setCaseInsensitiveRouting(bool caseInsensitiveRouting)
std::shared_ptr< Response > response
Controller(const Controller &controller)
void setCurrentRoute(Route *currentRoute)
void setRootRoute(RootRoute *rootRoute)
bool getCaseInsensitiveRouting() const
std::shared_ptr< Request > request
Controller & operator=(const Controller &controller) noexcept
const std::shared_ptr< Response > & getResponse()
Next(Controller &controller)
web::http::CiStringMap< std::string > cookies
Request(Request &&) noexcept=delete
Request & operator=(Request &&) noexcept=delete
std::map< std::string, std::string > params
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
web::http::CiStringMap< std::string > headers
web::http::CiStringMap< std::string > trailer
Request & operator=(Request &)=delete
const Router & setCaseInsensitiveRouting(bool caseInsensitiveRouting=true) const
const Router & setStrictRouting(bool strictRouting=true) const
Router(const Router &)=default
std::list< std::string > getRoutes() const
std::shared_ptr< RootRoute > rootRoute
VerboseRequest & operator=(const VerboseRequest &)=delete
VerboseRequest(Details details)
VerboseRequest(const VerboseRequest &)=delete
void required(CLI::Option *opt, bool req=true)
constexpr AttributeProxy(const Attribute &attribute)
constexpr Attribute & operator*()
std::map< std::string, std::shared_ptr< void > > attributes
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[])
static express::Router getRouter()
static WebApp getWebApp(const std::string &name)
static WebApp getWebApp(const std::string &name)
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