Cutelyst  1.5.0
component.h
1 /*
2  * Copyright (C) 2014-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_COMPONENT_H
21 #define CUTELYST_COMPONENT_H
22 
23 #include <QtCore/qobject.h>
24 
25 #include <Cutelyst/cutelyst_global.h>
26 
27 namespace Cutelyst {
28 
29 class Application;
30 class Context;
31 class Controller;
32 class Dispatcher;
33 class ComponentPrivate;
34 
40 class CUTELYST_LIBRARY Component : public QObject
41 {
42  Q_OBJECT
43  Q_DECLARE_PRIVATE(Component)
44  Q_FLAGS(Modifiers)
45 public:
46  enum Modifier {
47  None = 0 << 1,
48  OnlyExecute = 1 << 1,
49  BeforeExecute = 2 << 1,
50  AroundExecute = 3 << 1,
51  AfterExecute = 4 << 1,
52  };
53  Q_ENUM(Modifier)
54  Q_DECLARE_FLAGS(Modifiers, Modifier)
55 
56  explicit Component(QObject *parent = nullptr);
57  virtual ~Component();
58 
59  virtual Modifiers modifiers() const;
60 
65  QString name() const;
66 
67  void setName(const QString &name);
68 
73  inline QString reverse() const;
74 
75  inline void setReverse(const QString &reverse);
76 
83  virtual bool init(Application *application, const QVariantHash &args);
84 
85  bool execute(Context *c);
86 
87 protected:
88  virtual bool beforeExecute(Context *c);
89 
90  virtual bool aroundExecute(Context *c, QStack<Component *> stack);
91 
92  virtual bool afterExecute(Context *c);
93 
94  virtual bool doExecute(Context *c);
95 
96  void applyRoles(const QStack<Component *> &roles);
97 
104  virtual bool dispatcherReady(const Dispatcher *dispatch, Controller *controller);
105 
106 protected:
107  friend class Controller;
108  ComponentPrivate *d_ptr;
109 };
110 
111 inline QString Component::reverse() const {
112  return objectName();
113 }
114 inline void Component::setReverse(const QString &reverse) {
115  setObjectName(reverse);
116 }
117 
118 }
119 
120 #endif // CUTELYST_COMPONENT_H
The Cutelyst Component base class.
Definition: component.h:40
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
QString reverse() const
name
Definition: component.h:111
The Cutelyst Dispatcher.
Definition: dispatcher.h:41