From 0fd22ce4b092d8fde5105a2c7a75b6a34cd4a785 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 6 Nov 2012 14:23:21 +0400 Subject: [PATCH] CellRefList::find(CellRef &, Y &list) -> ::load(CellRef &, ESMStore &) --- apps/openmw/mwworld/cellstore.cpp | 40 +++++++++++++++---------------- apps/openmw/mwworld/cellstore.hpp | 22 ++++++++++------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index db9761b76..1ef2d36a2 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -98,26 +98,26 @@ namespace MWWorld */ switch(rec) { - case ESM::REC_ACTI: mActivators.find(ref, store.activators); break; - case ESM::REC_ALCH: mPotions.find(ref, store.potions); break; - case ESM::REC_APPA: mAppas.find(ref, store.appas); break; - case ESM::REC_ARMO: mArmors.find(ref, store.armors); break; - case ESM::REC_BOOK: mBooks.find(ref, store.books); break; - case ESM::REC_CLOT: mClothes.find(ref, store.clothes); break; - case ESM::REC_CONT: mContainers.find(ref, store.containers); break; - case ESM::REC_CREA: mCreatures.find(ref, store.creatures); break; - case ESM::REC_DOOR: mDoors.find(ref, store.doors); break; - case ESM::REC_INGR: mIngreds.find(ref, store.ingreds); break; - case ESM::REC_LEVC: mCreatureLists.find(ref, store.creatureLists); break; - case ESM::REC_LEVI: mItemLists.find(ref, store.itemLists); break; - case ESM::REC_LIGH: mLights.find(ref, store.lights); break; - case ESM::REC_LOCK: mLockpicks.find(ref, store.lockpicks); break; - case ESM::REC_MISC: mMiscItems.find(ref, store.miscItems); break; - case ESM::REC_NPC_: mNpcs.find(ref, store.npcs); break; - case ESM::REC_PROB: mProbes.find(ref, store.probes); break; - case ESM::REC_REPA: mRepairs.find(ref, store.repairs); break; - case ESM::REC_STAT: mStatics.find(ref, store.statics); break; - case ESM::REC_WEAP: mWeapons.find(ref, store.weapons); break; + case ESM::REC_ACTI: mActivators.load(ref, store); break; + case ESM::REC_ALCH: mPotions.load(ref, store); break; + case ESM::REC_APPA: mAppas.load(ref, store); break; + case ESM::REC_ARMO: mArmors.load(ref, store); break; + case ESM::REC_BOOK: mBooks.load(ref, store); break; + case ESM::REC_CLOT: mClothes.load(ref, store); break; + case ESM::REC_CONT: mContainers.load(ref, store); break; + case ESM::REC_CREA: mCreatures.load(ref, store); break; + case ESM::REC_DOOR: mDoors.load(ref, store); break; + case ESM::REC_INGR: mIngreds.load(ref, store); break; + case ESM::REC_LEVC: mCreatureLists.load(ref, store); break; + case ESM::REC_LEVI: mItemLists.load(ref, store); break; + case ESM::REC_LIGH: mLights.load(ref, store); break; + case ESM::REC_LOCK: mLockpicks.load(ref, store); break; + case ESM::REC_MISC: mMiscItems.load(ref, store); break; + case ESM::REC_NPC_: mNpcs.load(ref, store); break; + case ESM::REC_PROB: mProbes.load(ref, store); break; + case ESM::REC_REPA: mRepairs.load(ref, store); break; + case ESM::REC_STAT: mStatics.load(ref, store); break; + case ESM::REC_WEAP: mWeapons.load(ref, store); break; case 0: std::cout << "Cell reference " + ref.mRefID + " not found!\n"; break; default: diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 440ab0690..ba3d24d7e 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -7,6 +7,7 @@ #include #include "refdata.hpp" +#include "esmstore.hpp" namespace MWWorld { @@ -50,17 +51,20 @@ namespace MWWorld typedef std::list List; List mList; - // Search for the given reference in the given reclist from - // ESMStore. Insert the reference into the list if a match is - // found. If not, throw an exception. - template - void find(ESM::CellRef &ref, const Y& recList) + /// Searches for reference of appropriate type in given ESMStore. + /// If reference exists, loads it into container, throws an exception + /// on miss + void load(ESM::CellRef &ref, const MWWorld::ESMStore &esmStore) { - const X* obj = recList.find(ref.mRefID); - if(obj == NULL) - throw std::runtime_error("Error resolving cell reference " + ref.mRefID); + // for throwing exception on unhandled record type + const MWWorld::Store &store = esmStore.get(); + const X *ptr = store.find(ref.mRefID); - mList.push_back(LiveRef(ref, obj)); + /// \note redundant because Store::find() throws exception on miss + if (ptr == NULL) { + throw std::runtime_error("Error resolving cell reference " + ref.mRefID); + } + mList.push_back(LiveRef(ref, ptr)); } LiveRef *find (const std::string& name)