Issue #77 Refactor to inline functions

This commit is contained in:
Mat Sutcliffe
2020-08-24 00:50:28 +01:00
parent ac454ebf3a
commit 92edbb90c2
9 changed files with 73 additions and 85 deletions

View File

@@ -1,18 +0,0 @@
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
#include "blackmisc/appstarttime.h"
namespace BlackMisc
{
const QDateTime &getApplicationStartTimeUtc()
{
static const QDateTime gApplicationStartTimeUtc = QDateTime::currentDateTimeUtc();
return gApplicationStartTimeUtc;
}
}

View File

@@ -1,24 +0,0 @@
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_APPSTARTTIME_H
#define BLACKMISC_APPSTARTTIME_H
#include "blackmisc/blackmiscexport.h"
#include <QDateTime>
namespace BlackMisc
{
//! Get the application start time in UTC.
BLACKMISC_EXPORT const QDateTime &getApplicationStartTimeUtc();
}
#endif

View File

@@ -7,7 +7,6 @@
*/
#include "blackmisc/filelogger.h"
#include "blackmisc/appstarttime.h"
#include "blackmisc/loghandler.h"
#include "blackmisc/directoryutils.h"
#include "blackconfig/buildconfig.h"
@@ -40,7 +39,7 @@ namespace BlackMisc
{
static const QString fileName = applicationName() %
QLatin1String("_") %
getApplicationStartTimeUtc().toString(QStringLiteral("yyMMddhhmmss")) %
QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyMMddhhmmss")) %
QLatin1String("_") %
QString::number(QCoreApplication::applicationPid()) %
QLatin1String(".log");

View File

@@ -24,16 +24,6 @@ namespace BlackMisc
return QThread::currentThread() == toBeTested->thread();
}
bool CThreadUtils::isApplicationThreadObjectThread(const QObject *toBeTested)
{
return qApp && toBeTested->thread() == qApp->thread();
}
bool CThreadUtils::isApplicationThread(const QThread *toBeTested)
{
return qApp && toBeTested == qApp->thread();
}
bool CThreadUtils::isCurrentThreadApplicationThread()
{
return qApp && QThread::currentThread() == qApp->thread();
@@ -47,13 +37,4 @@ namespace BlackMisc
const QString id = QString::fromStdString(oss.str());
return QStringLiteral("%1 (%2) prio %3").arg(id).arg(thread->objectName()).arg(thread->priority());
}
bool CThreadUtils::callInObjectThread(QObject *object, std::function<void()> callFunct)
{
if (!object) { return false; }
if (CThreadUtils::isCurrentThreadObjectThread(object)) { return false; }
QMetaObject::invokeMethod(object, callFunct);
return true;
}
} // ns

View File

@@ -29,20 +29,11 @@ namespace BlackMisc
//! Is the current thread the object's thread?
static bool isCurrentThreadObjectThread(const QObject *toBeTested);
//! Is the application thread the object's thread?
static bool isApplicationThreadObjectThread(const QObject *toBeTested);
//! Is the application thread the object's thread?
static bool isApplicationThread(const QThread *toBeTested);
//! Is the current thread the application thread?
static bool isCurrentThreadApplicationThread();
//! Info about current thread, for debug messages
static QString currentThreadInfo();
//! Call in object's thread if not already in object's thread
static bool callInObjectThread(QObject *object, std::function<void()> callFunct);
};
} // ns