Cutelyst  1.8.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:
47  enum Modifier {
48  None = 0 << 1,
49  OnlyExecute = 1 << 1,
50  BeforeExecute = 2 << 1,
51  AroundExecute = 3 << 1,
52  AfterExecute = 4 << 1,
53  };
54  Q_ENUM(Modifier)
55  Q_DECLARE_FLAGS(Modifiers, Modifier)
56 
57 
62  explicit Component(QObject *parent = nullptr);
63  virtual ~Component();
64 
68  virtual Modifiers modifiers() const;
69 
73  QString name() const;
74 
78  void setName(const QString &name);
79 
83  inline QString reverse() const;
84 
88  inline void setReverse(const QString &reverse);
89 
96  virtual bool init(Application *application, const QVariantHash &args);
97 
101  bool execute(Context *c);
102 
103 protected:
107  virtual bool beforeExecute(Context *c);
108 
113  virtual bool aroundExecute(Context *c, QStack<Component *> stack);
114 
118  virtual bool afterExecute(Context *c);
119 
123  virtual bool doExecute(Context *c);
124 
128  void applyRoles(const QStack<Component *> &roles);
129 
136  virtual bool dispatcherReady(const Dispatcher *dispatch, Controller *controller);
137 
138 protected:
139  friend class Controller;
140  ComponentPrivate *d_ptr;
141 };
142 
143 inline QString Component::reverse() const {
144  return objectName();
145 }
146 inline void Component::setReverse(const QString &reverse) {
147  setObjectName(reverse);
148 }
149 
150 }
151 
152 #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:56
QString reverse() const
Definition: component.h:143
The Cutelyst Dispatcher.
Definition: dispatcher.h:41
void setReverse(const QString &reverse)
Definition: component.h:146