18 #include "dispatchtypepath_p.h"
21 #include "controller.h"
25 #include <QRegularExpression>
32 d_ptr(new DispatchTypePathPrivate)
36 DispatchTypePath::~DispatchTypePath()
51 for (
const QString &path : keys) {
52 const auto paths = d->paths.value(path);
53 for (
Action *action : paths) {
58 for (
int i = 0; i < action->numberOfArgs(); ++i) {
64 QString privateName = action->reverse();
69 table.
append({ _path, privateName });
83 _path = QStringLiteral(
"/");
86 const auto it = d->paths.constFind(_path);
87 if (it == d->paths.constEnd()) {
92 int numberOfArgs = args.
size();
93 for (
Action *action : it.value()) {
97 if (action->numberOfArgs() == numberOfArgs) {
98 Request *request = c->request();
103 }
else if (action->numberOfArgs() == -1 &&
107 Request *request = c->request();
124 for (
auto i = range.first; i != range.second; ++i) {
125 if (d->registerPath(*i, action)) {
137 return !d->paths.isEmpty();
145 auto it = attributes.
constFind(QStringLiteral(
"Path"));
146 if (it != attributes.constEnd()) {
147 const QString &path = it.value();
149 ret = QStringLiteral(
"/");
160 bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
167 _path = QStringLiteral(
"/");
170 auto it = paths.find(_path);
171 if (it != paths.end()) {
173 for (
const Action *regAction : it.value()) {
174 if (regAction->numberOfArgs() == actionNumberOfArgs) {
175 qCCritical(CUTELYST_DISPATCHER_PATH) <<
"Not registering Action"
179 <<
"because it conflicts with"
182 << regAction->controller()->objectName();
187 it.value().push_back(action);
188 std::sort(it.value().begin(), it.value().end(), [](
Action *a,
Action *b) ->
bool {
189 return a->numberOfArgs() < b->numberOfArgs();
192 paths.insert(_path, { action });
197 #include "moc_dispatchtypepath.cpp"
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const
ParamsMultiMap attributes() const
Controller * controller() const
virtual MatchType match(Context *c, const QString &path, const QStringList &args) const override
DispatchTypePath(QObject *parent=nullptr)
virtual QByteArray list() const override
list the registered actions To be implemented by subclasses
virtual bool inUse() override
virtual QString uriForAction(Action *action, const QStringList &captures) const override
virtual bool registerAction(Action *action) override
registerAction
void setupMatchedAction(Context *c, Action *action) const
void setArguments(const QStringList &arguments)
void setMatch(const QString &match)
The Cutelyst namespace holds all public Cutelyst API.
bool isEmpty() const const
QPair< QMap::iterator, QMap::iterator > equal_range(const Key &key)
typename QMap< Key, T >::const_iterator constFind(const Key &key, const T &value) const const
QString & append(QChar ch)
bool isEmpty() const const
QString & prepend(QChar ch)
QString & remove(int position, int n)
QString & replace(int position, int n, QChar after)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
void sort(Qt::CaseSensitivity cs)
void append(const T &value)