18 #include "dispatchtypepath_p.h"
21 #include "controller.h"
25 #include <QRegularExpression>
28 using namespace Cutelyst;
32 d_ptr(new DispatchTypePathPrivate)
36 DispatchTypePath::~DispatchTypePath()
50 keys.
sort(Qt::CaseInsensitive);
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();
123 const auto range = attributes.equal_range(
QLatin1String(
"Path"));
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 {
192 paths.insert(_path, { action });
197 #include "moc_dispatchtypepath.cpp"
void setupMatchedAction(Context *c, Action *action) const
virtual bool inUse() override
QString & append(QChar ch)
DispatchTypePath(QObject *parent=nullptr)
void append(const T &value)
QString & prepend(QChar ch)
virtual bool registerAction(Action *action) override
registerAction
virtual MatchType match(Context *c, const QString &path, const QStringList &args) const override
Controller * controller() const
virtual qint8 numberOfArgs() const
QString & remove(int position, int n)
void setMatch(const QString &match)
This class represents a Cutelyst Action.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setArguments(const QStringList &arguments)
virtual QByteArray list() const override
list the registered actions To be implemented by subclasses
QString & replace(int position, int n, QChar after)
QMap< QString, QString > attributes() const
virtual QString uriForAction(Action *action, const QStringList &captures) const override
void sort(Qt::CaseSensitivity cs)