diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 3176a28d5e..5e64e5fc28 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -129,14 +129,8 @@ namespace } static int sRecordTypeCounter = 0; -template struct SRecordType -{ - static const int recordId; - static int getId() { return recordId; }; -}; -#define AddStoreType(__Type) const int SRecordType<__Type>::recordId = sRecordTypeCounter++; -#define GetRecordTypeId(__Type) SRecordType<__Type>::recordId +#define AddStoreType(__Type) const int MWWorld::SRecordType<__Type>::recordId = sRecordTypeCounter++; AddStoreType(ESM::Activator); AddStoreType(ESM::Potion); @@ -307,58 +301,6 @@ namespace MWWorld }; -#define defineGetters(__Type) template <> const Store<__Type>& ESMStore::get<__Type>() const { return static_cast&>(*mStores[GetRecordTypeId(__Type)]); } \ - template <> Store<__Type>& ESMStore::getWritable<__Type>() { return static_cast&>(*mStores[GetRecordTypeId(__Type)]); } - - defineGetters(ESM::Activator); - defineGetters(ESM::Potion); - defineGetters(ESM::Apparatus); - defineGetters(ESM::Armor); - defineGetters(ESM::BodyPart); - defineGetters(ESM::Book); - defineGetters(ESM::BirthSign); - defineGetters(ESM::Class); - defineGetters(ESM::Clothing); - defineGetters(ESM::Container); - defineGetters(ESM::Creature); - defineGetters(ESM::Dialogue); - defineGetters(ESM::Door); - defineGetters(ESM::Enchantment); - defineGetters(ESM::Faction); - defineGetters(ESM::Global); - defineGetters(ESM::Ingredient); - defineGetters(ESM::CreatureLevList); - defineGetters(ESM::ItemLevList); - defineGetters(ESM::Light); - defineGetters(ESM::Lockpick); - defineGetters(ESM::Miscellaneous); - defineGetters(ESM::NPC); - defineGetters(ESM::Probe); - defineGetters(ESM::Race); - defineGetters(ESM::Region); - defineGetters(ESM::Repair); - defineGetters(ESM::SoundGenerator); - defineGetters(ESM::Sound); - defineGetters(ESM::Spell); - defineGetters(ESM::StartScript); - defineGetters(ESM::Static); - defineGetters(ESM::Weapon); - defineGetters(ESM::GameSetting); - defineGetters(ESM::Script); - defineGetters(ESM::Cell); - defineGetters(ESM::Land); - defineGetters(ESM::LandTexture); - defineGetters(ESM::Pathgrid); -#undef defineGetters - template <> const Store& ESMStore::get() const { return mStoreImp->mMagicEffect; } - template <> Store& ESMStore::getWritable() { return mStoreImp->mMagicEffect; } - - template <> const Store& ESMStore::get() const { return mStoreImp->mSkills; } - template <> Store& ESMStore::getWritable() { return mStoreImp->mSkills; } - - template <> const Store& ESMStore::get() const { return mStoreImp->mAttributes; } - template <> Store& ESMStore::getWritable() { return mStoreImp->mAttributes; } - ESMStore::ESMStore() { mStores.resize(sRecordTypeCount); @@ -891,5 +833,13 @@ void ESMStore::removeMissingObjects(Store& store) ESM3overrideRecord(ESM::NPC); #undef ESM3overrideRecord + template <> const Store& ESMStore::get() const { return mStoreImp->mMagicEffect; } + template <> Store& ESMStore::getWritable() { return mStoreImp->mMagicEffect; } + + template <> const Store& ESMStore::get() const { return mStoreImp->mSkills; } + template <> Store& ESMStore::getWritable() { return mStoreImp->mSkills; } + + template <> const Store& ESMStore::get() const { return mStoreImp->mAttributes; } + template <> Store& ESMStore::getWritable() { return mStoreImp->mAttributes; } } // end namespace diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index e4af64a285..3d9168cd4b 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -29,6 +29,12 @@ namespace ESM namespace MWWorld { struct ESMStoreImp; + template struct SRecordType + { + static const int recordId; + static int getId() { return recordId; }; + }; + #define GetRecordTypeId(__Type) SRecordType<__Type>::recordId class ESMStore { @@ -50,7 +56,7 @@ namespace MWWorld mutable std::unordered_map, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mSpellListCache; template - Store& getWritable(); + Store& getWritable() {return static_cast&>(*mStores[GetRecordTypeId(T)]);}; /// Validate entries in store after setup void validate(); @@ -111,7 +117,7 @@ namespace MWWorld void load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue); template - const Store& get() const; + const Store& get() const {return static_cast&>(*mStores[GetRecordTypeId(T)]);}; /// Insert a custom record (i.e. with a generated ID that will not clash will pre-existing records) template @@ -147,7 +153,15 @@ namespace MWWorld std::pair, bool> getSpellList(const std::string& id) const; }; + //Special cases these aren't StoreBase, but IndexedStore + template <> const Store& ESMStore::get() const; + template <> Store& ESMStore::getWritable(); + + template <> const Store& ESMStore::get() const; + template <> Store& ESMStore::getWritable(); + template <> const Store& ESMStore::get() const; + template <> Store& ESMStore::getWritable(); }