From 1505d7ea377f43962d9e3ffc49dc1fd830b50b80 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 3 Dec 2023 22:48:30 -0600 Subject: [PATCH] [keel,nostalgia/tools,studio] Convert some pointers to references --- src/keel/asset.cpp | 6 +++--- src/keel/assetmanager.hpp | 26 +++++++++++++------------- src/keel/context.hpp | 4 ++-- src/keel/media.cpp | 2 +- src/keel/media.hpp | 4 ++-- src/keel/module.hpp | 10 +++++----- src/nostalgia/tools/pack.cpp | 2 +- src/studio/modlib/src/project.cpp | 4 ++-- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/keel/asset.cpp b/src/keel/asset.cpp index a698d257..11141a70 100644 --- a/src/keel/asset.cpp +++ b/src/keel/asset.cpp @@ -6,7 +6,7 @@ namespace keel { -ox::Result readUuidHeader(const ox::Buffer &buff) noexcept { +ox::Result readUuidHeader(ox::Buffer const&buff) noexcept { return readUuidHeader(buff.data(), buff.size()); } @@ -21,7 +21,7 @@ ox::Result readUuidHeader(const char *buff, std::size_t buffLen) noexc return ox::UUID::fromString(ox::StringView(buff + k1Hdr.bytes(), 36)); } -ox::Result readAsset(ox::TypeStore *ts, const ox::Buffer &buff) noexcept { +ox::Result readAsset(ox::TypeStore *ts, ox::Buffer const&buff) noexcept { std::size_t offset = 0; if (!readUuidHeader(buff).error) { offset = K1HdrSz; @@ -39,7 +39,7 @@ ox::Result readAssetHeader(const char *buff, std::size_t buffLen) noex return out; } -ox::Result readAssetHeader(const ox::Buffer &buff) noexcept { +ox::Result readAssetHeader(ox::Buffer const&buff) noexcept { return readAssetHeader(buff.data(), buff.size()); } diff --git a/src/keel/assetmanager.hpp b/src/keel/assetmanager.hpp index 6c823901..163904d5 100644 --- a/src/keel/assetmanager.hpp +++ b/src/keel/assetmanager.hpp @@ -36,9 +36,9 @@ class AssetContainer { explicit constexpr AssetContainer(Args&&... args): m_obj(ox::forward(args)...) { } - AssetContainer(AssetContainer&) = delete; + AssetContainer(AssetContainer const&) = delete; AssetContainer(AssetContainer&&) = delete; - AssetContainer& operator=(AssetContainer&) = delete; + AssetContainer& operator=(AssetContainer const&) = delete; AssetContainer& operator=(AssetContainer&&) = delete; [[nodiscard]] @@ -55,7 +55,7 @@ class AssetContainer { m_obj = std::move(val); } - constexpr void set(const T &val) { + constexpr void set(T const&val) { m_obj = val; } @@ -85,7 +85,7 @@ class AssetRef: public ox::SignalHandler { explicit constexpr AssetRef(const AssetContainer *c = nullptr) noexcept; - constexpr AssetRef(const AssetRef &h) noexcept; + constexpr AssetRef(AssetRef const&h) noexcept; constexpr AssetRef(AssetRef &&h) noexcept; @@ -111,7 +111,7 @@ class AssetRef: public ox::SignalHandler { return m_ctr->get(); } - AssetRef &operator=(const AssetRef &h) noexcept { + AssetRef &operator=(AssetRef const&h) noexcept { if (this == &h) { return *this; } @@ -160,7 +160,7 @@ constexpr AssetRef::AssetRef(const AssetContainer *c) noexcept: m_ctr(c) { } template -constexpr AssetRef::AssetRef(const AssetRef &h) noexcept { +constexpr AssetRef::AssetRef(AssetRef const&h) noexcept { m_ctr = h.m_ctr; if (m_ctr) { m_ctr->updated.connect(this, &AssetRef::emitUpdated); @@ -187,16 +187,16 @@ class AssetManager { template class AssetTypeManager: public AssetTypeManagerBase { private: - ox::HashMap>> m_cache; + ox::HashMap>> m_cache; public: - ox::Result> getAsset(const ox::StringView &assetId) const noexcept { + ox::Result> getAsset(ox::StringView const&assetId) const noexcept { auto out = m_cache.at(assetId); oxReturnError(out); return AssetRef(out.value->get()); } - ox::Result> setAsset(const ox::StringView &assetId, const T &obj) noexcept { + ox::Result> setAsset(ox::StringView const&assetId, const T &obj) noexcept { auto &p = m_cache[assetId]; if (!p) { p = ox::make_unique>(obj); @@ -207,7 +207,7 @@ class AssetManager { return AssetRef(p.get()); } - ox::Result> setAsset(const ox::StringView &assetId, T &&obj) noexcept { + ox::Result> setAsset(ox::StringView const&assetId, T &&obj) noexcept { auto &p = m_cache[assetId]; if (!p) { p = ox::make_unique>(obj); @@ -228,7 +228,7 @@ class AssetManager { } }; - ox::HashMap> m_assetTypeManagers; + ox::HashMap> m_assetTypeManagers; template AssetTypeManager *getTypeManager() noexcept { @@ -255,7 +255,7 @@ class AssetManager { } void gc() noexcept { - for (const auto &amk : m_assetTypeManagers.keys()) { + for (auto const&amk : m_assetTypeManagers.keys()) { auto &am = m_assetTypeManagers[amk]; am->gc(); } @@ -265,7 +265,7 @@ class AssetManager { template class AssetRef { private: - const T *m_obj = nullptr; + const T *const m_obj = nullptr; public: constexpr AssetRef() noexcept = default; diff --git a/src/keel/context.hpp b/src/keel/context.hpp index 4ac30af2..db7d30ef 100644 --- a/src/keel/context.hpp +++ b/src/keel/context.hpp @@ -29,9 +29,9 @@ class Context { #endif constexpr Context() noexcept = default; - Context(const Context&) noexcept = delete; + Context(Context const&) noexcept = delete; Context(Context&&) noexcept = delete; - Context &operator=(const Context&) noexcept = delete; + Context &operator=(Context const&) noexcept = delete; Context &operator=(Context&&) noexcept = delete; constexpr virtual ~Context() noexcept = default; }; diff --git a/src/keel/media.cpp b/src/keel/media.cpp index d61255f2..8f33d635 100644 --- a/src/keel/media.cpp +++ b/src/keel/media.cpp @@ -171,7 +171,7 @@ ox::Result getPreloadAddr(keel::Context &ctx, const ox::FileAddress namespace keel { -ox::Error setRomFs(Context &ctx, ox::UPtr fs) noexcept { +ox::Error setRomFs(Context &ctx, ox::UPtr &&fs) noexcept { ctx.rom = std::move(fs); clearUuidMap(ctx); return buildUuidMap(ctx); diff --git a/src/keel/media.hpp b/src/keel/media.hpp index db203c8a..378ed49d 100644 --- a/src/keel/media.hpp +++ b/src/keel/media.hpp @@ -29,7 +29,7 @@ oxModelBegin(PreloadPtr) oxModelField(preloadAddr) oxModelEnd() -ox::Result getPreloadAddr(keel::Context &ctx, const ox::FileAddress &file) noexcept; +ox::Result getPreloadAddr(keel::Context &ctx, ox::FileAddress const&file) noexcept; ox::Result getPreloadAddr(keel::Context &ctx, ox::CRStringView file) noexcept; #ifndef OX_BARE_METAL @@ -158,7 +158,7 @@ ox::Error writeObj( return ctx.rom->write(file, objBuff.data(), objBuff.size()); } -ox::Error setRomFs(Context &ctx, ox::UPtr fs) noexcept; +ox::Error setRomFs(Context &ctx, ox::UPtr &&fs) noexcept; ox::Result> loadRomFs(ox::CRStringView path) noexcept; diff --git a/src/keel/module.hpp b/src/keel/module.hpp index 78b8865e..43626eaf 100644 --- a/src/keel/module.hpp +++ b/src/keel/module.hpp @@ -11,19 +11,19 @@ namespace keel { -using TypeDescGenerator = ox::Error(*)(ox::TypeStore*); +using TypeDescGenerator = ox::Error(*)(ox::TypeStore&); template -ox::Error generateTypeDesc(ox::TypeStore *ts) noexcept { - return ox::buildTypeDef(ts).error; +ox::Error generateTypeDesc(ox::TypeStore &ts) noexcept { + return ox::buildTypeDef(&ts).error; } class Module { public: constexpr Module() noexcept = default; - Module(const Module&) noexcept = delete; + Module(Module const&) noexcept = delete; Module(Module&&) noexcept = delete; - Module &operator=(const Module&) noexcept = delete; + Module &operator=(Module const&) noexcept = delete; Module &operator=(Module&&) noexcept = delete; constexpr virtual ~Module() noexcept = default; diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 7a58ce7b..aaaf253c 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -44,7 +44,7 @@ static ox::Result readFileBuff(ox::StringView path) noexcept { static ox::Error generateTypes(ox::TypeStore *ts) noexcept { for (const auto mod : keel::modules()) { for (auto gen : mod->types()) { - oxReturnError(gen(ts)); + oxReturnError(gen(*ts)); } } return {}; diff --git a/src/studio/modlib/src/project.cpp b/src/studio/modlib/src/project.cpp index 7693691f..ef72e69b 100644 --- a/src/studio/modlib/src/project.cpp +++ b/src/studio/modlib/src/project.cpp @@ -13,7 +13,7 @@ namespace studio { -static void generateTypes(ox::TypeStore *ts) noexcept { +static void generateTypes(ox::TypeStore &ts) noexcept { for (const auto mod : keel::modules()) { for (auto gen : mod->types()) { oxLogError(gen(ts)); @@ -28,7 +28,7 @@ Project::Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDa m_typeStore(*m_ctx.rom, ox::sfmt("/.{}/type_descriptors", projectDataDir)), m_fs(*m_ctx.rom) { oxTracef("studio", "Project: {}", m_path); - generateTypes(&m_typeStore); + generateTypes(m_typeStore); buildFileIndex(); }