Cutelyst  2.13.0
action.h
1 /*
2  * Copyright (C) 2013-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CUTELYST_ACTION_H
19 #define CUTELYST_ACTION_H
20 
21 #include <QtCore/QStringList>
22 #include <QtCore/QMetaMethod>
23 
24 #include <Cutelyst/cutelyst_global.h>
25 #include <Cutelyst/component.h>
26 #include <Cutelyst/context.h>
27 
28 namespace Cutelyst {
29 
30 class Controller;
31 class Dispatcher;
32 class ActionPrivate;
47 class CUTELYST_LIBRARY Action : public Component
48 {
49  Q_OBJECT
50 public:
54  explicit Action(QObject *parent = nullptr);
55  virtual ~Action() override = default;
56 
57  virtual Modifiers modifiers() const override;
58 
64  QMap<QString, QString> attributes() const;
65 
73  QString attribute(const QString &name, const QString &defaultValue = QString()) const;
74 
79  void setAttributes(const QMap<QString, QString> &attributes);
80 
84  QString className() const;
85 
89  Controller* controller() const;
90 
94  inline bool dispatch(Context *c) { return c->execute(this); }
95 
100  virtual bool match(int numberOfArgs) const;
101 
112  virtual bool matchCaptures(int numberOfCaptures) const;
113 
117  QString ns() const;
118 
124  virtual qint8 numberOfArgs() const;
125 
130  virtual qint8 numberOfCaptures() const;
131 
132 protected:
133  friend class Dispatcher;
134  friend class ControllerPrivate;
135 
139  explicit Action(ActionPrivate *ptr, QObject *parent = nullptr);
140 
144  virtual bool doExecute(Context *c) override;
145 
149  void setMethod(const QMetaMethod &method);
150 
154  void setController(Controller *controller);
155 
159  void setupAction(const QVariantHash &args, Application *app);
160 
161 private:
162  Q_DECLARE_PRIVATE(Action)
163 };
164 
166 typedef QVector<Action*> ActionList;
167 
168 }
169 
170 #endif // CUTELYST_ACTION_H
Cutelyst::Controller
Cutelyst Controller base class
Definition: controller.h:102
Cutelyst::Application
The Cutelyst Application.
Definition: application.h:55
Cutelyst::Dispatcher
The Cutelyst Dispatcher.
Definition: dispatcher.h:40
Cutelyst::Action::dispatch
bool dispatch(Context *c)
Definition: action.h:94
Cutelyst::Context
The Cutelyst Context.
Definition: context.h:50
Cutelyst::Component
The Cutelyst Component base class.
Definition: component.h:38
Cutelyst::Context::execute
bool execute(Component *code)
Definition: context.cpp:415
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Cutelyst::Action
This class represents a Cutelyst Action.
Definition: action.h:47
Cutelyst::ActionList
QVector< Action * > ActionList
Definition: action.h:166