Cutelyst  2.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 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();
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  ActionPrivate *d_ptr;
134  friend class Dispatcher;
135  friend class ControllerPrivate;
136 
140  virtual bool doExecute(Context *c) override;
141 
145  void setMethod(const QMetaMethod &method);
146 
150  void setController(Controller *controller);
151 
155  void setupAction(const QVariantHash &args, Application *app);
156 
157 private:
158  Q_DECLARE_PRIVATE(Action)
159 };
160 
162 typedef QVector<Action*> ActionList;
163 
164 }
165 
166 #endif // CUTELYST_ACTION_H
QVector< Action * > ActionList
Definition: action.h:162
bool dispatch(Context *c)
Definition: action.h:94
The Cutelyst Component base class.
Definition: component.h:38
This class represents a Cutelyst Action.
Definition: action.h:47
The Cutelyst Context.
Definition: context.h:50
Cutelyst Controller base class
Definition: controller.h:102
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
bool execute(Component *code)
Definition: context.cpp:356
The Cutelyst Application.
Definition: application.h:55
The Cutelyst Dispatcher.
Definition: dispatcher.h:40