Verified Commit 134837ca authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

More C++17 cleanup

parent 97d1db7c
......@@ -76,11 +76,11 @@ void SetupTest::setupAgents()
mAgentsCreated = true;
Config *config = Config::instance();
const auto agents = config->agents();
for (const auto agent : agents) {
qCDebug(AKONADITEST_LOG) << "Creating agent" << agent.first << "...";
for (const auto &[instance, sync]: agents) {
qCDebug(AKONADITEST_LOG) << "Creating agent" << instance << "...";
++mSetupJobCount;
Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob(agent.first, this);
job->setProperty("sync", agent.second);
Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob(instance, this);
job->setProperty("sync", sync);
connect(job, &Akonadi::AgentInstanceCreateJob::result, this, &SetupTest::agentCreationResult);
job->start();
}
......
......@@ -53,7 +53,7 @@ private Q_SLOTS:
QFETCH(QString, name);
QFETCH(bool, shouldThrow);
QPair<QString, QString> p;
std::pair<QString, QString> p;
bool didThrow = false;
try {
p = PartTypeHelper::parseFqName(fqName);
......
......@@ -277,26 +277,26 @@ void SearchTaskManager::searchLoop()
continue;
}
QVector<QPair<QString, qint64> >::iterator it = task->queries.begin();
for (; it != task->queries.end();) {
for (auto it = task->queries.begin(); it != task->queries.end();) {
if (!mRunningTasks.contains(it->first)) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "\t Sending query for collection" << it->second << "to resource" << it->first;
const auto &[resource, colId] = *it;
qCDebug(AKONADISERVER_SEARCH_LOG) << "\t Sending query for collection" << colId << "to resource" << resource;
ResourceTask *rTask = new ResourceTask;
rTask->resourceId = it->first;
rTask->collectionId = it->second;
rTask->resourceId = resource;
rTask->collectionId = colId;
rTask->parentTask = task;
rTask->timestamp = QDateTime::currentMSecsSinceEpoch();
mRunningTasks.insert(it->first, rTask);
mRunningTasks.insert(resource, rTask);
mInstancesLock.lock();
AgentSearchInstance *instance = mInstances.value(it->first);
AgentSearchInstance *instance = mInstances.value(resource);
if (!instance) {
mInstancesLock.unlock();
// Resource disappeared in the meanwhile
continue;
}
instance->search(task->id, task->query, it->second);
instance->search(task->id, task->query, colId);
mInstancesLock.unlock();
task->sharedLock.lock();
......
......@@ -547,11 +547,11 @@ bool DbUpdater::complexUpdate_36()
continue;
}
const auto result = recreateTableWithForeignKeys(table);
if (!result.first) {
const auto &[ok, query] = recreateTableWithForeignKeys(table);
if (!ok) {
qCCritical(AKONADISERVER_LOG, "SQL error when updating table %s", qUtf8Printable(table.name));
qCCritical(AKONADISERVER_LOG, "Query: %s", qUtf8Printable(result.second.executedQuery()));
qCCritical(AKONADISERVER_LOG, "Error: %s", qUtf8Printable(result.second.lastError().text()));
qCCritical(AKONADISERVER_LOG, "Query: %s", qUtf8Printable(query.executedQuery()));
qCCritical(AKONADISERVER_LOG, "Error: %s", qUtf8Printable(query.lastError().text()));
return false;
}
}
......@@ -559,11 +559,11 @@ bool DbUpdater::complexUpdate_36()
const auto relations = schema.relations();
for (const auto &relation : relations) {
const RelationTableDescription table(relation);
const auto result = recreateTableWithForeignKeys(table);
if (!result.first) {
const auto &[ok, query] = recreateTableWithForeignKeys(table);
if (!ok) {
qCCritical(AKONADISERVER_LOG, "SQL error when updating relation table %s", qUtf8Printable(table.name));
qCCritical(AKONADISERVER_LOG, "Query: %s", qUtf8Printable(result.second.executedQuery()));
qCCritical(AKONADISERVER_LOG, "Error: %s", qUtf8Printable(result.second.lastError().text()));
qCCritical(AKONADISERVER_LOG, "Query: %s", qUtf8Printable(query.executedQuery()));
qCCritical(AKONADISERVER_LOG, "Error: %s", qUtf8Printable(query.lastError().text()));
return false;
}
}
......
......@@ -24,21 +24,22 @@
#include <QStringList>
#include <tuple>
using namespace Akonadi::Server;
QPair< QString, QString > PartTypeHelper::parseFqName(const QString &fqName)
std::pair<QString, QString> PartTypeHelper::parseFqName(const QString &fqName)
{
const QStringList name = fqName.split(QLatin1Char(':'), QString::SkipEmptyParts);
if (name.size() != 2) {
throw PartTypeException("Invalid part type name.");
}
return qMakePair(name.first(), name.last());
return {name.first(), name.last()};
}
PartType PartTypeHelper::fromFqName(const QString &fqName)
{
const QPair<QString, QString> p = parseFqName(fqName);
return fromFqName(p.first, p.second);
return std::apply(qOverload<const QString &, const QString &>(PartTypeHelper::fromFqName), parseFqName(fqName));
}
PartType PartTypeHelper::fromFqName(const QByteArray &fqName)
......@@ -57,11 +58,11 @@ PartType PartTypeHelper::fromFqName(const QString &ns, const QString &name)
Query::Condition PartTypeHelper::conditionFromFqName(const QString &fqName)
{
const QPair<QString, QString> p = parseFqName(fqName);
const auto [ns, name] = parseFqName(fqName);
Query::Condition c;
c.setSubQueryMode(Query::And);
c.addValueCondition(PartType::nsFullColumnName(), Query::Equals, p.first);
c.addValueCondition(PartType::nameFullColumnName(), Query::Equals, p.second);
c.addValueCondition(PartType::nsFullColumnName(), Query::Equals, ns);
c.addValueCondition(PartType::nameFullColumnName(), Query::Equals, name);
return c;
}
......
......@@ -91,7 +91,7 @@ Query::Condition conditionFromFqNames(const T<QByteArray> &fqNames)
* @throws PartTypeException if @p fqName does not match the NS:NAME schema
* @internal
*/
QPair<QString, QString> parseFqName(const QString &fqName);
std::pair<QString, QString> parseFqName(const QString &fqName);
/**
* Returns full part name
......
......@@ -184,11 +184,11 @@ void QueryBuilder::sqliteAdaptUpdateJoin(Query::Condition &condition)
return;
}
const QPair<JoinType, Query::Condition> joinCondition = mJoins.value(table);
const auto &[type, joinCondition] = mJoins.value(table);
QueryBuilder qb(table, Select);
qb.addColumn(condition.mColumn);
qb.addCondition(joinCondition.second);
qb.addCondition(joinCondition);
// Convert the subquery to string
condition.mColumn.reserve(1024);
......@@ -218,8 +218,8 @@ void QueryBuilder::buildQuery(QString *statement)
*statement += QLatin1String(" FROM ");
*statement += mTable;
for (const QString &joinedTable : qAsConst(mJoinedTables)) {
const QPair<JoinType, Query::Condition> &join = mJoins.value(joinedTable);
switch (join.first) {
const auto &[joinType, joinCond] = mJoins.value(joinedTable);
switch (joinType) {
case LeftJoin:
*statement += QLatin1String(" LEFT JOIN ");
break;
......@@ -229,7 +229,7 @@ void QueryBuilder::buildQuery(QString *statement)
}
*statement += joinedTable;
*statement += QLatin1String(" ON ");
buildWhereCondition(statement, join.second);
buildWhereCondition(statement, joinCond);
}
break;
case Insert: {
......@@ -259,9 +259,9 @@ void QueryBuilder::buildQuery(QString *statement)
// put the ON condition into the WHERE part of the UPDATE query
if (mDatabaseType != DbType::Sqlite) {
for (const QString &table : qAsConst(mJoinedTables)) {
const QPair< JoinType, Query::Condition > &join = mJoins.value(table);
Q_ASSERT(join.first == InnerJoin);
whereCondition.addCondition(join.second);
const auto &[joinType, joinCond] = mJoins.value(table);
Q_ASSERT(joinType == InnerJoin);
whereCondition.addCondition(joinCond);
}
} else {
// Note: this will modify the whereCondition
......@@ -280,10 +280,10 @@ void QueryBuilder::buildQuery(QString *statement)
*statement += QLatin1String(" SET ");
Q_ASSERT_X(mColumnValues.count() >= 1, "QueryBuilder::exec()", "At least one column needs to be changed");
for (int i = 0, c = mColumnValues.size(); i < c; ++i) {
const QPair<QString, QVariant> &p = mColumnValues.at(i);
*statement += p.first;
const auto &[column, value] = mColumnValues.at(i);
*statement += column;
*statement += QLatin1String(" = ");
bindValue(statement, p.second);
bindValue(statement, value);
if (i + 1 < c) {
*statement += QLatin1String(", ");
}
......@@ -324,9 +324,9 @@ void QueryBuilder::buildQuery(QString *statement)
Q_ASSERT_X(mType == Select, "QueryBuilder::exec()", "Order statements are only valid for SELECT queries");
*statement += QLatin1String(" ORDER BY ");
for (int i = 0, c = mSortColumns.size(); i < c; ++i) {
const QPair<QString, Query::SortOrder> &order = mSortColumns.at(i);
*statement += order.first;
*statement += sortOrderToString(order.second);
const auto &[column, order] = mSortColumns.at(i);
*statement += column;
*statement += sortOrderToString(order);
if (i + 1 < c) {
*statement += QLatin1String(", ");
}
......
......@@ -27,10 +27,6 @@ namespace AkTraits {
namespace detail {
/// Helpers from C++17
template<typename ...>
using void_t = void;
template<typename ...>
struct conjunction : std::true_type {};
template<typename T>
......@@ -39,13 +35,13 @@ namespace detail {
struct conjunction<T, Ts...> : std::conditional_t<bool(T::value), conjunction<Ts...>, T> {};
#define DECLARE_HAS_MEBER_TYPE(type_name) \
template<typename T, typename U = void_t<>> \
template<typename T, typename U = std::void_t<>> \
struct hasMember_##type_name { \
static constexpr bool value = false; \
}; \
\
template<typename T> \
struct hasMember_##type_name<T, void_t<typename T:: type_name>> : std::true_type {};
struct hasMember_##type_name<T, std::void_t<typename T:: type_name>> : std::true_type {};
DECLARE_HAS_MEBER_TYPE(value_type)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment