From b1d5d604be0d71d27bdf056672972cff0bf3cc04 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Tue, 6 Sep 2022 23:10:58 +0200 Subject: [PATCH] various fixes fixed naming convention replaced std::string by string_view when possible removed unused function and member varaible replaced type::value by type_v set default destructor in cpp function getTypeIndex => getnextindex --- apps/openmw/mwworld/esmstore.cpp | 35 ++++++++++---------------------- apps/openmw/mwworld/esmstore.hpp | 16 +++++++-------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 8cba07aaa2..222dec2d9d 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -140,7 +140,6 @@ namespace MWWorld ESMStore::StoreTuple mStores; std::map mRecNameToStore; - std::unordered_map mStoreToRecName; // Lookup of all IDs. Makes looking up references faster. Just // maps the id name to the record type. @@ -157,7 +156,7 @@ namespace MWWorld assert(&store == &std::get>(stores.mStoreImp->mStores)); stores.mStores[storeIndex] = &store; - if constexpr (std::is_convertible*, DynamicStore*>::value) + if constexpr (std::is_convertible_v*, DynamicStore*>) { stores.mDynamicStores.push_back(&store); constexpr ESM::RecNameInts recName = T::sRecordId; @@ -168,19 +167,10 @@ namespace MWWorld } return 0; } - - void setupAfterStoresCreation(ESMStore& store) - { - for (const auto& recordStorePair : mRecNameToStore) - { - const DynamicStore* storePtr = recordStorePair.second; - mStoreToRecName[storePtr] = recordStorePair.first; - } - } }; - int ESMStore::find(const std::string_view& id) const + int ESMStore::find(const std::string_view id) const { IDMap::const_iterator it = mStoreImp->mIds.find(id); if (it == mStoreImp->mIds.end()) { @@ -189,7 +179,7 @@ namespace MWWorld return it->second; } - int ESMStore::findStatic(const std::string& id) const + int ESMStore::findStatic(const std::string_view id) const { IDMap::const_iterator it = mStoreImp-> mStaticIds.find(id); if (it == mStoreImp->mStaticIds.end()) { @@ -203,13 +193,10 @@ namespace MWWorld mStoreImp = std::make_unique(); std::apply([this](auto& ...x) {(ESMStoreImp::assignStoreToIndex(*this, x), ...); }, mStoreImp->mStores); mDynamicCount = 0; - mStoreImp->setupAfterStoresCreation(*this); getWritable().setCells(getWritable()); } - ESMStore::~ESMStore() //necessary for the destruction of of unique_ptr - { - } + ESMStore::~ESMStore() = default; void ESMStore::clearDynamic() { @@ -325,16 +312,16 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialo } } -int& ESMStore::getIdType(std::string& id) +int& ESMStore::getIdType(const std::string& id) { return mStoreImp->mIds[id]; } static std::size_t sTypeIndexCounter = 0; -std::size_t& ESMStore::getTypeIndexCounter() +std::size_t ESMStore::geNextTypeIndex() { - return sTypeIndexCounter; + return sTypeIndexCounter++; } ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const @@ -448,8 +435,8 @@ void ESMStore::validate() // Validate spell effects for invalid arguments std::vector spellsToReplace; - auto& Spells = getWritable(); - for (ESM::Spell spell : Spells) + auto& spells = getWritable(); + for (ESM::Spell spell : spells) { if (spell.mEffects.mList.empty()) continue; @@ -505,8 +492,8 @@ void ESMStore::validate() for (const ESM::Spell &spell : spellsToReplace) { - Spells.eraseStatic(spell.mId); - Spells.insertStatic(spell); + spells.eraseStatic(spell.mId); + spells.insertStatic(spell); } } diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 2c07f4c2e4..697a2c3db0 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -133,13 +133,13 @@ namespace MWWorld static constexpr bool value = (std::is_same_v || ...); }; - static std::size_t &getTypeIndexCounter(); + static std::size_t geNextTypeIndex(); template static std::size_t getTypeIndex() { static_assert(HasMember::value); - static std::size_t sIndex = getTypeIndexCounter()++; + static std::size_t sIndex = geNextTypeIndex(); return sIndex; } @@ -165,7 +165,7 @@ namespace MWWorld template void removeMissingObjects(Store& store); - int& getIdType(std::string& id); + int& getIdType(const std::string& id); using LuaContent = std::variant< ESM::LuaScriptsCfg, // data from an omwaddon @@ -188,9 +188,9 @@ namespace MWWorld } /// Look up the given ID in 'all'. Returns 0 if not found. - int find(const std::string_view& id) const; + int find(const std::string_view id) const; - int findStatic(const std::string& id) const; + int findStatic(const std::string_view id) const; ESMStore(); @@ -225,7 +225,7 @@ namespace MWWorld record.mId = id; T *ptr = store.insert(record); - if constexpr (std::is_convertible*, DynamicStore*>::value) + if constexpr (std::is_convertible_v*, DynamicStore*>) { getIdType(ptr->mId) = T::sRecordId; } @@ -238,7 +238,7 @@ namespace MWWorld Store &store = getWritable(); T *ptr = store.insert(x); - if constexpr (std::is_convertible*, DynamicStore*>::value) + if constexpr (std::is_convertible_v*, DynamicStore*>) { getIdType(ptr->mId) = T::sRecordId; } @@ -256,7 +256,7 @@ namespace MWWorld } T *ptr = store.insertStatic(x); - if constexpr (std::is_convertible*, DynamicStore*>::value) + if constexpr (std::is_convertible_v*, DynamicStore*>) { getIdType(ptr->mId) = T::sRecordId; }