From dc64a2ef9ff0990ebfeec845d2104f4fc9e7d1e7 Mon Sep 17 00:00:00 2001 From: cstamford Date: Fri, 30 May 2014 23:34:25 +0100 Subject: [PATCH] A bunch of minor changes to allow compilation with Visual Studio 2013. VS2013 (non-CTP) doesn't seem to allow c++11 uniform initialization syntax or noexcept. The CTP seems to compile, but the IDE shows syntax errors and it's really frustrating so I've just stripped all mention of those two from the code. Hopefully I haven't missed anything. --- src/core/object/stasset.cpp | 8 ++-- src/core/object/stasset.hpp | 2 +- src/core/object/stnpc.cpp | 4 +- src/core/object/stnpc.hpp | 3 +- src/core/object/stobject.cpp | 4 +- src/core/object/stobject.hpp | 3 +- src/core/object/sttile.cpp | 24 ++++++------ src/core/object/sttile.hpp | 10 ++--- src/core/stassetmanager.cpp | 21 +++++------ src/core/stassetmanager.hpp | 1 - src/core/stjsonfile.cpp | 32 +++++++++------- src/core/stjsonfile.hpp | 2 +- src/core/stparseable.cpp | 8 ++-- src/core/stparseable.hpp | 10 ++--- src/core/world/stlevel.cpp | 9 +++-- src/core/world/stlevel.hpp | 2 +- src/core/world/stworldfile.cpp | 6 +-- src/core/world/stworldfile.hpp | 2 +- src/gui/steditorglwidget.cpp | 9 ++--- src/gui/stmainwindow.cpp | 4 +- src/gui/stmainwindow.hpp | 7 ++-- src/main.cpp | 29 +++++++-------- src/stexception.hpp | 46 +++++++++++++---------- src/ststlspecialisation.hpp | 2 +- src/utility/stdirectoryservices.cpp | 41 +++++++++++---------- src/utility/stdirectoryservices.hpp | 7 ++-- src/utility/stlogger.cpp | 57 +++++++++++++++-------------- src/utility/stlogger.hpp | 3 +- src/utility/sttimer.cpp | 6 ++- src/utility/sttimer.hpp | 2 +- 30 files changed, 188 insertions(+), 176 deletions(-) diff --git a/src/core/object/stasset.cpp b/src/core/object/stasset.cpp index ddee4eb..c1c1838 100644 --- a/src/core/object/stasset.cpp +++ b/src/core/object/stasset.cpp @@ -12,11 +12,13 @@ Source file contributers: namespace Starstructor { namespace Core { Asset::Asset(const QString& path) - : Parseable{ path } -{} + : Parseable(path) +{ +} Asset::~Asset() -{} +{ +} } diff --git a/src/core/object/stasset.hpp b/src/core/object/stasset.hpp index c514d7f..59258c4 100644 --- a/src/core/object/stasset.hpp +++ b/src/core/object/stasset.hpp @@ -22,7 +22,7 @@ class Asset : public Parseable virtual ~Asset() = 0; protected: - Asset(const QString& path); + explicit Asset(const QString& path); }; } diff --git a/src/core/object/stnpc.cpp b/src/core/object/stnpc.cpp index 740b92e..60dfdc5 100644 --- a/src/core/object/stnpc.cpp +++ b/src/core/object/stnpc.cpp @@ -11,9 +11,9 @@ Source file contributers: namespace Starstructor { namespace Core { -NPC::NPC(const QString& path) : Asset(path) +NPC::NPC(const QString& path) + : Asset(path) { - } } diff --git a/src/core/object/stnpc.hpp b/src/core/object/stnpc.hpp index bdbaeee..c5bf7e3 100644 --- a/src/core/object/stnpc.hpp +++ b/src/core/object/stnpc.hpp @@ -17,8 +17,7 @@ namespace Starstructor { namespace Core { class NPC final : public Asset { public: - NPC() = delete; - NPC(const QString& path); + explicit NPC(const QString& path); private: }; diff --git a/src/core/object/stobject.cpp b/src/core/object/stobject.cpp index 4e954c5..20fe0c9 100644 --- a/src/core/object/stobject.cpp +++ b/src/core/object/stobject.cpp @@ -11,9 +11,9 @@ Source file contributers: namespace Starstructor { namespace Core { -Object::Object(const QString& path) : Asset(path) +Object::Object(const QString& path) + : Asset(path) { - } } diff --git a/src/core/object/stobject.hpp b/src/core/object/stobject.hpp index 32fe198..7205230 100644 --- a/src/core/object/stobject.hpp +++ b/src/core/object/stobject.hpp @@ -17,8 +17,7 @@ namespace Starstructor { namespace Core { class Object final : public Asset { public: - Object() = delete; - Object(const QString& path); + explicit Object(const QString& path); private: }; diff --git a/src/core/object/sttile.cpp b/src/core/object/sttile.cpp index 433bf47..6a5482d 100644 --- a/src/core/object/sttile.cpp +++ b/src/core/object/sttile.cpp @@ -23,13 +23,13 @@ Tile::Tile(const QString& path) : Asset(path) { auto obj = doc.object(); - m_info.reset(new TileInfo{}); + m_info.reset(new TileInfo()); m_info->id = obj.find("materialId").value().toInt(); m_info->name = obj.find("materialName").value().toString(); m_info->platform = obj.find("platform").value().toBool(); if (m_info->name.isNull()) - throw JsonInvalidFormatException{ "No materialName defined" }; + throw JsonInvalidFormatException("No materialName defined"); if (!m_info->platform) { @@ -38,13 +38,13 @@ Tile::Tile(const QString& path) : Asset(path) const QString framesName = obj.find("frames").value().toString(); if (framesName.isNull()) - throw JsonInvalidFormatException{ "No frames defined" }; + throw JsonInvalidFormatException("No frames defined"); const QString framesPath = - QFileInfo{ path }.dir().absoluteFilePath(framesName); + QFileInfo(path).dir().absoluteFilePath(framesName); m_matRenderInfo.reset( - new MaterialRenderInfo{ variants, multiColoured, framesPath }); + new MaterialRenderInfo(variants, multiColoured, framesPath)); } else { @@ -53,17 +53,19 @@ Tile::Tile(const QString& path) : Asset(path) } catch (const Exception& ex) { - throw AssetLoadException{ ex.message() + " in file " + path + " when " - + "deserialising tile" }; + throw AssetLoadException(ex.message() + " in file " + path + " when " + + "deserialising tile"); } } MaterialRenderInfo::MaterialRenderInfo(const unsigned int& variants, const bool& multiColoured, const QString& framesPath) - : m_image{ framesPath }, m_variants{ variants }, m_multiColoured{ multiColoured } + : m_image(framesPath), + m_variants(variants), + m_multiColoured(multiColoured) { if (!m_image.open(QIODevice::ReadOnly)) - throw FileNotFoundException{ "Unable to open file at " + framesPath }; + throw FileNotFoundException("Unable to open file at " + framesPath); } const QRectF MaterialRenderInfo::tile(const unsigned int& variant, @@ -75,10 +77,10 @@ const QRectF MaterialRenderInfo::tile(const unsigned int& variant, const float TILE_WIDTH = 8.0f; const float TILE_HEIGHT = 8.0f; - return QRectF{ X_OFFSET, + return QRectF(X_OFFSET, Y_OFFSET, X_OFFSET + (variant * TILE_WIDTH), - Y_OFFSET + (colour * TILE_HEIGHT) }; + Y_OFFSET + (colour * TILE_HEIGHT)); } } diff --git a/src/core/object/sttile.hpp b/src/core/object/sttile.hpp index d2faf02..2cc3058 100644 --- a/src/core/object/sttile.hpp +++ b/src/core/object/sttile.hpp @@ -7,8 +7,8 @@ Source file contributers: Chris Stamford contact: cstamford@gmail.com */ -#ifndef STMATERIAL_HPP -#define STMATERIAL_HPP +#ifndef STTILE_HPP +#define STTILE_HPP #include "core/object/stasset.hpp" @@ -27,8 +27,7 @@ class Tile final : public Asset struct TileInfo; public: - Tile() = delete; - Tile(const QString& path); + explicit Tile(const QString& path); const TileInfo& info() const { return *m_info; } const MaterialRenderInfo& matRenderInfo() const { return *m_matRenderInfo; } @@ -50,7 +49,6 @@ class Tile final : public Asset class MaterialRenderInfo { public: - MaterialRenderInfo() = delete; MaterialRenderInfo(const unsigned int& variants, const bool& multiColoured, const QString& framesPath); @@ -75,4 +73,4 @@ class PlatformRenderInfo } -#endif // STMATERIAL_HPP \ No newline at end of file +#endif // STTILE_HPP \ No newline at end of file diff --git a/src/core/stassetmanager.cpp b/src/core/stassetmanager.cpp index 532f80a..274bd13 100644 --- a/src/core/stassetmanager.cpp +++ b/src/core/stassetmanager.cpp @@ -21,45 +21,44 @@ namespace Starstructor { namespace Core { AssetManager::AssetManager(const Utility::DirectoryServices& services, Utility::Logger& logger) - : m_logger{ &logger } + : m_logger(&logger) { - auto assetFileList = services.getFiles( + const auto assetFileList = services.getFiles( Utility::DirectoryServicesFlag::OBJECT | Utility::DirectoryServicesFlag::MATERIAL | Utility::DirectoryServicesFlag::NPC); - const int assetsFound{ assetFileList.count() }; - int assetsLoaded{ 0 }; + const int assetsFound = assetFileList.count(); + int assetsLoaded = 0; m_logger->writeLine(QString::number(assetsFound) + " assets to be loaded."); - Utility::Timer loadTimer{}; + Utility::Timer loadTimer; for (const auto& file : assetFileList) { - const QString name{ file.fileName() }; + const QString name = file.fileName(); if (m_assetMap.find(name) != m_assetMap.end()) { m_logger->writeLine("Failed to load asset " + name + " because it already exists in the asset map."); - continue; } - const QString assetType{ file.suffix()} ; + const QString assetType = file.suffix(); try { if (assetType == "object") - m_assetMap[name].reset(new Object{ file.filePath() }); + m_assetMap[name].reset(new Object(file.filePath())); else if (assetType == "material") - m_assetMap[name].reset(new Tile{ file.filePath() }); + m_assetMap[name].reset(new Tile(file.filePath())); else if (assetType == "npc") - m_assetMap[name].reset(new NPC{ file.filePath() }); + m_assetMap[name].reset(new NPC(file.filePath())); } catch (const Exception& ex) { diff --git a/src/core/stassetmanager.hpp b/src/core/stassetmanager.hpp index 5cb9bc3..799b75e 100644 --- a/src/core/stassetmanager.hpp +++ b/src/core/stassetmanager.hpp @@ -26,7 +26,6 @@ namespace Starstructor { namespace Core { class AssetManager { public: - AssetManager() = delete; AssetManager(const Utility::DirectoryServices& services, Utility::Logger& logger); diff --git a/src/core/stjsonfile.cpp b/src/core/stjsonfile.cpp index 2f150bb..d71fbe6 100644 --- a/src/core/stjsonfile.cpp +++ b/src/core/stjsonfile.cpp @@ -17,13 +17,14 @@ Source file contributers: namespace Starstructor { namespace Core { JsonFile::JsonFile(const QString& path) - : m_filePath{ path } + : m_filePath(path) { loadFromFile(path); } JsonFile::~JsonFile() -{} +{ +} const QString& JsonFile::getFilePath() const { @@ -37,12 +38,12 @@ const QJsonDocument& JsonFile::getJsonDocument() const void JsonFile::loadFromFile(const QString& path) { - QFile file{ path }; + QFile file(path); if (!file.open(QIODevice::ReadOnly)) - throw FileNotFoundException{ "Unable to open file at " + path }; + throw FileNotFoundException("Unable to open file at " + path); - const QByteArray rawData{ file.readAll() }; + const QByteArray rawData(file.readAll()); file.close(); try @@ -51,34 +52,37 @@ void JsonFile::loadFromFile(const QString& path) } catch (const JsonInvalidFormatException& ex) { - const QString fileName{ QFileInfo{ file }.fileName() }; - throw JsonInvalidFormatException{ ex.message() + " from file " + fileName }; + const QString fileName = QFileInfo(file).fileName(); + throw JsonInvalidFormatException(ex.message() + " from file " + fileName); } } void JsonFile::loadFromRawData(const QByteArray& rawData) { - QJsonParseError error{}; + QJsonParseError error; - m_jsonDocument = QJsonDocument::fromJson(JsonFile::stripComments(rawData), + m_jsonDocument = QJsonDocument::fromJson(stripComments(rawData), &error); if (error.error != QJsonParseError::NoError) - throw JsonInvalidFormatException{ error.errorString() }; + throw JsonInvalidFormatException(error.errorString()); else if (m_jsonDocument.isNull()) - throw JsonInvalidFormatException{ "Parsed document is null - empty file?" }; + throw JsonInvalidFormatException("Parsed document is null - empty file?"); } QByteArray JsonFile::stripComments(const QByteArray& rawData) { - QString formattedJson{ rawData }; + // Starbound supports non-standard comments in JSON files, so we need to strip + // the comments from the file before parsing. + + QString formattedJson(rawData); // Strip c++-style comments - formattedJson.replace(QRegularExpression{ R"(//(.*?)\n)" }, ""); + formattedJson.replace(QRegularExpression(R"(//(.*?)\n)"), ""); /* Strip c-style comments */ - formattedJson.replace(QRegularExpression{ R"(/\*(.*)\*/)" }, ""); + formattedJson.replace(QRegularExpression(R"(/\*(.*)\*/)"), ""); return formattedJson.toUtf8(); } diff --git a/src/core/stjsonfile.hpp b/src/core/stjsonfile.hpp index 1af9c48..ab80025 100644 --- a/src/core/stjsonfile.hpp +++ b/src/core/stjsonfile.hpp @@ -20,7 +20,7 @@ namespace Starstructor { namespace Core { class JsonFile final { public: - JsonFile(const QString& path); + explicit JsonFile(const QString& path); ~JsonFile(); const QString& getFilePath() const; diff --git a/src/core/stparseable.cpp b/src/core/stparseable.cpp index dba2e55..4bad051 100644 --- a/src/core/stparseable.cpp +++ b/src/core/stparseable.cpp @@ -12,11 +12,13 @@ Source file contributers: namespace Starstructor { namespace Core { Parseable::Parseable(const QString& path) - : m_json{ path } -{} + : m_json(path) +{ +} Parseable::~Parseable() -{} +{ +} JsonFile* Parseable::getJsonFile() { diff --git a/src/core/stparseable.hpp b/src/core/stparseable.hpp index ec8bf96..485a9cd 100644 --- a/src/core/stparseable.hpp +++ b/src/core/stparseable.hpp @@ -19,17 +19,15 @@ namespace Starstructor { namespace Core { class Parseable { public: - Parseable() = delete; - Parseable(const Parseable& other) = delete; - Parseable& operator=(const Parseable& other) = delete; - virtual ~Parseable() = 0; JsonFile* getJsonFile(); + Parseable(const Parseable& other) = delete; + Parseable& operator=(const Parseable& other) = delete; + protected: - Parseable(const QString& path); - Parseable(Parseable&& other) = default; + explicit Parseable(const QString& path); JsonFile m_json; }; diff --git a/src/core/world/stlevel.cpp b/src/core/world/stlevel.cpp index 3a493fc..610ca4e 100644 --- a/src/core/world/stlevel.cpp +++ b/src/core/world/stlevel.cpp @@ -12,11 +12,14 @@ Source file contributers: namespace Starstructor { namespace Core { Level::Level(const QString& path) - : Parseable{ path } -{} + : Parseable(path) +{ +} Level::~Level() -{} +{ + +} } diff --git a/src/core/world/stlevel.hpp b/src/core/world/stlevel.hpp index e7fbf80..d75774e 100644 --- a/src/core/world/stlevel.hpp +++ b/src/core/world/stlevel.hpp @@ -20,7 +20,7 @@ class Level : public Parseable virtual ~Level() = 0; protected: - Level(const QString& path); + explicit Level(const QString& path); }; } diff --git a/src/core/world/stworldfile.cpp b/src/core/world/stworldfile.cpp index 38ac28d..6416558 100644 --- a/src/core/world/stworldfile.cpp +++ b/src/core/world/stworldfile.cpp @@ -16,12 +16,12 @@ namespace Starstructor { namespace Core { WorldFile::WorldFile(const QString& path) { - QFile file{ path }; + QFile file(path); if (!file.open(QIODevice::ReadOnly)) - throw FileNotFoundException{ "Unable to open world file at " + path }; + throw FileNotFoundException("Unable to open world file at " + path); - QByteArray rawData{ file.readAll() }; + QByteArray rawData(file.readAll()); } } diff --git a/src/core/world/stworldfile.hpp b/src/core/world/stworldfile.hpp index 7b9690f..9098003 100644 --- a/src/core/world/stworldfile.hpp +++ b/src/core/world/stworldfile.hpp @@ -17,7 +17,7 @@ namespace Starstructor { namespace Core { class WorldFile { public: - WorldFile(const QString& path); + explicit WorldFile(const QString& path); private: }; diff --git a/src/gui/steditorglwidget.cpp b/src/gui/steditorglwidget.cpp index 648ff95..fb75b8d 100644 --- a/src/gui/steditorglwidget.cpp +++ b/src/gui/steditorglwidget.cpp @@ -10,7 +10,8 @@ Source file contributers: #include "gui/steditorglwidget.hpp" EditorGLWidget::EditorGLWidget(QWidget* parent) -{} +{ +} void EditorGLWidget::initializeGL() { @@ -25,11 +26,7 @@ void EditorGLWidget::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - static float rotation = 0.0f; - rotation += 0.01f; - glTranslatef(0.0f, 0.0f, -7.5f); - glRotatef(rotation, 0.0f, 1.0f, 0.0f); glBegin(GL_TRIANGLES); glVertex3f(-1.0f, +1.0f, +0.0f); @@ -45,10 +42,12 @@ void EditorGLWidget::resizeGL(int width, int height) glMatrixMode(GL_PROJECTION); glLoadIdentity(); + #ifdef QT_OPENGL_ES_1 glOrthof(-2, +2, -2, +2, 1.0, 15.0); #else glOrtho(-2, +2, -2, +2, 1.0, 15.0); #endif + glMatrixMode(GL_MODELVIEW); } \ No newline at end of file diff --git a/src/gui/stmainwindow.cpp b/src/gui/stmainwindow.cpp index 723c35a..a9cfbc2 100644 --- a/src/gui/stmainwindow.cpp +++ b/src/gui/stmainwindow.cpp @@ -14,8 +14,8 @@ void MainWindow::frame() m_mainWindow.editorGlView->updateGL(); } -MainWindow::MainWindow(QWidget* parent) : - QMainWindow{ parent } +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) { m_mainWindow.setupUi(this); } \ No newline at end of file diff --git a/src/gui/stmainwindow.hpp b/src/gui/stmainwindow.hpp index 2dafbec..a927e16 100644 --- a/src/gui/stmainwindow.hpp +++ b/src/gui/stmainwindow.hpp @@ -19,13 +19,14 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(QWidget* parent = nullptr); + explicit MainWindow(QWidget* parent = nullptr); + + void frame(); + MainWindow(const MainWindow& other) = delete; MainWindow(MainWindow&& other) = delete; MainWindow& operator=(const MainWindow& other) = delete; - void frame(); - private: Ui::ApplicationWindow m_mainWindow; }; diff --git a/src/main.cpp b/src/main.cpp index 75145d8..f762ac7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,33 +22,30 @@ Source file contributers: #include #include -#include using namespace Starstructor; int main(int argc, char* argv[]) { - QApplication application{ argc, argv }; + QApplication application(argc, argv); - MainWindow window{}; - window.show(); - - const QString logPath{ application.applicationDirPath() + "/logs/" }; - const QString fileName{ - QDateTime::currentDateTime().toString("MM-dd-yyyy_HH-mm-ss") - + "_starstructor.txt" }; - - Utility::Logger log{ logPath + fileName }; + const QString logPath = application.applicationDirPath() + "/logs/"; + const QString logFileName = QDateTime::currentDateTime().toString("MM-dd-yyyy_HH-mm-ss") + + "_starstructor.txt"; - const QString path{ "A:/Development/starbound/" }; - Utility::DirectoryServices dirServices{ path, log }; + Utility::Logger log(logPath + logFileName); + // Temporary directory, used for testing -- to be replaced. + Utility::DirectoryServices dirServices("A:/Development/projects/starbound/", log); - Core::AssetManager assetManager{ dirServices, log }; + Core::AssetManager assetManager(dirServices, log); auto worldList = dirServices.getFiles(Utility::DirectoryServicesFlag::WORLD); - Utility::Timer frameTimer{}; - int frames{}; + MainWindow window; + window.show(); + + Utility::Timer frameTimer; + int frames = 0; while (window.isVisible()) { diff --git a/src/stexception.hpp b/src/stexception.hpp index 586f28b..24918df 100644 --- a/src/stexception.hpp +++ b/src/stexception.hpp @@ -17,20 +17,22 @@ namespace Starstructor { class Exception { public: - Exception(const QString& message, - const QString& exType = "General exception") noexcept - : m_message{ message }, m_exType{ exType } - {} + explicit Exception(const QString& message, const QString& exType = "General exception") + : m_message(message), + m_exType(exType) + { + } virtual ~Exception() - {} + { + } - QString what() const noexcept + QString what() const { return m_exType + ": " + m_message; } - QString message() const noexcept + QString message() const { return m_message; } @@ -43,34 +45,40 @@ class Exception class FileNotFoundException : public Exception { public: - FileNotFoundException(const QString& message) noexcept - : Exception{ message, "File not found exception" } - {} + explicit FileNotFoundException(const QString& message) + : Exception(message, "File not found exception") + { + } virtual ~FileNotFoundException() - {} + { + } }; class JsonInvalidFormatException : public Exception { public: - JsonInvalidFormatException(const QString& message) noexcept - : Exception{ message, "JSON invalid format exception" } - {} + explicit JsonInvalidFormatException(const QString& message) + : Exception(message, "JSON invalid format exception") + { + } virtual ~JsonInvalidFormatException() - {} + { + } }; class AssetLoadException : public Exception { public: - AssetLoadException(const QString& message) noexcept - : Exception{ message, "Asset load exception" } - {} + explicit AssetLoadException(const QString& message) + : Exception(message, "Asset load exception") + { + } virtual ~AssetLoadException() - {} + { + } }; } diff --git a/src/ststlspecialisation.hpp b/src/ststlspecialisation.hpp index 7776adb..e2efe8d 100644 --- a/src/ststlspecialisation.hpp +++ b/src/ststlspecialisation.hpp @@ -15,7 +15,7 @@ Source file contributers: namespace std { - template <> + template<> struct hash { size_t operator()(const QString& val) const diff --git a/src/utility/stdirectoryservices.cpp b/src/utility/stdirectoryservices.cpp index d8b2b33..51ac110 100644 --- a/src/utility/stdirectoryservices.cpp +++ b/src/utility/stdirectoryservices.cpp @@ -16,22 +16,23 @@ using std::mutex; namespace Starstructor { namespace Utility { DirectoryServices::DirectoryServices(const QDir& path, Utility::Logger& logger) - : m_logger{ &logger }, m_readWriteMutex{} + : m_logger(&logger) { rescanPath(path); } DirectoryServices::DirectoryServices(const QString& path, Utility::Logger& logger) - : DirectoryServices(QDir{ path }, logger) -{} + : DirectoryServices(QDir(path), logger) +{ +} void DirectoryServices::rescanPath(const QDir& path) { - const QList filters{ "object", "material", "npc", + const QList filters = { "object", "material", "npc", "structure", "dungeon", "world", "shipworld" }; - QString msg{ "Scanning for all files in " + path.path() - + " with extensions:" }; + QString msg = "Scanning for all files in " + path.path() + + " with extensions:"; for (const auto& filter : filters) { @@ -40,21 +41,21 @@ void DirectoryServices::rescanPath(const QDir& path) m_logger->writeLine(msg); - Timer timer{}; + Timer timer; const auto newFiles = getDirContents_r(path, filters); - lock_guard lock{ m_readWriteMutex }; - m_files = newFiles; - m_logger->writeLine("Scanning complete in " + QString::number(timer.getTime()) + "ms. " + QString::number(m_files.count()) + " files found."); + + lock_guard lock(m_readWriteMutex); + m_files = std::move(newFiles); } void DirectoryServices::rescanPath(const QString& path) { - rescanPath(QDir{ path }); + rescanPath(QDir(path)); } QList DirectoryServices::getFiles(const DirectoryServicesFlags flags) const @@ -67,11 +68,11 @@ QList DirectoryServices::getFiles(const DirectoryServicesFlags flags) DirectoryServicesFlag::DUNGEON & DirectoryServicesFlag::WORLD & DirectoryServicesFlag::SHIPWORLD) { - lock_guard lock{ m_readWriteMutex }; + lock_guard lock(m_readWriteMutex); return m_files; } - QList filters{}; + QList filters; if (flags & DirectoryServicesFlag::OBJECT) filters.push_back("object"); @@ -99,12 +100,12 @@ QList DirectoryServices::getFiles(const DirectoryServicesFlags flags) QList DirectoryServices::getFilteredList(const QList& filters) const { - QList newList{}; - lock_guard lock{ m_readWriteMutex }; + QList newList; + lock_guard lock(m_readWriteMutex); for (const auto& file : m_files) { - const QString suffix{ file.suffix() }; + const QString suffix = file.suffix(); for (const auto& filter : filters) { @@ -119,17 +120,17 @@ QList DirectoryServices::getFilteredList(const QList& filter QList DirectoryServices::getDirContents_r(const QDir& directory, const QList& filters) const { - const QList fileList{ directory.entryInfoList( - QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::DirsFirst) }; + const QList fileList = directory.entryInfoList( + QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::DirsFirst); - QList matchingFiles{}; + QList matchingFiles; for (const auto& file : fileList) { if (file.isDir()) { const auto recMatchingFiles = getDirContents_r( - QDir{ file.absoluteFilePath() }, filters); + QDir(file.absoluteFilePath()), filters); if (!recMatchingFiles.isEmpty()) matchingFiles += recMatchingFiles; diff --git a/src/utility/stdirectoryservices.hpp b/src/utility/stdirectoryservices.hpp index 39a1f2b..3b645ff 100644 --- a/src/utility/stdirectoryservices.hpp +++ b/src/utility/stdirectoryservices.hpp @@ -37,8 +37,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(DirectoryServicesFlags); class DirectoryServices final { public: - DirectoryServices(const QDir& path, Utility::Logger& logger); - DirectoryServices(const QString& path, Utility::Logger& logger); + DirectoryServices(const QDir& path, Logger& logger); + DirectoryServices(const QString& path, Logger& logger); void rescanPath(const QDir& path); void rescanPath(const QString& path); @@ -48,7 +48,6 @@ class DirectoryServices final DirectoryServicesFlag::DUNGEON | DirectoryServicesFlag::WORLD | DirectoryServicesFlag::SHIPWORLD) const; - DirectoryServices() = delete; DirectoryServices(const DirectoryServices& other) = delete; DirectoryServices& operator=(const DirectoryServices& other) = delete; DirectoryServices(DirectoryServices&& other) = delete; @@ -60,7 +59,7 @@ class DirectoryServices final const QList& filters) const; QList m_files; - Utility::Logger* m_logger; + Logger* m_logger; mutable std::mutex m_readWriteMutex; }; diff --git a/src/utility/stlogger.cpp b/src/utility/stlogger.cpp index 3e1916a..f71fa54 100644 --- a/src/utility/stlogger.cpp +++ b/src/utility/stlogger.cpp @@ -19,10 +19,11 @@ using lockGuard = std::lock_guard; namespace Starstructor { namespace Utility { Logger::Logger(const QString& path) - : m_failed{ false }, m_logFile{ path }, m_stream{}, m_writeMutex{} + : m_failed(false), + m_logFile(path) { // Get the directory from the full path - const QDir dir{ QFileInfo{ m_logFile }.dir() }; + const QDir dir(QFileInfo(m_logFile).dir()); if (!dir.exists()) dir.mkpath("."); @@ -53,7 +54,7 @@ Logger::~Logger() Logger& Logger::operator<<(const char* input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -70,7 +71,7 @@ Logger& Logger::operator<<(const char* input) Logger& Logger::operator<<(const std::string& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -87,7 +88,7 @@ Logger& Logger::operator<<(const std::string& input) Logger& Logger::operator<<(const QString& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -104,7 +105,7 @@ Logger& Logger::operator<<(const QString& input) Logger& Logger::operator<<(const QVariant& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -121,7 +122,7 @@ Logger& Logger::operator<<(const QVariant& input) Logger& Logger::operator<<(const Exception& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -138,7 +139,7 @@ Logger& Logger::operator<<(const Exception& input) Logger& Logger::operator<<(const std::exception& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -155,7 +156,7 @@ Logger& Logger::operator<<(const std::exception& input) Logger& Logger::operator<<(const QTextStreamFunction& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); if (!m_failed) { @@ -168,84 +169,84 @@ Logger& Logger::operator<<(const QTextStreamFunction& input) void Logger::write(const char* input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input); *this << formattedInput; } void Logger::write(const std::string& input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input.c_str() }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input.c_str()); *this << formattedInput; } void Logger::write(const QString& input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input); *this << formattedInput; } void Logger::write(const QVariant& input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input.toString() }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input.toString()); *this << formattedInput; } void Logger::write(const Exception& input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input.what() }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input.what()); *this << formattedInput; } void Logger::write(const std::exception& input) { - lockGuard lock{ m_writeMutex }; - const QString formattedInput{ getTime() + input.what() }; + lockGuard lock(m_writeMutex); + const QString formattedInput(getTime() + input.what()); *this << formattedInput; } void Logger::writeLine(const char* input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } void Logger::writeLine(const std::string& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } void Logger::writeLine(const QString& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } void Logger::writeLine(const QVariant& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } void Logger::writeLine(const Exception& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } void Logger::writeLine(const std::exception& input) { - lockGuard lock{ m_writeMutex }; + lockGuard lock(m_writeMutex); write(input); *this << endl; } @@ -257,7 +258,7 @@ bool Logger::fail() const QString Logger::getTime() { - const QString format{ "HH:mm:ss zzz" }; + const QString format = "HH:mm:ss zzz"; return "[" + QTime::currentTime().toString(format) + "] "; } diff --git a/src/utility/stlogger.hpp b/src/utility/stlogger.hpp index 0960d7f..d472717 100644 --- a/src/utility/stlogger.hpp +++ b/src/utility/stlogger.hpp @@ -25,7 +25,7 @@ namespace Starstructor { namespace Utility { class Logger final { public: - Logger(const QString& path); + explicit Logger(const QString& path); ~Logger(); Logger& operator<<(const char* input); @@ -52,7 +52,6 @@ class Logger final bool fail() const; - Logger() = delete; Logger(const Logger& other) = delete; Logger(Logger&& other) = delete; Logger& operator=(const Logger& other) = delete; diff --git a/src/utility/sttimer.cpp b/src/utility/sttimer.cpp index d8ca4a9..20f77c1 100644 --- a/src/utility/sttimer.cpp +++ b/src/utility/sttimer.cpp @@ -14,8 +14,10 @@ using namespace std::chrono; namespace Starstructor { namespace Utility { Timer::Timer(const TimerPrecision precision) - : m_initialTime{ high_resolution_clock::now() }, m_precision{ precision } -{} + : m_initialTime(high_resolution_clock::now()), + m_precision(precision) +{ +} void Timer::setPrecision(const TimerPrecision precision) { diff --git a/src/utility/sttimer.hpp b/src/utility/sttimer.hpp index a216f0d..2f562bc 100644 --- a/src/utility/sttimer.hpp +++ b/src/utility/sttimer.hpp @@ -25,7 +25,7 @@ enum class TimerPrecision class Timer { public: - Timer(const TimerPrecision precision = TimerPrecision::MILLISECONDS); + explicit Timer(const TimerPrecision precision = TimerPrecision::MILLISECONDS); void setPrecision(const TimerPrecision precision); void reset(); long long getTime() const;