6 #include "controller.h" 7 #include "dispatchtypepath_p.h" 12 #include <QRegularExpression> 18 , d_ptr(new DispatchTypePathPrivate)
22 DispatchTypePath::~DispatchTypePath()
37 for (
const QString &path : keys) {
38 const auto paths = d->paths.value(path);
39 for (
Action *action : paths) {
44 for (
int i = 0; i < action->numberOfArgs(); ++i) {
50 QString privateName = action->reverse();
55 table.
append({_path, privateName});
59 return Utils::buildTable(table,
71 _path = QStringLiteral(
"/");
74 const auto it = d->paths.constFind(_path);
75 if (it == d->paths.constEnd()) {
80 int numberOfArgs = args.
size();
81 for (
Action *action : it.value()) {
85 if (action->numberOfArgs() == numberOfArgs) {
86 Request *request = c->request();
91 }
else if (action->numberOfArgs() == -1 && !c->action()) {
94 Request *request = c->request();
111 for (
auto i = range.first; i != range.second; ++i) {
112 if (d->registerPath(*i, action)) {
124 return !d->paths.isEmpty();
132 auto it = attributes.
constFind(QStringLiteral(
"Path"));
133 if (it != attributes.constEnd()) {
134 const QString &path = it.value();
136 ret = QStringLiteral(
"/");
147 bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
154 _path = QStringLiteral(
"/");
157 auto it = paths.find(_path);
158 if (it != paths.end()) {
160 for (
const Action *regAction : it.value()) {
161 if (regAction->numberOfArgs() == actionNumberOfArgs) {
162 qCCritical(CUTELYST_DISPATCHER_PATH)
163 <<
"Not registering Action" << action->
name() <<
"of controller" 165 << regAction->name() <<
"of controller" 166 << regAction->controller()->objectName();
171 it.value().push_back(action);
172 std::sort(it.value().begin(), it.value().end(), [](
Action *a,
Action *b) ->
bool {
176 paths.insert(_path, {action});
181 #include "moc_dispatchtypepath.cpp" ParamsMultiMap attributes() const noexcept
virtual bool inUse() override
QString & append(QChar ch)
typename QMap< Key, T >::const_iterator constFind(const Key &key, const T &value) const const
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
void setupMatchedAction(Context *c, Action *action) const
QString & remove(int position, int n)
void setMatch(const QString &match)
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const noexcept
bool isEmpty() const const
bool isEmpty() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
Controller * controller() const
The Cutelyst namespace holds all public Cutelyst API.
void setArguments(const QStringList &arguments)
virtual QByteArray list() const override
list the registered actions To be implemented by subclasses
QPair< QMap::iterator, QMap::iterator > equal_range(const Key &key)
QString & replace(int position, int n, QChar after)
virtual QString uriForAction(Action *action, const QStringList &captures) const override
void sort(Qt::CaseSensitivity cs)