cutelyst  4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
action.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYST_ACTION_H
6 #define CUTELYST_ACTION_H
7 
8 #include <Cutelyst/component.h>
9 #include <Cutelyst/context.h>
10 #include <Cutelyst/cutelyst_global.h>
11 
12 #include <QtCore/QMetaMethod>
13 #include <QtCore/QStringList>
14 
15 namespace Cutelyst {
16 
17 class Controller;
18 class Dispatcher;
19 class ActionPrivate;
35 class CUTELYST_LIBRARY Action : public Component
36 {
37  Q_OBJECT
38 public:
42  explicit Action(QObject *parent = nullptr);
43 
47  virtual ~Action() override = default;
48 
52  virtual Modifiers modifiers() const override;
53 
59  [[nodiscard]] ParamsMultiMap attributes() const noexcept;
60 
68  [[nodiscard]] QString attribute(const QString &name, const QString &defaultValue = {}) const;
69 
74  void setAttributes(const ParamsMultiMap &attributes);
75 
79  [[nodiscard]] QString className() const noexcept;
80 
84  [[nodiscard]] Controller *controller() const noexcept;
85 
89  inline bool dispatch(Context *c) { return c->execute(this); }
90 
95  [[nodiscard]] virtual bool match(int numberOfArgs) const noexcept;
96 
107  [[nodiscard]] virtual bool matchCaptures(int numberOfCaptures) const noexcept;
108 
112  [[nodiscard]] QString ns() const noexcept;
113 
119  [[nodiscard]] virtual qint8 numberOfArgs() const;
120 
125  [[nodiscard]] virtual qint8 numberOfCaptures() const;
126 
127 protected:
128  friend class Dispatcher;
129  friend class ControllerPrivate;
130 
135  explicit Action(ActionPrivate *ptr, QObject *parent = nullptr);
136 
140  bool doExecute(Context *c) override;
141 
145  void setMethod(const QMetaMethod &method);
146 
150  void setController(Controller *controller);
151 
155  void setupAction(const QVariantHash &args, Application *app);
156 
157 private:
158  Q_DECLARE_PRIVATE(Action)
159 };
160 
163 
164 } // namespace Cutelyst
165 
166 #endif // CUTELYST_ACTION_H
bool dispatch(Context *c)
Definition: action.h:89
The Cutelyst Component base class.
Definition: component.h:30
This class represents a Cutelyst Action.
Definition: action.h:35
The Cutelyst Context.
Definition: context.h:42
Cutelyst Controller base class.
Definition: controller.h:55
The Cutelyst namespace holds all public Cutelyst API.
bool execute(Component *code)
Definition: context.cpp:423
The Cutelyst application.
Definition: application.h:72
The Cutelyst Dispatcher.
Definition: dispatcher.h:28