From 681b3c70780335ec8ea91fbd2bfdf5b2f9b4d497 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Fri, 29 Jul 2016 13:10:32 +0300 Subject: [PATCH] reduced code duplication --- lib/HeroBonus.cpp | 29 ++++++++++++----------------- lib/HeroBonus.h | 25 ++----------------------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index bb527f6ca..8f7108036 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -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::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::size_type BonusList::operator-=(Bonus* const &i) @@ -284,26 +285,20 @@ std::vector::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::size_type sz, Bonus* c ) { bonuses.resize(sz, c); - - if (belongsToTree) - CBonusSystemNode::treeHasChanged(); + changed(); } void BonusList::insert(std::vector::iterator position, std::vector::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 diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index ba637dacc..ad9dd80ac 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -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::iterator range_begin(BonusList & x); - //friend inline std::vector::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 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 - { - typedef std::vector::iterator type; - }; - - template<> - struct range_const_iterator - { - typedef std::vector::const_iterator type; - }; -}*/