Cutelyst  1.5.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 Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CUTELYST_ACTION_H
21 #define CUTELYST_ACTION_H
22 
23 #include <QtCore/QStringList>
24 #include <QtCore/QMetaMethod>
25 
26 #include <Cutelyst/cutelyst_global.h>
27 #include <Cutelyst/component.h>
28 #include <Cutelyst/context.h>
29 
30 namespace Cutelyst {
31 
32 class Controller;
33 class Dispatcher;
34 class ActionPrivate;
49 class CUTELYST_LIBRARY Action : public Component
50 {
51  Q_OBJECT
52 public:
53  explicit Action(QObject *parent = nullptr);
54  virtual ~Action();
55 
56  virtual Modifiers modifiers() const override;
57 
63  QMap<QString, QString> attributes() const;
64 
72  QString attribute(const QString &name, const QString &defaultValue = QString()) const;
73 
78  void setAttributes(const QMap<QString, QString> &attributes);
79 
83  QString className() const;
84 
88  Controller* controller() const;
89 
93  inline bool dispatch(Context *c) { return c->execute(this); }
94 
99  virtual bool match(int numberOfArgs) const;
100 
111  virtual bool matchCaptures(int numberOfCaptures) const;
112 
116  QString ns() const;
117 
123  virtual qint8 numberOfArgs() const;
124 
129  virtual qint8 numberOfCaptures() const;
130 
131 protected:
132  ActionPrivate *d_ptr;
133  friend class Dispatcher;
134  friend class ControllerPrivate;
135 
139  virtual 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 
160 typedef QVector<Action*> ActionList;
161 
162 }
163 
164 #endif // CUTELYST_ACTION_H
bool dispatch(Context *c)
Definition: action.h:93
The Cutelyst Component base class.
Definition: component.h:40
This class represents a Cutelyst Action.
Definition: action.h:49
bool execute(Component *code)
The Cutelyst Context.
Definition: context.h:52
Cutelyst Controller base class
Definition: controller.h:104
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:55
The Cutelyst Dispatcher.
Definition: dispatcher.h:41