1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

reduced code duplication

This commit is contained in:
AlexVinS 2016-07-29 13:10:32 +03:00
parent 629922f43e
commit 681b3c7078
2 changed files with 14 additions and 40 deletions

View File

@ -105,6 +105,12 @@ BonusList& BonusList::operator=(const BonusList &bonusList)
return *this;
}
void BonusList::changed()
{
if(belongsToTree)
CBonusSystemNode::treeHasChanged();
}
int BonusList::totalValue() const
{
int base = 0;
@ -258,24 +264,19 @@ void BonusList::eliminateDuplicates()
void BonusList::push_back(Bonus* const &x)
{
bonuses.push_back(x);
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
}
std::vector<Bonus*>::iterator BonusList::erase(const int position)
{
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
return bonuses.erase(bonuses.begin() + position);
}
void BonusList::clear()
{
bonuses.clear();
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
}
std::vector<BonusList*>::size_type BonusList::operator-=(Bonus* const &i)
@ -284,26 +285,20 @@ std::vector<BonusList*>::size_type BonusList::operator-=(Bonus* const &i)
if(itr == bonuses.end())
return false;
bonuses.erase(itr);
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
return true;
}
void BonusList::resize(std::vector<Bonus*>::size_type sz, Bonus* c )
{
bonuses.resize(sz, c);
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
}
void BonusList::insert(std::vector<Bonus*>::iterator position, std::vector<Bonus*>::size_type n, Bonus* const &x)
{
bonuses.insert(position, n, x);
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
}
int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector) const

View File

@ -412,7 +412,7 @@ private:
TInternalContainer bonuses;
bool belongsToTree;
void changed();
public:
typedef TInternalContainer::const_reference const_reference;
@ -496,11 +496,8 @@ public:
}
friend class CBonusSystemNode;
//friend inline std::vector<Bonus*>::iterator range_begin(BonusList & x);
//friend inline std::vector<Bonus*>::iterator range_end(BonusList & x);
};
// Extensions for BOOST_FOREACH to enable iterating of BonusList objects
// Don't touch/call this functions
inline BonusList::iterator range_begin(BonusList & x)
@ -1011,23 +1008,5 @@ template <class InputIterator>
void BonusList::insert(const int position, InputIterator first, InputIterator last)
{
bonuses.insert(bonuses.begin() + position, first, last);
if (belongsToTree)
CBonusSystemNode::treeHasChanged();
changed();
}
// Extensions for BOOST_FOREACH to enable iterating of BonusList objects
/*namespace boost
{
template<>
struct range_mutable_iterator<BonusList>
{
typedef std::vector<Bonus*>::iterator type;
};
template<>
struct range_const_iterator<BonusList>
{
typedef std::vector<Bonus*>::const_iterator type;
};
}*/