From 2f9accf5ba39a10ec3ed7fefe67e239c8a56c1eb Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 17 Jul 2021 12:20:57 -0500 Subject: [PATCH] [nostalgia/studio] Cleanup --- src/nostalgia/studio/lib/module.hpp | 2 +- src/nostalgia/studio/lib/project.cpp | 22 +++++++++----------- src/nostalgia/studio/lib/project.hpp | 31 ++++++++++++++-------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/nostalgia/studio/lib/module.hpp b/src/nostalgia/studio/lib/module.hpp index bf7ef7c8..ca54c3cf 100644 --- a/src/nostalgia/studio/lib/module.hpp +++ b/src/nostalgia/studio/lib/module.hpp @@ -31,7 +31,7 @@ class Module { virtual QVector importWizards(const Context *ctx); - virtual QVector editors(const class Context *ctx); + virtual QVector editors(const class Context *ctx); }; diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 367debd5..ea498b51 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -13,20 +13,18 @@ namespace nostalgia::studio { -QString filePathToName(QString path, QString prefix, QString suffix) { +QString filePathToName(const QString &path, const QString &prefix, const QString &suffix) { const auto begin = prefix.size(); const auto end = path.size() - (suffix.size() + prefix.size()); return path.mid(begin, end); } -Project::Project(QString path): m_fs(std::make_unique(path.toUtf8())) { +Project::Project(const QString &path): m_fs(std::make_unique(path.toUtf8())) { qDebug() << "Project:" << path; m_path = path; } -Project::~Project() = default; - void Project::create() { QDir().mkpath(m_path); } @@ -35,32 +33,32 @@ ox::FileSystem *Project::romFs() { return m_fs.get(); } -void Project::mkdir(QString path) const { +void Project::mkdir(const QString &path) const { oxThrowError(m_fs->mkdir(path.toUtf8().data(), true)); emit fileUpdated(path); } -ox::FileStat Project::stat(QString path) const { +ox::FileStat Project::stat(const QString &path) const { oxRequireT(s, m_fs->stat(path.toUtf8().data())); return s; } -bool Project::exists(QString path) const { +bool Project::exists(const QString &path) const { return m_fs->stat(path.toUtf8().data()).error == 0; } -void Project::writeBuff(QString path, uint8_t *buff, size_t buffLen) const { +void Project::writeBuff(const QString &path, uint8_t *buff, size_t buffLen) const { oxThrowError(m_fs->write(path.toUtf8().data(), buff, buffLen)); emit fileUpdated(path); } -ox::Buffer Project::loadBuff(QString path) const { +ox::Buffer Project::loadBuff(const QString &path) const { const auto csPath = path.toUtf8(); oxRequireMT(buff, m_fs->read(csPath.data())); return std::move(buff); } -void Project::lsProcDir(QStringList *paths, QString path) const { +void Project::lsProcDir(QStringList *paths, const QString &path) const { oxRequireT(files, m_fs->ls(path.toUtf8())); for (const auto &name : files) { const auto fullPath = path + "/" + name.c_str(); @@ -78,10 +76,10 @@ void Project::lsProcDir(QStringList *paths, QString path) const { } } -QStringList Project::listFiles(QString path) const { +QStringList Project::listFiles(const QString &path) const { QStringList paths; lsProcDir(&paths, path); - return paths; + return ox::move(paths); } } diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 8f91bd77..916e6560 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -32,7 +32,8 @@ enum class ProjectEvent { FileUpdated, }; -[[nodiscard]] QString filePathToName(QString path, QString prefix, QString suffix); +[[nodiscard]] +QString filePathToName(const QString &path, const QString &prefix, const QString &suffix); class NOSTALGIASTUDIO_EXPORT Project: public QObject { Q_OBJECT @@ -42,42 +43,40 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject { mutable std::unique_ptr m_fs; public: - explicit Project(QString path); + explicit Project(const QString &path); - ~Project() override; + ~Project() override = default; void create(); ox::FileSystem *romFs(); - void mkdir(QString path) const; + void mkdir(const QString &path) const; /** * Writes a MetalClaw object to the project at the given path. */ template - void writeObj(QString path, T *obj) const; + void writeObj(const QString &path, T *obj) const; template - std::unique_ptr loadObj(QString path) const; + std::unique_ptr loadObj(const QString &path) const; - ox::FileStat stat(QString path) const; + ox::FileStat stat(const QString &path) const; - bool exists(QString path) const; - - void subscribe(ProjectEvent e, QObject *tgt, const char *slot) const; + bool exists(const QString& path) const; template void subscribe(ProjectEvent e, QObject *tgt, Functor &&slot) const; private: - void writeBuff(QString path, uint8_t *buff, size_t buffLen) const; + void writeBuff(const QString &path, uint8_t *buff, size_t buffLen) const; - ox::Buffer loadBuff(QString path) const; + ox::Buffer loadBuff(const QString &path) const; - void lsProcDir(QStringList *paths, QString path) const; + void lsProcDir(QStringList *paths, const QString &path) const; - QStringList listFiles(QString path = "") const; + QStringList listFiles(const QString &path = "") const; signals: void fileEvent(ProjectEvent, QString path) const; @@ -92,7 +91,7 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject { }; template -void Project::writeObj(QString path, T *obj) const { +void Project::writeObj(const QString &path, T *obj) const { // write MetalClaw oxRequireMT(buff, ox::writeClaw(obj, ox::ClawFormat::Metal)); // write to FS @@ -112,7 +111,7 @@ void Project::writeObj(QString path, T *obj) const { } template -std::unique_ptr Project::loadObj(QString path) const { +std::unique_ptr Project::loadObj(const QString &path) const { auto obj = std::make_unique(); auto buff = loadBuff(path); oxThrowError(ox::readClaw(buff.data(), buff.size(), obj.get()));