cutelyst  3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
controller.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYST_CONTROLLER_H
6 #define CUTELYST_CONTROLLER_H
7 
8 #include <Cutelyst/action.h>
9 #include <Cutelyst/context.h>
10 #include <Cutelyst/cutelyst_global.h>
11 #include <Cutelyst/request.h>
12 #include <Cutelyst/response.h>
13 
14 #include <QObject>
15 
16 #define STR(X) #X
17 #define C_PATH(X, Y) Q_CLASSINFO(STR(X##_Path), STR(Y))
18 #define C_NAMESPACE(value) Q_CLASSINFO("Namespace", value)
19 #define C_ATTR(X, Y) Q_CLASSINFO(STR(X), STR(Y)) Q_INVOKABLE
20 
21 #define CActionFor(str) \
22  ([this]() -> Cutelyst::Action * { \
23  static thread_local Cutelyst::Action *action = Cutelyst::Controller::actionFor(str); \
24  return action; \
25  }())
26 
27 namespace Cutelyst {
28 
29 class ControllerPrivate;
87 class CUTELYST_LIBRARY Controller : public QObject
88 {
89  Q_OBJECT
90 public:
94  explicit Controller(QObject *parent = nullptr);
95  virtual ~Controller();
96 
106  QString ns() const;
107 
114  Action *actionFor(const QString &name) const;
115 
122  Action *actionFor(QStringView name) const;
123 
128  ActionList actions() const;
129 
133  bool operator==(const char *className);
134 
135 protected:
144  virtual bool preFork(Application *app);
145 
154  virtual bool postFork(Application *app);
155 
161  bool _DISPATCH(Context *c);
162 
163  ControllerPrivate *d_ptr;
164 
165 private:
166  Q_DECLARE_PRIVATE(Controller)
167  friend class Application;
168  friend class Dispatcher;
169 };
170 
171 } // namespace Cutelyst
172 
173 #endif // CUTELYST_CONTROLLER_H
This class represents a Cutelyst Action.
Definition: action.h:34
The Cutelyst Context.
Definition: context.h:38
Cutelyst Controller base class
Definition: controller.h:87
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:42
The Cutelyst Dispatcher.
Definition: dispatcher.h:27