7#include "dispatchtypepath_p.h"
12#include <QRegularExpression>
19 , d_ptr(new DispatchTypePathPrivate)
36 auto keys = d->paths.keys();
39 return a.compare(b, Qt::CaseInsensitive) < 0;
41 for (
const auto &path : keys) {
42 const auto paths = d->paths.value(path);
43 for (
Action *action : paths.actions) {
52 _path.
replace(multipleSlashes, u
"/"_s);
59 table.
append({_path, privateName});
63 return Utils::buildTable(table, {u
"Path"_s, u
"Private"_s}, u
"Loaded Path actions:"_s);
71 auto it = d->paths.constFind(path);
72 if (it == d->paths.constEnd()) {
77 int numberOfArgs = args.
size();
78 for (
Action *action : it->actions) {
107 const auto range = attributes.
equal_range(u
"Path"_s);
108 for (
auto i = range.first; i != range.second; ++i) {
109 if (d->registerPath(*i, action)) {
121 return !d->paths.isEmpty();
129 auto it = attributes.
constFind(u
"Path"_s);
130 if (it != attributes.constEnd()) {
131 const QString &path = it.value();
144bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
154 auto it = paths.find(_path);
155 if (it != paths.end()) {
157 auto &actions = it->actions;
158 for (
const Action *regAction : actions) {
159 if (regAction->numberOfArgs() == actionNumberOfArgs) {
160 qCCritical(CUTELYST_DISPATCHER_PATH)
161 <<
"Not registering Action" << action->
name() <<
"of controller"
163 << regAction->name() <<
"of controller"
164 << regAction->controller()->objectName();
169 actions.push_back(action);
170 std::sort(actions.begin(), actions.end(), [](
Action *a,
Action *b) ->
bool {
171 return a->numberOfArgs() < b->numberOfArgs();
174 paths.insert(_path, DispatchTypePathReplacement{_path, {action}});
179#include "moc_dispatchtypepath.cpp"
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const
ParamsMultiMap attributes() const noexcept
Controller * controller() const noexcept
QString attribute(const QString &name, const QString &defaultValue={}) const
QString reverse() const noexcept
QString name() const noexcept
~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
DispatchType(QObject *parent=nullptr)
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< T > &&value)
bool isEmpty() const const
qsizetype size() const const
QMultiMap< Key, T >::const_iterator constFind(const Key &key) const const
std::pair< QMultiMap< Key, T >::iterator, QMultiMap< Key, T >::iterator > equal_range(const Key &key)
QObject * parent() const const
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