From 90b415a8dd930a718eb929de5b784a1b02ea4391 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Thu, 6 Jun 2024 11:20:14 +0200 Subject: [PATCH] comments by elsid --- apps/openmw/mwworld/manualref.cpp | 75 +++++++++++-------------------- apps/openmw/mwworld/manualref.hpp | 4 +- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/apps/openmw/mwworld/manualref.cpp b/apps/openmw/mwworld/manualref.cpp index fce66d2919..e9a3f08c79 100644 --- a/apps/openmw/mwworld/manualref.cpp +++ b/apps/openmw/mwworld/manualref.cpp @@ -29,79 +29,56 @@ namespace } template - void createGeneric(F func, const MWWorld::ESMStore& store, ESM::RefId name) + void visitRefStore(const MWWorld::ESMStore& store, ESM::RefId name, F func) { switch (store.find(name)) { case ESM::REC_ACTI: - func(store.get()); - break; + return func(store.get()); case ESM::REC_ALCH: - func(store.get()); - break; + return func(store.get()); case ESM::REC_APPA: - func(store.get()); - break; + return func(store.get()); case ESM::REC_ARMO: - func(store.get()); - break; + return func(store.get()); case ESM::REC_BOOK: - func(store.get()); - break; + return func(store.get()); case ESM::REC_CLOT: - func(store.get()); - break; + return func(store.get()); case ESM::REC_CONT: - func(store.get()); - break; + return func(store.get()); case ESM::REC_CREA: - func(store.get()); - break; + return func(store.get()); case ESM::REC_DOOR: - func(store.get()); - break; + return func(store.get()); case ESM::REC_INGR: - func(store.get()); - break; + return func(store.get()); case ESM::REC_LEVC: - func(store.get()); - break; + return func(store.get()); case ESM::REC_LEVI: - func(store.get()); - break; + return func(store.get()); case ESM::REC_LIGH: - func(store.get()); - break; + return func(store.get()); case ESM::REC_LOCK: - func(store.get()); - break; + return func(store.get()); case ESM::REC_MISC: - func(store.get()); - break; + return func(store.get()); case ESM::REC_NPC_: - func(store.get()); - break; + return func(store.get()); case ESM::REC_PROB: - func(store.get()); - break; + return func(store.get()); case ESM::REC_REPA: - func(store.get()); - break; + return func(store.get()); case ESM::REC_STAT: - func(store.get()); - break; + return func(store.get()); case ESM::REC_WEAP: - func(store.get()); - break; + return func(store.get()); case ESM::REC_BODY: - func(store.get()); - break; + return func(store.get()); case ESM::REC_STAT4: - func(store.get()); - break; + return func(store.get()); case ESM::REC_TERM4: - func(store.get()); - break; + return func(store.get()); case 0: throw std::logic_error( "failed to create manual cell ref for " + name.toDebugString() + " (unknown ID)"); @@ -116,7 +93,7 @@ namespace MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count) { auto cb = [&](const auto& store) { create(store, name, mRef, mPtr); }; - createGeneric(cb, store, name); + visitRefStore(store, name, cb); mPtr.getCellRef().setCount(count); } @@ -124,7 +101,7 @@ MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& MWWorld::ManualRef::ManualRef(const ESMStore& store, const Ptr& template_, const int count) { auto cb = [&](const auto& store) { create(store, template_, mRef, mPtr); }; - createGeneric(cb, store, template_.getCellRef().getRefId()); + visitRefStore(store, template_.getCellRef().getRefId(), cb); mPtr.getCellRef().setCount(count); mPtr.getCellRef().unsetRefNum(); diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index f46cde7322..4611ed95bb 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -7,9 +7,11 @@ namespace MWWorld { - /// \brief Manually constructed live cell ref + /// \brief Manually constructed live cell ref. The resulting Ptr shares its lifetime with this ManualRef and must + /// not be used past its end. class ManualRef { + // Stores the ref (LiveCellRef) by value. std::any mRef; Ptr mPtr;