diff options
author | hjk <hjk@qt.io> | 2018-04-23 13:34:11 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2018-04-24 05:59:57 +0000 |
commit | 22428af7507cda230212ee0032596e53d18d73a7 (patch) | |
tree | c73471e0f17254a051493aec9b96981204a0c973 /src/libs/utils | |
parent | 58f0a7a3ddb134be1c50e72c200283d43a5c32e6 (diff) |
Utils: Use free functions in OsSpecificAspects
Generates a bit less code in debug mode and is easier to read IMNSHO.
Change-Id: Ib9c0b9a0c058327facff16600a7014207167b050
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/libs/utils')
-rw-r--r-- | src/libs/utils/environment.cpp | 6 | ||||
-rw-r--r-- | src/libs/utils/hostosinfo.h | 10 | ||||
-rw-r--r-- | src/libs/utils/osspecificaspects.h | 63 |
3 files changed, 38 insertions, 41 deletions
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index fadaaac7598..c3b0f13f7c6 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -325,13 +325,13 @@ void Environment::prependOrSet(const QString&key, const QString &value, const QS void Environment::appendOrSetPath(const QString &value) { appendOrSet("PATH", QDir::toNativeSeparators(value), - QString(OsSpecificAspects(m_osType).pathListSeparator())); + QString(OsSpecificAspects::pathListSeparator(m_osType))); } void Environment::prependOrSetPath(const QString &value) { prependOrSet("PATH", QDir::toNativeSeparators(value), - QString(OsSpecificAspects(m_osType).pathListSeparator())); + QString(OsSpecificAspects::pathListSeparator(m_osType))); } void Environment::prependOrSetLibrarySearchPath(const QString &value) @@ -496,7 +496,7 @@ FileName Environment::searchInPath(const QString &executable, FileNameList Environment::path() const { const QStringList pathComponents = value("PATH") - .split(OsSpecificAspects(m_osType).pathListSeparator(), QString::SkipEmptyParts); + .split(OsSpecificAspects::pathListSeparator(m_osType), QString::SkipEmptyParts); return Utils::transform(pathComponents, &FileName::fromUserInput); } diff --git a/src/libs/utils/hostosinfo.h b/src/libs/utils/hostosinfo.h index 23d1b2b6508..541419e432e 100644 --- a/src/libs/utils/hostosinfo.h +++ b/src/libs/utils/hostosinfo.h @@ -75,7 +75,7 @@ public: static QString withExecutableSuffix(const QString &executable) { - return hostOsAspects().withExecutableSuffix(executable); + return OsSpecificAspects::withExecutableSuffix(hostOs(), executable); } static void setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity); @@ -85,24 +85,22 @@ public: { return m_useOverrideFileNameCaseSensitivity ? m_overrideFileNameCaseSensitivity - : hostOsAspects().fileNameCaseSensitivity(); + : OsSpecificAspects::fileNameCaseSensitivity(hostOs()); } static QChar pathListSeparator() { - return hostOsAspects().pathListSeparator(); + return OsSpecificAspects::pathListSeparator(hostOs()); } static Qt::KeyboardModifier controlModifier() { - return hostOsAspects().controlModifier(); + return OsSpecificAspects::controlModifier(hostOs()); } static bool canCreateOpenGLContext(QString *errorMessage); private: - static OsSpecificAspects hostOsAspects() { return OsSpecificAspects(hostOs()); } - static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity; static bool m_useOverrideFileNameCaseSensitivity; }; diff --git a/src/libs/utils/osspecificaspects.h b/src/libs/utils/osspecificaspects.h index e588c54fc02..58a4234dbac 100644 --- a/src/libs/utils/osspecificaspects.h +++ b/src/libs/utils/osspecificaspects.h @@ -38,44 +38,43 @@ namespace Utils { // Add more as needed. enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOther }; -class QTCREATOR_UTILS_EXPORT OsSpecificAspects -{ -public: - OsSpecificAspects(OsType osType) : m_osType(osType) { } +namespace OsSpecificAspects { - QString withExecutableSuffix(const QString &executable) const { - QString finalName = executable; - if (m_osType == OsTypeWindows) - finalName += QLatin1String(QTC_WIN_EXE_SUFFIX); - return finalName; - } +QTCREATOR_UTILS_EXPORT inline QString withExecutableSuffix(OsType osType, const QString &executable) +{ + QString finalName = executable; + if (osType == OsTypeWindows) + finalName += QLatin1String(QTC_WIN_EXE_SUFFIX); + return finalName; +} - Qt::CaseSensitivity fileNameCaseSensitivity() const { - return m_osType == OsTypeWindows || m_osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive; - } +QTCREATOR_UTILS_EXPORT inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType) +{ + return osType == OsTypeWindows || osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive; +} - QChar pathListSeparator() const { - return QLatin1Char(m_osType == OsTypeWindows ? ';' : ':'); - } +QTCREATOR_UTILS_EXPORT inline QChar pathListSeparator(OsType osType) +{ + return QLatin1Char(osType == OsTypeWindows ? ';' : ':'); +} - Qt::KeyboardModifier controlModifier() const { - return m_osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier; - } +QTCREATOR_UTILS_EXPORT inline Qt::KeyboardModifier controlModifier(OsType osType) +{ + return osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier; +} - QString pathWithNativeSeparators(const QString &pathName) const { - if (m_osType == OsTypeWindows) { - const int pos = pathName.indexOf('/'); - if (pos >= 0) { - QString n = pathName; - std::replace(std::begin(n) + pos, std::end(n), '/', '\\'); - return n; - } +QTCREATOR_UTILS_EXPORT inline QString pathWithNativeSeparators(OsType osType, const QString &pathName) +{ + if (osType == OsTypeWindows) { + const int pos = pathName.indexOf('/'); + if (pos >= 0) { + QString n = pathName; + std::replace(std::begin(n) + pos, std::end(n), '/', '\\'); + return n; } - return pathName; } + return pathName; +} -private: - const OsType m_osType; -}; - +} // namespace OsSpecificAspects } // namespace Utils |