7#include "dispatchtypepath_p.h"
12#include <QRegularExpression>
19 , d_ptr(new DispatchTypePathPrivate)
36 auto keys = d->paths.keys();
40 for (
const auto &path : std::as_const(keys)) {
41 const auto paths = d->paths.
value(path);
42 for (
Action *action : paths.actions) {
44 if (action->attribute(u
"Args"_s).isEmpty()) {
47 for (
int i = 0; i < action->numberOfArgs(); ++i) {
51 _path.
replace(multipleSlashes, u
"/"_s);
53 QString privateName = action->reverse();
58 table.
append({_path, privateName});
62 return Utils::buildTable(table,
67 u
"Loaded Path actions:"_s);
75 auto it = d->paths.constFind(path);
76 if (it == d->paths.constEnd()) {
81 int numberOfArgs = args.
size();
82 for (
Action *action : it->actions) {
86 if (action->numberOfArgs() == numberOfArgs) {
92 }
else if (action->numberOfArgs() == -1 && !c->
action()) {
111 const auto range = attributes.
equal_range(u
"Path"_s);
112 for (
auto i = range.first; i != range.second; ++i) {
113 if (d->registerPath(*i, action)) {
125 return !d->paths.isEmpty();
133 auto it = attributes.
constFind(u
"Path"_s);
134 if (it != attributes.constEnd()) {
135 const QString &path = it.value();
148bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
158 auto it = paths.find(_path);
159 if (it != paths.end()) {
161 auto &actions = it->actions;
162 bool conflict = std::ranges::any_of(actions, [&](
const Action *regAction) {
164 qCCritical(CUTELYST_DISPATCHER_PATH)
165 <<
"Not registering Action" << action->name() <<
"of controller"
166 << action->controller()->objectName() <<
"because it conflicts with"
167 << regAction->name() <<
"of controller"
168 << regAction->controller()->objectName();
177 actions.push_back(action);
178 std::ranges::sort(actions, [](
const Action *a,
const Action *b) ->
bool {
183 DispatchTypePathReplacement{
191#include "moc_dispatchtypepath.cpp"
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const
ParamsMultiMap attributes() const noexcept
Describes a path dispatch type.
~DispatchTypePath() override
DispatchTypePath(QObject *parent=nullptr)
QByteArray list() const override
MatchType match(Context *c, QStringView path, const QStringList &args) const override
QString uriForAction(Action *action, const QStringList &captures) const override
bool registerAction(Action *action) override
Abstract class to described a dispatch type.
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.
void append(QList::parameter_type value)
bool isEmpty() const const
qsizetype size() const const
T value(qsizetype i) const const
QMultiMap::const_iterator constFind(const Key &key) const const
QPair< QMultiMap::iterator, QMultiMap::iterator > equal_range(const Key &key)
QString & append(QChar ch)
bool isEmpty() const const
QString & prepend(QChar ch)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int compare(QChar ch) const const