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:
parent
629922f43e
commit
681b3c7078
@ -105,6 +105,12 @@ BonusList& BonusList::operator=(const BonusList &bonusList)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BonusList::changed()
|
||||||
|
{
|
||||||
|
if(belongsToTree)
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
int BonusList::totalValue() const
|
int BonusList::totalValue() const
|
||||||
{
|
{
|
||||||
int base = 0;
|
int base = 0;
|
||||||
@ -258,24 +264,19 @@ void BonusList::eliminateDuplicates()
|
|||||||
void BonusList::push_back(Bonus* const &x)
|
void BonusList::push_back(Bonus* const &x)
|
||||||
{
|
{
|
||||||
bonuses.push_back(x);
|
bonuses.push_back(x);
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Bonus*>::iterator BonusList::erase(const int position)
|
std::vector<Bonus*>::iterator BonusList::erase(const int position)
|
||||||
{
|
{
|
||||||
if (belongsToTree)
|
changed();
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
return bonuses.erase(bonuses.begin() + position);
|
return bonuses.erase(bonuses.begin() + position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BonusList::clear()
|
void BonusList::clear()
|
||||||
{
|
{
|
||||||
bonuses.clear();
|
bonuses.clear();
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BonusList*>::size_type BonusList::operator-=(Bonus* const &i)
|
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())
|
if(itr == bonuses.end())
|
||||||
return false;
|
return false;
|
||||||
bonuses.erase(itr);
|
bonuses.erase(itr);
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BonusList::resize(std::vector<Bonus*>::size_type sz, Bonus* c )
|
void BonusList::resize(std::vector<Bonus*>::size_type sz, Bonus* c )
|
||||||
{
|
{
|
||||||
bonuses.resize(sz, c);
|
bonuses.resize(sz, c);
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BonusList::insert(std::vector<Bonus*>::iterator position, std::vector<Bonus*>::size_type n, Bonus* const &x)
|
void BonusList::insert(std::vector<Bonus*>::iterator position, std::vector<Bonus*>::size_type n, Bonus* const &x)
|
||||||
{
|
{
|
||||||
bonuses.insert(position, n, x);
|
bonuses.insert(position, n, x);
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector) const
|
int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector) const
|
||||||
|
@ -412,7 +412,7 @@ private:
|
|||||||
|
|
||||||
TInternalContainer bonuses;
|
TInternalContainer bonuses;
|
||||||
bool belongsToTree;
|
bool belongsToTree;
|
||||||
|
void changed();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef TInternalContainer::const_reference const_reference;
|
typedef TInternalContainer::const_reference const_reference;
|
||||||
@ -496,11 +496,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
friend class CBonusSystemNode;
|
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
|
// Extensions for BOOST_FOREACH to enable iterating of BonusList objects
|
||||||
// Don't touch/call this functions
|
// Don't touch/call this functions
|
||||||
inline BonusList::iterator range_begin(BonusList & x)
|
inline BonusList::iterator range_begin(BonusList & x)
|
||||||
@ -1011,23 +1008,5 @@ template <class InputIterator>
|
|||||||
void BonusList::insert(const int position, InputIterator first, InputIterator last)
|
void BonusList::insert(const int position, InputIterator first, InputIterator last)
|
||||||
{
|
{
|
||||||
bonuses.insert(bonuses.begin() + position, first, last);
|
bonuses.insert(bonuses.begin() + position, first, last);
|
||||||
|
changed();
|
||||||
if (belongsToTree)
|
|
||||||
CBonusSystemNode::treeHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
};
|
|
||||||
}*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user