diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 3334732164..a56c05bb3e 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -135,7 +135,7 @@ namespace MWClass const std::string trapActivationSound = "Disarm Trap Fail"; MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); + const MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); bool isLocked = ptr.getCellRef().getLockLevel() > 0; bool isTrapped = !ptr.getCellRef().getTrap().empty(); diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 830ba258b9..425a2f7060 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -106,7 +106,7 @@ namespace MWClass const std::string lockedSound = "LockedDoor"; const std::string trapActivationSound = "Disarm Trap Fail"; - MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); + const MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); bool isLocked = ptr.getCellRef().getLockLevel() > 0; bool isTrapped = !ptr.getCellRef().getTrap().empty(); @@ -130,7 +130,7 @@ namespace MWClass // make key id lowercase std::string keyId = ptr.getCellRef().getKey(); Misc::StringUtils::lowerCaseInPlace(keyId); - for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) + for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(); it != invStore.cend(); ++it) { std::string refId = it->getCellRef().getRefId(); Misc::StringUtils::lowerCaseInPlace(refId); diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 481e1ceb47..376fc71527 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -44,10 +44,10 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor) MWWorld::Ptr player = MWMechanics::getPlayer(); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); - MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); + const MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; - for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); - iter!=store.end(); ++iter) + for (MWWorld::ConstContainerStoreIterator iter (store.cbegin(categories)); + iter!=store.cend(); ++iter) { if (iter->getClass().hasItemHealth(*iter)) { diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 5dcd5212cf..d47396f041 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -33,7 +33,8 @@ ActorAnimation::ActorAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr { MWWorld::ContainerStore& store = mPtr.getClass().getContainerStore(mPtr); - for (MWWorld::ContainerStoreIterator iter = store.begin(MWWorld::ContainerStore::Type_Light); iter != store.end(); ++iter) + for (MWWorld::ConstContainerStoreIterator iter = store.cbegin(MWWorld::ContainerStore::Type_Light); + iter != store.cend(); ++iter) { const ESM::Light* light = iter->get()->mBase; if (!(light->mData.mFlags & ESM::Light::Carry)) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 0b4c9a0fc5..e5880ee37f 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -140,7 +140,7 @@ namespace MWScript MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); std::string itemName; - for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) + for (MWWorld::ConstContainerStoreIterator iter(store.cbegin()); iter != store.cend(); ++iter) if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) itemName = iter->getClass().getName(*iter); @@ -316,9 +316,9 @@ namespace MWScript runtime.pop(); int count = 0; - MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); - for (MWWorld::ContainerStoreIterator it = invStore.begin(MWWorld::ContainerStore::Type_Miscellaneous); - it != invStore.end(); ++it) + const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); + for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(MWWorld::ContainerStore::Type_Miscellaneous); + it != invStore.cend(); ++it) { if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), name)) count += it->getRefData().getCount(); diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index c3c7f918d9..a5090a66ad 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -117,16 +117,6 @@ MWWorld::ContainerStore::ContainerStore() : mListener(NULL), mCachedWeight (0), MWWorld::ContainerStore::~ContainerStore() {} -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask) -{ - return ContainerStoreIterator (mask, this); -} - -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end() -{ - return ContainerStoreIterator (this); -} - MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cbegin (int mask) const { return ConstContainerStoreIterator (mask, this); @@ -137,6 +127,26 @@ MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cend() const return ConstContainerStoreIterator (this); } +MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::begin (int mask) const +{ + return cbegin(mask); +} + +MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::end() const +{ + return cend(); +} + +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask) +{ + return ContainerStoreIterator (mask, this); +} + +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end() +{ + return ContainerStoreIterator (this); +} + int MWWorld::ContainerStore::count(const std::string &id) { int total=0; @@ -199,7 +209,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::restack(const MWWorld:: return retval; } -bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) +bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) const { const MWWorld::Class& cls1 = ptr1.getClass(); const MWWorld::Class& cls2 = ptr2.getClass(); @@ -800,7 +810,7 @@ void MWWorld::ContainerStore::readState (const ESM::InventoryState& inventory) template template -void MWWorld::ContainerStoreIteratorBase::copy(const ContainerStoreIteratorBase& src) +void MWWorld::ContainerStoreIteratorBase::copy (const ContainerStoreIteratorBase& src) { mType = src.mType; mMask = src.mMask; diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index c10b87fdad..9849dbf262 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -119,13 +119,13 @@ namespace MWWorld virtual ContainerStore* clone() { return new ContainerStore(*this); } - ContainerStoreIterator begin (int mask = Type_All); - - ContainerStoreIterator end(); - ConstContainerStoreIterator cbegin (int mask = Type_All) const; - ConstContainerStoreIterator cend() const; + ConstContainerStoreIterator begin (int mask = Type_All) const; + ConstContainerStoreIterator end() const; + + ContainerStoreIterator begin (int mask = Type_All); + ContainerStoreIterator end(); virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool setOwner=false); ///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed) @@ -176,7 +176,7 @@ namespace MWWorld public: - virtual bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2); + virtual bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2) const; ///< @return true if the two specified objects can stack with each other void fill (const ESM::InventoryList& items, const std::string& owner);