Pārlūkot izejas kodu

reduced code duplication

AlexVinS 9 gadi atpakaļ
vecāks
revīzija
681b3c7078
2 mainītis faili ar 14 papildinājumiem un 40 dzēšanām
  1. 12 17
      lib/HeroBonus.cpp
  2. 2 23
      lib/HeroBonus.h

+ 12 - 17
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<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

+ 2 - 23
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<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;
-	};
-}*/