Browse Source

Added move constructor for BonusList

AlexVinS 9 years ago
parent
commit
d42947f109
2 changed files with 11 additions and 12 deletions
  1. 10 10
      lib/HeroBonus.cpp
  2. 1 2
      lib/HeroBonus.h

+ 10 - 10
lib/HeroBonus.cpp

@@ -97,6 +97,13 @@ BonusList::BonusList(const BonusList &bonusList)
 	belongsToTree = false;
 }
 
+BonusList::BonusList(BonusList&& other):
+	belongsToTree(false)
+{
+	std::swap(belongsToTree, other.belongsToTree);
+	std::swap(bonuses, other.bonuses);
+}
+
 BonusList& BonusList::operator=(const BonusList &bonusList)
 {
 	bonuses.resize(bonusList.size());
@@ -705,23 +712,16 @@ CBonusSystemNode::CBonusSystemNode() : bonuses(true), exportedBonuses(true), nod
 }
 
 CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other):
-	bonuses(other.bonuses),
-	exportedBonuses(other.exportedBonuses),
+	bonuses(std::move(other.bonuses)),
+	exportedBonuses(std::move(other.exportedBonuses)),
 	nodeType(other.nodeType),
 	description(other.description),
 	cachedLast(0)
 {
-	//todo: move constructor for bonuslist
-	other.bonuses.clear();
-	other.exportedBonuses.clear();
-
-	bonuses.belongsToTree = true;
-	exportedBonuses.belongsToTree = true;
-
 	std::swap(parents, other.parents);
 	std::swap(children, other.children);
 
-	//TODO: move cache
+	//cache ignored
 
 	//cachedBonuses
 	//cachedRequests

+ 1 - 2
lib/HeroBonus.h

@@ -423,6 +423,7 @@ public:
 
 	BonusList(bool BelongsToTree = false);
 	BonusList(const BonusList &bonusList);
+	BonusList(BonusList && other);
 	BonusList& operator=(const BonusList &bonusList);
 
 	// wrapper functions of the STL vector container
@@ -494,8 +495,6 @@ public:
 	{
 		return bonuses.end();
 	}
-
-	friend class CBonusSystemNode;
 };
 
 // Extensions for BOOST_FOREACH to enable iterating of BonusList objects