1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00

ESM Store: no more automatic function implementation that suppose a mId member

All the ESM3 store will continue to work the same, used a macro to quickly define the different functions
This commit is contained in:
florent.teppe 2022-07-03 13:46:12 +02:00
parent db2b4600aa
commit 0a0b301cc4
2 changed files with 55 additions and 28 deletions

View File

@ -204,6 +204,41 @@ namespace MWWorld
}
return ptr;
}
template <class T>
static const T * ESM3overrideRecord(ESMStore& stores, const T &x) {
Store<T> &store = const_cast<Store<T> &>( stores.get<T>());
T *ptr = store.insert(x);
for (ESMStore::iterator it = stores.mStores.begin(); it != stores.mStores.end(); ++it) {
if (it->second == &store) {
stores.mIds[ptr->mId] = it->first;
}
}
return ptr;
}
template <class T>
static const T *ESM3insertStatic(ESMStore& stores, const T &x)
{
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 = x;
T *ptr = store.insertStatic(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()
@ -699,6 +734,24 @@ void ESMStore::removeMissingObjects(Store<T>& store)
ESM3Insert(ESM::Spell);
#undef ESM3Insert
#define ESM3InsertStatic(__Type) template<> const __Type* ESMStore::insertStatic<__Type>(const __Type &toInsert) { return ESMStoreImp::ESM3insertStatic(*this, toInsert); }
ESM3InsertStatic(ESM::GameSetting);
ESM3InsertStatic(ESM::Static);
ESM3InsertStatic(ESM::Door);
ESM3InsertStatic(ESM::Global);
ESM3InsertStatic(ESM::NPC);
#undef ESM3InsertStatic
#define ESM3overrideRecord(__Type) template<> const __Type* ESMStore::overrideRecord<__Type>(const __Type &toInsert) { return ESMStoreImp::ESM3overrideRecord(*this, toInsert); }
ESM3overrideRecord(ESM::Container);
ESM3overrideRecord(ESM::Creature);
ESM3overrideRecord(ESM::CreatureLevList);
ESM3overrideRecord(ESM::Door);
ESM3overrideRecord(ESM::ItemLevList);
ESM3overrideRecord(ESM::NPC);
#undef ESM3overrideRecord
template <>
const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const {
return mStoreImp->mActivators;

View File

@ -119,36 +119,10 @@ namespace MWWorld
/// Insert a record with set ID, and allow it to override a pre-existing static record.
template <class T>
const T *overrideRecord(const T &x) {
Store<T> &store = const_cast<Store<T> &>(get<T>());
T *ptr = store.insert(x);
for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
if (it->second == &store) {
mIds[ptr->mId] = it->first;
}
}
return ptr;
}
const T *overrideRecord(const T &x);
template <class T>
const T *insertStatic(const T &x)
{
Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(x.mId) != nullptr)
{
const std::string msg = "Try to override existing record '" + x.mId + "'";
throw std::runtime_error(msg);
}
T *ptr = store.insertStatic(x);
for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
if (it->second == &store) {
mIds[ptr->mId] = it->first;
}
}
return ptr;
}
const T *insertStatic(const T &x);
// This method must be called once, after loading all master/plugin files. This can only be done
// from the outside, so it must be public.