Porting code to ConstContainerStoreIterator #1

0.6.1
Rafael Moura 8 years ago
parent ecbde7b11e
commit 9963601484

@ -135,7 +135,7 @@ namespace MWClass
const std::string trapActivationSound = "Disarm Trap Fail"; const std::string trapActivationSound = "Disarm Trap Fail";
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); 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 isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty(); bool isTrapped = !ptr.getCellRef().getTrap().empty();

@ -106,7 +106,7 @@ namespace MWClass
const std::string lockedSound = "LockedDoor"; const std::string lockedSound = "LockedDoor";
const std::string trapActivationSound = "Disarm Trap Fail"; 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 isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty(); bool isTrapped = !ptr.getCellRef().getTrap().empty();
@ -130,7 +130,7 @@ namespace MWClass
// make key id lowercase // make key id lowercase
std::string keyId = ptr.getCellRef().getKey(); std::string keyId = ptr.getCellRef().getKey();
Misc::StringUtils::lowerCaseInPlace(keyId); 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(); std::string refId = it->getCellRef().getRefId();
Misc::StringUtils::lowerCaseInPlace(refId); Misc::StringUtils::lowerCaseInPlace(refId);

@ -44,10 +44,10 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor)
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); 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; int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor;
for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); for (MWWorld::ConstContainerStoreIterator iter (store.cbegin(categories));
iter!=store.end(); ++iter) iter!=store.cend(); ++iter)
{ {
if (iter->getClass().hasItemHealth(*iter)) if (iter->getClass().hasItemHealth(*iter))
{ {

@ -33,7 +33,8 @@ ActorAnimation::ActorAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group>
{ {
MWWorld::ContainerStore& store = mPtr.getClass().getContainerStore(mPtr); 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<ESM::Light>()->mBase; const ESM::Light* light = iter->get<ESM::Light>()->mBase;
if (!(light->mData.mFlags & ESM::Light::Carry)) if (!(light->mData.mFlags & ESM::Light::Carry))

@ -140,7 +140,7 @@ namespace MWScript
MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr);
std::string itemName; 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)) if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item))
itemName = iter->getClass().getName(*iter); itemName = iter->getClass().getName(*iter);
@ -316,9 +316,9 @@ namespace MWScript
runtime.pop(); runtime.pop();
int count = 0; int count = 0;
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
for (MWWorld::ContainerStoreIterator it = invStore.begin(MWWorld::ContainerStore::Type_Miscellaneous); for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(MWWorld::ContainerStore::Type_Miscellaneous);
it != invStore.end(); ++it) it != invStore.cend(); ++it)
{ {
if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), name)) if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), name))
count += it->getRefData().getCount(); count += it->getRefData().getCount();

@ -117,24 +117,34 @@ MWWorld::ContainerStore::ContainerStore() : mListener(NULL), mCachedWeight (0),
MWWorld::ContainerStore::~ContainerStore() {} MWWorld::ContainerStore::~ContainerStore() {}
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask) MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cbegin (int mask) const
{ {
return ContainerStoreIterator (mask, this); return ConstContainerStoreIterator (mask, this);
} }
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end() MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cend() const
{ {
return ContainerStoreIterator (this); return ConstContainerStoreIterator (this);
} }
MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cbegin (int mask) const MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::begin (int mask) const
{ {
return ConstContainerStoreIterator (mask, this); return cbegin(mask);
} }
MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::cend() const MWWorld::ConstContainerStoreIterator MWWorld::ContainerStore::end() const
{ {
return ConstContainerStoreIterator (this); 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 MWWorld::ContainerStore::count(const std::string &id)
@ -199,7 +209,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::restack(const MWWorld::
return retval; 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& cls1 = ptr1.getClass();
const MWWorld::Class& cls2 = ptr2.getClass(); const MWWorld::Class& cls2 = ptr2.getClass();
@ -800,7 +810,7 @@ void MWWorld::ContainerStore::readState (const ESM::InventoryState& inventory)
template<class PtrType> template<class PtrType>
template<class T> template<class T>
void MWWorld::ContainerStoreIteratorBase<PtrType>::copy(const ContainerStoreIteratorBase<T>& src) void MWWorld::ContainerStoreIteratorBase<PtrType>::copy (const ContainerStoreIteratorBase<T>& src)
{ {
mType = src.mType; mType = src.mType;
mMask = src.mMask; mMask = src.mMask;

@ -119,13 +119,13 @@ namespace MWWorld
virtual ContainerStore* clone() { return new ContainerStore(*this); } virtual ContainerStore* clone() { return new ContainerStore(*this); }
ContainerStoreIterator begin (int mask = Type_All);
ContainerStoreIterator end();
ConstContainerStoreIterator cbegin (int mask = Type_All) const; ConstContainerStoreIterator cbegin (int mask = Type_All) const;
ConstContainerStoreIterator cend() 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); 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) ///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
@ -176,7 +176,7 @@ namespace MWWorld
public: 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 ///< @return true if the two specified objects can stack with each other
void fill (const ESM::InventoryList& items, const std::string& owner); void fill (const ESM::InventoryList& items, const std::string& owner);

Loading…
Cancel
Save