cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
component.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2014-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYST_COMPONENT_H
6 #define CUTELYST_COMPONENT_H
7 
8 #include <Cutelyst/cutelyst_export.h>
9 
10 #include <QtCore/qobject.h>
11 
12 namespace Cutelyst {
13 
14 class Application;
15 class Context;
16 class Controller;
17 class Dispatcher;
18 class ComponentPrivate;
19 
29 class CUTELYST_EXPORT Component : public QObject
30 {
31  Q_OBJECT
32  Q_DECLARE_PRIVATE(Component)
33  Q_FLAGS(Modifiers)
34 public:
36  enum Modifier {
37  None = 0 << 1,
38  OnlyExecute = 1 << 1,
39  BeforeExecute = 2 << 1,
40  AroundExecute = 3 << 1,
41  AfterExecute = 4 << 1,
42  };
43  Q_ENUM(Modifier)
44  Q_DECLARE_FLAGS(Modifiers, Modifier)
45 
46 
51  explicit Component(QObject *parent = nullptr);
52 
56  virtual ~Component() override;
57 
61  [[nodiscard]] virtual Modifiers modifiers() const;
62 
67  [[nodiscard]] QString name() const noexcept;
68 
73  void setName(const QString &name);
74 
79  [[nodiscard]] QString reverse() const noexcept;
80 
85  void setReverse(const QString &reverse);
86 
93  virtual bool init(Application *application, const QVariantHash &args);
94 
98  bool execute(Context *c);
99 
100 protected:
105  explicit Component(ComponentPrivate *d, QObject *parent = nullptr);
106 
110  virtual bool beforeExecute(Context *c);
111 
116  virtual bool aroundExecute(Context *c, QStack<Component *> stack);
117 
121  virtual bool afterExecute(Context *c);
122 
126  virtual bool doExecute(Context *c);
127 
131  void applyRoles(const QStack<Component *> &roles);
132 
139  virtual bool dispatcherReady(const Dispatcher *dispatch, Controller *controller);
140 
141 protected:
142  friend class Controller;
143  ComponentPrivate
144  *d_ptr;
145 };
146 
147 } // namespace Cutelyst
148 
149 #endif // CUTELYST_COMPONENT_H
The Cutelyst application.
Definition: application.h:66
The Cutelyst Component base class.
Definition: component.h:30
The Cutelyst Context.
Definition: context.h:42
Cutelyst Controller base class.
Definition: controller.h:56
The Cutelyst Dispatcher.
Definition: dispatcher.h:29
The Cutelyst namespace holds all public Cutelyst API.