cutelyst 4.0.0
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-2023 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#pragma once
6
7#include <Cutelyst/action.h>
8#include <Cutelyst/context.h>
9#include <Cutelyst/cutelyst_global.h>
10#include <Cutelyst/request.h>
11#include <Cutelyst/response.h>
12
13#include <QObject>
14
15#define STR(X) #X
16#define C_PATH(X, Y) Q_CLASSINFO(STR(X##_Path), STR(Y))
17#define C_NAMESPACE(value) Q_CLASSINFO("Namespace", value)
18#define C_ATTR(X, Y) Q_CLASSINFO(STR(X), STR(Y)) Q_INVOKABLE
19
20#define CActionFor(str) \
21 ([this]() -> Cutelyst::Action * { \
22 static thread_local Cutelyst::Action *action = Cutelyst::Controller::actionFor(str); \
23 return action; \
24 }())
25
26namespace Cutelyst {
27
28class ControllerPrivate;
86class CUTELYST_LIBRARY Controller : public QObject
87{
88 Q_OBJECT
89public:
93 explicit Controller(QObject *parent = nullptr);
94 virtual ~Controller();
95
105 [[nodiscard]] QString ns() const noexcept;
106
113 Action *actionFor(QStringView name) const;
114
119 [[nodiscard]] ActionList actions() const noexcept;
120
124 bool operator==(const char *className);
125
126protected:
135 virtual bool preFork(Application *app);
136
145 virtual bool postFork(Application *app);
146
152 bool _DISPATCH(Context *c);
153
154 ControllerPrivate *d_ptr;
155
156private:
157 Q_DECLARE_PRIVATE(Controller)
158 friend class Application;
159 friend class Dispatcher;
160};
161
162} // namespace Cutelyst
This class represents a Cutelyst Action.
Definition: action.h:35
The Cutelyst Application.
Definition: application.h:43
The Cutelyst Context.
Definition: context.h:38
Cutelyst Controller base class
Definition: controller.h:87
The Cutelyst Dispatcher.
Definition: dispatcher.h:27
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
QVector< Action * > ActionList
Definition: action.h:154