cutelyst  4.4.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
dispatcher.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2023 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #pragma once
6 
7 #include <Cutelyst/action.h>
8 #include <Cutelyst/cutelyst_export.h>
9 
10 #include <QtCore/qhash.h>
11 #include <QtCore/qobject.h>
12 #include <QtCore/qstringlist.h>
13 
14 namespace Cutelyst {
15 
16 class Context;
17 class Controller;
18 class DispatchType;
19 class DispatcherPrivate;
20 
28 class CUTELYST_EXPORT Dispatcher : public QObject
29 {
30  Q_OBJECT
31 public:
35  Dispatcher(QObject *parent = nullptr);
36 
40  ~Dispatcher();
41 
45  [[nodiscard]] Action *getAction(QStringView name, QStringView nameSpace = {}) const;
46 
50  [[nodiscard]] Action *getActionByPath(QStringView path) const;
51 
56  [[nodiscard]] ActionList getActions(QStringView name, QStringView nameSpace) const;
57 
61  [[nodiscard]] Controller *controller(QStringView name) const;
62 
66  [[nodiscard]] QList<Controller *> controllers() const;
67 
76  [[nodiscard]] QString uriForAction(Action *action, const QStringList &captures) const;
77 
83  [[nodiscard]] Action *expandAction(const Context *c, Action *action) const;
84 
89  [[nodiscard]] QVector<DispatchType *> dispatchers() const;
90 
91 protected:
95  void setupActions(const QVector<Controller *> &controllers,
96  const QVector<DispatchType *> &dispatchers,
97  bool printActions);
98 
103  bool dispatch(Context *c);
104 
108  bool forward(Context *c, Component *component);
109 
113  bool forward(Context *c, QStringView opname);
114 
118  void prepareAction(Context *c);
119 
120 protected:
121  friend class Application;
122  friend class Context;
123  friend class Controller;
124  DispatcherPrivate *d_ptr;
125 
126 private:
127  Q_DECLARE_PRIVATE(Dispatcher)
128 };
129 
130 } // namespace Cutelyst
This class represents a Cutelyst Action.
Definition: action.h:35
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.