cutelyst  3.9.1
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;
34 class CUTELYST_LIBRARY Action : public Component
35 {
36  Q_OBJECT
37 public:
41  explicit Action(QObject *parent = nullptr);
42  virtual ~Action() override = default;
43 
44  virtual Modifiers modifiers() const override;
45 
51  ParamsMultiMap attributes() const noexcept;
52 
60  QString attribute(const QString &name, const QString &defaultValue = {}) const;
61 
66  void setAttributes(const ParamsMultiMap &attributes);
67 
71  QString className() const;
72 
76  Controller *controller() const;
77 
81  inline bool dispatch(Context *c) { return c->execute(this); }
82 
87  virtual bool match(int numberOfArgs) const noexcept;
88 
99  virtual bool matchCaptures(int numberOfCaptures) const noexcept;
100 
104  QString ns() const noexcept;
105 
111  virtual qint8 numberOfArgs() const noexcept;
112 
117  virtual qint8 numberOfCaptures() const noexcept;
118 
119 protected:
120  friend class Dispatcher;
121  friend class ControllerPrivate;
122 
127  explicit Action(ActionPrivate *ptr, QObject *parent = nullptr);
128 
132  virtual bool doExecute(Context *c) override;
133 
137  void setMethod(const QMetaMethod &method);
138 
142  void setController(Controller *controller);
143 
147  void setupAction(const QVariantHash &args, Application *app);
148 
149 private:
150  Q_DECLARE_PRIVATE(Action)
151 };
152 
155 
156 } // namespace Cutelyst
157 
158 #endif // CUTELYST_ACTION_H
bool dispatch(Context *c)
Definition: action.h:81
The Cutelyst Component base class.
Definition: component.h:25
This class represents a Cutelyst Action.
Definition: action.h:34
The Cutelyst Context.
Definition: context.h:38
Cutelyst Controller base class
Definition: controller.h:87
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
bool execute(Component *code)
Definition: context.cpp:429
The Cutelyst Application.
Definition: application.h:42
The Cutelyst Dispatcher.
Definition: dispatcher.h:27