From bcc5894e2d820b7497f2381ddef8af7da61cf836 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 1 Feb 2014 15:24:01 +0100 Subject: [PATCH] changed implementation functions for container serialisation from free functions to member functions (will need some polymorphism later) --- apps/openmw/mwworld/containerstore.cpp | 59 +++++++++++++------------- apps/openmw/mwworld/containerstore.hpp | 11 +++++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 2d5a9bbd3..7d12c7b6e 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -57,42 +57,43 @@ namespace return MWWorld::Ptr(); } +} - template - void getState (MWWorld::CellRefList& collection, const ESM::ObjectState& state) - { - if (!MWWorld::LiveCellRef::checkState (state)) - return; // not valid anymore with current content files -> skip +template +void MWWorld::ContainerStore::getState (CellRefList& collection, const ESM::ObjectState& state) +{ + if (!LiveCellRef::checkState (state)) + return; // not valid anymore with current content files -> skip - const T *record = MWBase::Environment::get().getWorld()->getStore(). - get().search (state.mRef.mRefID); + const T *record = MWBase::Environment::get().getWorld()->getStore(). + get().search (state.mRef.mRefID); - if (!record) - return; + if (!record) + return; - MWWorld::LiveCellRef ref (record); - ref.load (state); - ref.mRef.mRefNum.mContentFile = -1; - collection.mList.push_back (ref); - } + LiveCellRef ref (record); + ref.load (state); + ref.mRef.mRefNum.mContentFile = -1; + collection.mList.push_back (ref); +} - template - void storeState (const MWWorld::LiveCellRef& ref, ESM::ObjectState& state) - { - ref.save (state); - } +template +void MWWorld::ContainerStore::storeState (const LiveCellRef& ref, ESM::ObjectState& state) + const +{ + ref.save (state); +} - template - void storeStates (const MWWorld::CellRefList& collection, - std::vector > >& states) +template +void MWWorld::ContainerStore::storeStates (const CellRefList& collection, + std::vector > >& states) const +{ + for (typename CellRefList::List::const_iterator iter (collection.mList.begin()); + iter!=collection.mList.end(); ++iter) { - for (typename MWWorld::CellRefList::List::const_iterator iter (collection.mList.begin()); - iter!=collection.mList.end(); ++iter) - { - ESM::ObjectState state; - storeState (*iter, state); - states.push_back (std::make_pair (state, std::make_pair (T::sRecordId, -1))); - } + ESM::ObjectState state; + storeState (*iter, state); + states.push_back (std::make_pair (state, std::make_pair (T::sRecordId, -1))); } } diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 3bdefb1ec..5e305d408 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -57,6 +57,17 @@ namespace MWWorld ContainerStoreIterator addImp (const Ptr& ptr, int count); void addInitialItem (const std::string& id, const std::string& owner, const std::string& faction, int count, bool topLevel=true); + template + void getState (CellRefList& collection, const ESM::ObjectState& state); + + template + void storeState (const LiveCellRef& ref, ESM::ObjectState& state) const; + + template + void storeStates (const CellRefList& collection, + std::vector > >& states) + const; + public: ContainerStore();