Add move constructor to MWMechanics::Spells

pull/593/head
elsid 4 years ago
parent 46e34c500c
commit ca7add0624
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -164,4 +164,12 @@ namespace MWMechanics
if (it != mListeners.end())
mListeners.erase(it);
}
void SpellList::updateListener(Spells* before, Spells* after)
{
const auto it = std::find(mListeners.begin(), mListeners.end(), before);
if (it == mListeners.end())
return mListeners.push_back(after);
*it = after;
}
}

@ -61,6 +61,8 @@ namespace MWMechanics
void removeListener(Spells* spells);
void updateListener(Spells* before, Spells* after);
const std::vector<std::string> getSpells() const;
};
}

@ -32,6 +32,15 @@ namespace MWMechanics
mSpellList->addListener(this);
}
Spells::Spells(Spells&& spells) : mSpellList(std::move(spells.mSpellList)), mSpells(std::move(spells.mSpells)),
mSelectedSpell(std::move(spells.mSelectedSpell)), mUsedPowers(std::move(spells.mUsedPowers)),
mSpellsChanged(std::move(spells.mSpellsChanged)), mEffects(std::move(spells.mEffects)),
mSourcedEffects(std::move(spells.mSourcedEffects))
{
if (mSpellList)
mSpellList->updateListener(&spells, this);
}
std::map<const ESM::Spell*, SpellParams>::const_iterator Spells::begin() const
{
return mSpells.begin();

@ -59,7 +59,7 @@ namespace MWMechanics
Spells(const Spells&);
Spells(const Spells&&) = delete;
Spells(Spells&& spells);
~Spells();

Loading…
Cancel
Save