Cutelyst  1.7.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:
56  explicit Action(QObject *parent = nullptr);
57  virtual ~Action();
58 
59  virtual Modifiers modifiers() const override;
60 
66  QMap<QString, QString> attributes() const;
67 
75  QString attribute(const QString &name, const QString &defaultValue = QString()) const;
76 
81  void setAttributes(const QMap<QString, QString> &attributes);
82 
86  QString className() const;
87 
91  Controller* controller() const;
92 
96  inline bool dispatch(Context *c) { return c->execute(this); }
97 
102  virtual bool match(int numberOfArgs) const;
103 
114  virtual bool matchCaptures(int numberOfCaptures) const;
115 
119  QString ns() const;
120 
126  virtual qint8 numberOfArgs() const;
127 
132  virtual qint8 numberOfCaptures() const;
133 
134 protected:
135  ActionPrivate *d_ptr;
136  friend class Dispatcher;
137  friend class ControllerPrivate;
138 
142  virtual bool doExecute(Context *c) override;
143 
147  void setMethod(const QMetaMethod &method);
148 
152  void setController(Controller *controller);
153 
157  void setupAction(const QVariantHash &args, Application *app);
158 
159 private:
160  Q_DECLARE_PRIVATE(Action)
161 };
162 
164 typedef QVector<Action*> ActionList;
165 
166 }
167 
168 #endif // CUTELYST_ACTION_H
QVector< Action * > ActionList
Definition: action.h:164
bool dispatch(Context *c)
Definition: action.h:96
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:56
The Cutelyst Dispatcher.
Definition: dispatcher.h:41