diff --git a/libdiscover/utils.h b/libdiscover/utils.h index 67ec36f9..6aafbfe5 100644 --- a/libdiscover/utils.h +++ b/libdiscover/utils.h @@ -1,86 +1,86 @@ /*************************************************************************** * Copyright ?? 2012 Aleix Pol Gonzalez * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #ifndef UTILS_H #define UTILS_H #include #include #include class OneTimeAction : public QObject { public: OneTimeAction(std::function func, QObject* parent) : QObject(parent), m_function(func) {} void trigger() { m_function(); deleteLater(); } private: std::function m_function; }; template static T kTransform(const Q &input, _UnaryOperation op) { T ret; ret.reserve(input.size()); for(const auto& v : input) { ret += op(v); } return ret; } template static T kFilter(const Q &input, _UnaryOperation op) { T ret; for(const auto& v : input) { if (op(v)) ret += v; } return ret; } template static int kIndexOf(const Q& list, W func) { int i = 0; for (auto it = list.constBegin(), itEnd = list.constEnd(); it!=itEnd; ++it) { if (func(*it)) return i; ++i; } return -1; } class ElapsedDebug : private QElapsedTimer { public: ElapsedDebug(const QString &name = QStringLiteral("")) : m_name(name) { start(); } ~ElapsedDebug() { qDebug("elapsed %s: %lld!", m_name.toUtf8().constData(), elapsed()); } - void step(const QString &step) { qDebug("step(%s) %s: %lld!", qPrintable(step), m_name.toUtf8().constData(), elapsed()); } + void step(const QString &step) { qDebug("step %s(%s): %lld!", m_name.toUtf8().constData(), qPrintable(step), elapsed()); } QString m_name; }; #endif