Cutelyst  3.5.0
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 <QtCore/qobject.h>
9 
10 #include <Cutelyst/cutelyst_global.h>
11 
12 namespace Cutelyst {
13 
14 class Application;
15 class Context;
16 class Controller;
17 class Dispatcher;
18 class ComponentPrivate;
19 
25 class CUTELYST_LIBRARY Component : public QObject
26 {
27  Q_OBJECT
28  Q_DECLARE_PRIVATE(Component)
29  Q_FLAGS(Modifiers)
30 public:
32  enum Modifier {
33  None = 0 << 1,
34  OnlyExecute = 1 << 1,
35  BeforeExecute = 2 << 1,
36  AroundExecute = 3 << 1,
37  AfterExecute = 4 << 1,
38  };
39  Q_ENUM(Modifier)
40  Q_DECLARE_FLAGS(Modifiers, Modifier)
41 
42 
47  explicit Component(QObject *parent = nullptr);
48  virtual ~Component() override;
49 
53  virtual Modifiers modifiers() const;
54 
58  QString name() const;
59 
63  void setName(const QString &name);
64 
68  QString reverse() const;
69 
73  void setReverse(const QString &reverse);
74 
81  virtual bool init(Application *application, const QVariantHash &args);
82 
86  bool execute(Context *c);
87 
88 protected:
92  explicit Component(ComponentPrivate *d, QObject *parent = nullptr);
93 
97  virtual bool beforeExecute(Context *c);
98 
103  virtual bool aroundExecute(Context *c, QStack<Component *> stack);
104 
108  virtual bool afterExecute(Context *c);
109 
113  virtual bool doExecute(Context *c);
114 
118  void applyRoles(const QStack<Component *> &roles);
119 
126  virtual bool dispatcherReady(const Dispatcher *dispatch, Controller *controller);
127 
128 protected:
129  friend class Controller;
130  ComponentPrivate *d_ptr;
131 };
132 
133 }
134 
135 #endif // CUTELYST_COMPONENT_H
The Cutelyst Component base class.
Definition: component.h:25
The Cutelyst Context.
Definition: context.h:38
Cutelyst Controller base class
Definition: controller.h:89
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