cutelyst  4.4.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-2024 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #pragma once
6 
7 #include <Cutelyst/component.h>
8 #include <Cutelyst/context.h>
9 #include <Cutelyst/cutelyst_export.h>
10 
11 #include <QtCore/QMetaMethod>
12 #include <QtCore/QStringList>
13 
14 namespace Cutelyst {
15 
16 class Controller;
17 class Dispatcher;
18 class ActionPrivate;
34 class CUTELYST_EXPORT Action : public Component
35 {
36  Q_OBJECT
37 public:
41  explicit Action(QObject *parent = nullptr);
42 
46  virtual ~Action() override = default;
47 
51  virtual Modifiers modifiers() const override;
52 
58  [[nodiscard]] ParamsMultiMap attributes() const noexcept;
59 
67  [[nodiscard]] QString attribute(const QString &name, const QString &defaultValue = {}) const;
68 
73  void setAttributes(const ParamsMultiMap &attributes);
74 
78  [[nodiscard]] QString className() const noexcept;
79 
83  [[nodiscard]] Controller *controller() const noexcept;
84 
88  inline bool dispatch(Context *c) { return c->execute(this); }
89 
94  [[nodiscard]] virtual bool match(int numberOfArgs) const noexcept;
95 
106  [[nodiscard]] virtual bool matchCaptures(int numberOfCaptures) const noexcept;
107 
111  [[nodiscard]] QString ns() const noexcept;
112 
118  [[nodiscard]] virtual qint8 numberOfArgs() const;
119 
124  [[nodiscard]] virtual qint8 numberOfCaptures() const;
125 
126 protected:
127  friend class Dispatcher;
128  friend class ControllerPrivate;
129 
134  explicit Action(ActionPrivate *ptr, QObject *parent = nullptr);
135 
139  bool doExecute(Context *c) override;
140 
144  void setMethod(const QMetaMethod &method);
145 
149  void setController(Controller *controller);
150 
154  void setupAction(const QVariantHash &args, Application *app);
155 
156 private:
157  Q_DECLARE_PRIVATE(Action)
158 };
159 
162 
163 } // namespace Cutelyst
This class represents a Cutelyst Action.
Definition: action.h:35
virtual ~Action() override=default
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.