6 #include "controller.h" 7 #include "dispatchtypepath_p.h" 12 #include <QRegularExpression> 18 , d_ptr(new DispatchTypePathPrivate)
35 auto keys = d->paths.keys();
40 for (
const auto &path : keys) {
41 const auto paths = d->paths.
value(path);
42 for (
Action *action : paths.actions) {
51 _path.
replace(multipleSlashes, u
"/"_qs);
58 table.
append({_path, privateName});
62 return Utils::buildTable(table, {u
"Path"_qs, u
"Private"_qs}, u
"Loaded Path actions:"_qs);
70 auto it = d->paths.constFind(path);
71 if (it == d->paths.constEnd()) {
76 int numberOfArgs = args.
size();
77 for (
Action *action : it->actions) {
106 const auto range = attributes.
equal_range(u
"Path"_qs);
107 for (
auto i = range.first; i != range.second; ++i) {
108 if (d->registerPath(*i, action)) {
120 return !d->paths.isEmpty();
128 auto it = attributes.
constFind(u
"Path"_qs);
129 if (it != attributes.constEnd()) {
130 const QString &path = it.value();
143 bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
153 auto it = paths.find(_path);
154 if (it != paths.end()) {
156 auto &actions = it->actions;
157 for (
const Action *regAction : actions) {
158 if (regAction->numberOfArgs() == actionNumberOfArgs) {
159 qCCritical(CUTELYST_DISPATCHER_PATH)
160 <<
"Not registering Action" << action->
name() <<
"of controller" 162 << regAction->name() <<
"of controller" 163 << regAction->controller()->objectName();
168 actions.push_back(action);
169 std::sort(actions.begin(), actions.end(), [](
Action *a,
Action *b) ->
bool {
173 paths.insert(_path, DispatchTypePathReplacement{_path, {action}});
178 #include "moc_dispatchtypepath.cpp" Controller * controller() const noexcept
ParamsMultiMap attributes() const noexcept
QString & append(QChar ch)
QMultiMap::const_iterator constFind(const Key &key) const const
DispatchTypePath(QObject *parent=nullptr)
QString & prepend(QChar ch)
bool registerAction(Action *action) override
int compare(QStringView str, Qt::CaseSensitivity cs) const const
void setupMatchedAction(Context *c, Action *action) const
void setMatch(const QString &match)
QString reverse() const noexcept
qsizetype size() const const
This class represents a Cutelyst Action.
T value(qsizetype i) const const
QPair< QMultiMap::iterator, QMultiMap::iterator > equal_range(const Key &key)
void append(QList::parameter_type value)
bool isEmpty() const const
bool isEmpty() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString name() const noexcept
The Cutelyst namespace holds all public Cutelyst API.
void setArguments(const QStringList &arguments)
Describes a path dispatch type.
QByteArray list() const override
QString & replace(qsizetype position, qsizetype n, QChar after)
Abstract class to described a dispatch type.
QString uriForAction(Action *action, const QStringList &captures) const override
~DispatchTypePath() override
virtual qint8 numberOfArgs() const
QString attribute(const QString &name, const QString &defaultValue={}) const
MatchType match(Context *c, QStringView path, const QStringList &args) const override