CellRefList<X>::find(CellRef &, Y &list) -> ::load(CellRef &, ESMStore &)

This commit is contained in:
greye 2012-11-06 14:23:21 +04:00
parent 242a9b5a59
commit 0fd22ce4b0
2 changed files with 33 additions and 29 deletions

View file

@ -98,26 +98,26 @@ namespace MWWorld
*/ */
switch(rec) switch(rec)
{ {
case ESM::REC_ACTI: mActivators.find(ref, store.activators); break; case ESM::REC_ACTI: mActivators.load(ref, store); break;
case ESM::REC_ALCH: mPotions.find(ref, store.potions); break; case ESM::REC_ALCH: mPotions.load(ref, store); break;
case ESM::REC_APPA: mAppas.find(ref, store.appas); break; case ESM::REC_APPA: mAppas.load(ref, store); break;
case ESM::REC_ARMO: mArmors.find(ref, store.armors); break; case ESM::REC_ARMO: mArmors.load(ref, store); break;
case ESM::REC_BOOK: mBooks.find(ref, store.books); break; case ESM::REC_BOOK: mBooks.load(ref, store); break;
case ESM::REC_CLOT: mClothes.find(ref, store.clothes); break; case ESM::REC_CLOT: mClothes.load(ref, store); break;
case ESM::REC_CONT: mContainers.find(ref, store.containers); break; case ESM::REC_CONT: mContainers.load(ref, store); break;
case ESM::REC_CREA: mCreatures.find(ref, store.creatures); break; case ESM::REC_CREA: mCreatures.load(ref, store); break;
case ESM::REC_DOOR: mDoors.find(ref, store.doors); break; case ESM::REC_DOOR: mDoors.load(ref, store); break;
case ESM::REC_INGR: mIngreds.find(ref, store.ingreds); break; case ESM::REC_INGR: mIngreds.load(ref, store); break;
case ESM::REC_LEVC: mCreatureLists.find(ref, store.creatureLists); break; case ESM::REC_LEVC: mCreatureLists.load(ref, store); break;
case ESM::REC_LEVI: mItemLists.find(ref, store.itemLists); break; case ESM::REC_LEVI: mItemLists.load(ref, store); break;
case ESM::REC_LIGH: mLights.find(ref, store.lights); break; case ESM::REC_LIGH: mLights.load(ref, store); break;
case ESM::REC_LOCK: mLockpicks.find(ref, store.lockpicks); break; case ESM::REC_LOCK: mLockpicks.load(ref, store); break;
case ESM::REC_MISC: mMiscItems.find(ref, store.miscItems); break; case ESM::REC_MISC: mMiscItems.load(ref, store); break;
case ESM::REC_NPC_: mNpcs.find(ref, store.npcs); break; case ESM::REC_NPC_: mNpcs.load(ref, store); break;
case ESM::REC_PROB: mProbes.find(ref, store.probes); break; case ESM::REC_PROB: mProbes.load(ref, store); break;
case ESM::REC_REPA: mRepairs.find(ref, store.repairs); break; case ESM::REC_REPA: mRepairs.load(ref, store); break;
case ESM::REC_STAT: mStatics.find(ref, store.statics); break; case ESM::REC_STAT: mStatics.load(ref, store); break;
case ESM::REC_WEAP: mWeapons.find(ref, store.weapons); break; case ESM::REC_WEAP: mWeapons.load(ref, store); break;
case 0: std::cout << "Cell reference " + ref.mRefID + " not found!\n"; break; case 0: std::cout << "Cell reference " + ref.mRefID + " not found!\n"; break;
default: default:

View file

@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "refdata.hpp" #include "refdata.hpp"
#include "esmstore.hpp"
namespace MWWorld namespace MWWorld
{ {
@ -50,17 +51,20 @@ namespace MWWorld
typedef std::list<LiveRef> List; typedef std::list<LiveRef> List;
List mList; List mList;
// Search for the given reference in the given reclist from /// Searches for reference of appropriate type in given ESMStore.
// ESMStore. Insert the reference into the list if a match is /// If reference exists, loads it into container, throws an exception
// found. If not, throw an exception. /// on miss
template <typename Y> void load(ESM::CellRef &ref, const MWWorld::ESMStore &esmStore)
void find(ESM::CellRef &ref, const Y& recList)
{ {
const X* obj = recList.find(ref.mRefID); // for throwing exception on unhandled record type
if(obj == NULL) const MWWorld::Store<X> &store = esmStore.get<X>();
throw std::runtime_error("Error resolving cell reference " + ref.mRefID); const X *ptr = store.find(ref.mRefID);
mList.push_back(LiveRef(ref, obj)); /// \note redundant because Store<X>::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) LiveRef *find (const std::string& name)