Cutelyst  1.11.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 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_COMPONENT_H
19 #define CUTELYST_COMPONENT_H
20 
21 #include <QtCore/qobject.h>
22 
23 #include <Cutelyst/cutelyst_global.h>
24 
25 namespace Cutelyst {
26 
27 class Application;
28 class Context;
29 class Controller;
30 class Dispatcher;
31 class ComponentPrivate;
32 
38 class CUTELYST_LIBRARY Component : public QObject
39 {
40  Q_OBJECT
41  Q_DECLARE_PRIVATE(Component)
42  Q_FLAGS(Modifiers)
43 public:
45  enum Modifier {
46  None = 0 << 1,
47  OnlyExecute = 1 << 1,
48  BeforeExecute = 2 << 1,
49  AroundExecute = 3 << 1,
50  AfterExecute = 4 << 1,
51  };
52  Q_ENUM(Modifier)
53  Q_DECLARE_FLAGS(Modifiers, Modifier)
54 
55 
60  explicit Component(QObject *parent = nullptr);
61  virtual ~Component();
62 
66  virtual Modifiers modifiers() const;
67 
71  QString name() const;
72 
76  void setName(const QString &name);
77 
81  inline QString reverse() const;
82 
86  inline void setReverse(const QString &reverse);
87 
94  virtual bool init(Application *application, const QVariantHash &args);
95 
99  bool execute(Context *c);
100 
101 protected:
105  virtual bool beforeExecute(Context *c);
106 
111  virtual bool aroundExecute(Context *c, QStack<Component *> stack);
112 
116  virtual bool afterExecute(Context *c);
117 
121  virtual bool doExecute(Context *c);
122 
126  void applyRoles(const QStack<Component *> &roles);
127 
134  virtual bool dispatcherReady(const Dispatcher *dispatch, Controller *controller);
135 
136 protected:
137  friend class Controller;
138  ComponentPrivate *d_ptr;
139 };
140 
141 inline QString Component::reverse() const {
142  return objectName();
143 }
144 inline void Component::setReverse(const QString &reverse) {
145  setObjectName(reverse);
146 }
147 
148 }
149 
150 #endif // CUTELYST_COMPONENT_H
The Cutelyst Component base class.
Definition: component.h:38
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
The Cutelyst Application.
Definition: application.h:54
QString reverse() const
Definition: component.h:141
The Cutelyst Dispatcher.
Definition: dispatcher.h:40
void setReverse(const QString &reverse)
Definition: component.h:144