1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-22 04:09:45 +00:00

ESM Store: removed a lot of declarations that became useless

the default implementation of the template<> get() threw a reuntime error, when it is a compile time issue
now all the implementations are in the cpp file
This commit is contained in:
florent.teppe 2022-07-03 13:17:55 +02:00
parent 6467e48be8
commit db2b4600aa
2 changed files with 39 additions and 77 deletions

View file

@ -180,6 +180,30 @@ namespace MWWorld
// Special entry which is hardcoded and not loaded from an ESM
Store<ESM::Attribute> mAttributes;
template<typename T>
static const T* ESM3StoreInsert(ESMStore& stores, const T &toInsert)
{
const std::string id = "$dynamic" + std::to_string(stores.mDynamicCount++);
Store<T> &store = const_cast<Store<T> &>(stores.get<T>());
if (store.search(id) != nullptr)
{
const std::string msg = "Try to override existing record '" + id + "'";
throw std::runtime_error(msg);
}
T record = toInsert;
record.mId = id;
T *ptr = store.insert(record);
for (ESMStore::iterator it = stores.mStores.begin(); it != stores.mStores.end(); ++it) {
if (it->second == &store) {
stores.mIds[ptr->mId] = it->first;
}
}
return ptr;
}
};
ESMStore::ESMStore()
@ -664,6 +688,17 @@ void ESMStore::removeMissingObjects(Store<T>& store)
return ptr;
}
#define ESM3Insert(__Type) template<> const __Type* ESMStore::insert<__Type>(const __Type &toInsert) { return ESMStoreImp::ESM3StoreInsert(*this, toInsert); }
ESM3Insert(ESM::Book);
ESM3Insert(ESM::Armor);
ESM3Insert(ESM::Class);
ESM3Insert(ESM::Enchantment);
ESM3Insert(ESM::Potion);
ESM3Insert(ESM::Weapon);
ESM3Insert(ESM::Clothing);
ESM3Insert(ESM::Spell);
#undef ESM3Insert
template <>
const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const {
return mStoreImp->mActivators;

View file

@ -29,8 +29,8 @@ namespace MWWorld
class ESMStore
{
std::unique_ptr<ESMStoreImp> mStoreImp;
friend struct ESMStoreImp; //This allows StoreImp to extend esmstore without beeing included everywhere
std::unique_ptr<ESMStoreImp> mStoreImp;
// Lookup of all IDs. Makes looking up references faster. Just
// maps the id name to the record type.
@ -111,34 +111,11 @@ namespace MWWorld
void load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue);
template <class T>
const Store<T> &get() const {
throw std::runtime_error("Storage for this type not exist");
}
const Store<T>& get() const;
/// Insert a custom record (i.e. with a generated ID that will not clash will pre-existing records)
template <class T>
const T *insert(const T &x)
{
const std::string id = "$dynamic" + std::to_string(mDynamicCount++);
Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(id) != nullptr)
{
const std::string msg = "Try to override existing record '" + id + "'";
throw std::runtime_error(msg);
}
T record = x;
record.mId = id;
T *ptr = store.insert(record);
for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
if (it->second == &store) {
mIds[ptr->mId] = it->first;
}
}
return ptr;
}
const T* insert(const T& x);
/// Insert a record with set ID, and allow it to override a pre-existing static record.
template <class T>
@ -197,57 +174,7 @@ namespace MWWorld
};
template <>
const ESM::Cell* ESMStore::insert<ESM::Cell>(const ESM::Cell& cell);
template <>
const ESM::NPC* ESMStore::insert<ESM::NPC>(const ESM::NPC& npc);
#define DeclareStoreGet(__Type ) template<> const Store<__Type>& ESMStore::get<__Type>() const;
DeclareStoreGet(ESM::Activator)
DeclareStoreGet(ESM::Potion)
DeclareStoreGet(ESM::Apparatus)
DeclareStoreGet(ESM::Armor)
DeclareStoreGet(ESM::BodyPart)
DeclareStoreGet(ESM::Book)
DeclareStoreGet(ESM::BirthSign)
DeclareStoreGet(ESM::Class)
DeclareStoreGet(ESM::Clothing)
DeclareStoreGet(ESM::Container)
DeclareStoreGet(ESM::Creature)
DeclareStoreGet(ESM::Dialogue)
DeclareStoreGet(ESM::Door)
DeclareStoreGet(ESM::Enchantment)
DeclareStoreGet(ESM::Faction)
DeclareStoreGet(ESM::Global)
DeclareStoreGet(ESM::Ingredient)
DeclareStoreGet(ESM::CreatureLevList)
DeclareStoreGet(ESM::ItemLevList)
DeclareStoreGet(ESM::Light)
DeclareStoreGet(ESM::Lockpick)
DeclareStoreGet(ESM::Miscellaneous)
DeclareStoreGet(ESM::NPC)
DeclareStoreGet(ESM::Probe)
DeclareStoreGet(ESM::Race)
DeclareStoreGet(ESM::Region)
DeclareStoreGet(ESM::Repair)
DeclareStoreGet(ESM::SoundGenerator)
DeclareStoreGet(ESM::Sound)
DeclareStoreGet(ESM::Spell)
DeclareStoreGet(ESM::StartScript)
DeclareStoreGet(ESM::Static)
DeclareStoreGet(ESM::Weapon)
DeclareStoreGet(ESM::GameSetting)
DeclareStoreGet(ESM::Script)
DeclareStoreGet(ESM::Cell)
DeclareStoreGet(ESM::Land)
DeclareStoreGet(ESM::LandTexture)
DeclareStoreGet(ESM::Pathgrid)
DeclareStoreGet(ESM::MagicEffect)
DeclareStoreGet(ESM::Skill)
DeclareStoreGet(ESM::Attribute)
#undef DeclareStoreGet
}
#endif