ソースを参照

CArtifactsOfHero: use shared_ptr for SCommonPart

Arseniy Shestakov 9 年 前
コミット
0236309d25

+ 2 - 2
client/widgets/CArtifactHolder.cpp

@@ -595,7 +595,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWo
 {
 	if(createCommonPart)
 	{
-		commonInfo = new CArtifactsOfHero::SCommonPart;
+		commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
 		commonInfo->participants.insert(this);
 	}
 
@@ -622,7 +622,7 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart
 {
 	if(createCommonPart)
 	{
-		commonInfo = new CArtifactsOfHero::SCommonPart;
+		commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
 		commonInfo->participants.insert(this);
 	}
 

+ 2 - 1
client/widgets/CArtifactHolder.h

@@ -107,7 +107,8 @@ public:
 		std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
 
 		void reset();
-	} * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
+	};
+	std::shared_ptr<SCommonPart> commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
 
 	bool updateState; // Whether the commonInfo should be updated on setHero or not.
 

+ 1 - 1
client/widgets/CGarrisonInt.cpp

@@ -169,7 +169,7 @@ bool CGarrisonSlot::highlightOrDropArtifact()
 	bool artSelected = false;
 	if (CWindowWithArtifacts* chw = dynamic_cast<CWindowWithArtifacts*>(GH.topInt())) //dirty solution
 	{
-		const CArtifactsOfHero::SCommonPart *commonInfo = chw->artSets.front()->commonInfo;
+		const std::shared_ptr<CArtifactsOfHero::SCommonPart> commonInfo = chw->artSets.front()->commonInfo;
 		if (const CArtifactInstance *art = commonInfo->src.art)
 		{
 			const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();

+ 2 - 2
client/windows/CHeroWindow.cpp

@@ -47,7 +47,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector
 	TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero);
 	TBonusListPtr bonusesFromPickedUpArtifact;
 
-	CArtifactsOfHero::SCommonPart *cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr;
+	std::shared_ptr<CArtifactsOfHero::SCommonPart> cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr;
 	if(cp && cp->src.art && cp->src.valid() && cp->src.AOH && cp->src.AOH->getHero() == hero)
 	{
 		bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero);
@@ -317,7 +317,7 @@ void CHeroWindow::commanderWindow()
 {
 	//TODO: allow equipping commander artifacts by drag / drop
 	//bool artSelected = false;
-	const CArtifactsOfHero::SCommonPart *commonInfo = artSets.front()->commonInfo;
+	const std::shared_ptr<CArtifactsOfHero::SCommonPart> commonInfo = artSets.front()->commonInfo;
 
 	if (const CArtifactInstance *art = commonInfo->src.art)
 	{

+ 1 - 1
client/windows/CTradeWindow.cpp

@@ -390,7 +390,7 @@ void CTradeWindow::initItems(bool Left)
 
 		BLOCK_CAPTURING;
 		arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset));
-		arts->commonInfo = new CArtifactsOfHero::SCommonPart;
+		arts->commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
 		arts->commonInfo->participants.insert(arts);
 		arts->recActions = 255;
 		arts->setHero(hero);

+ 1 - 2
client/windows/GUIClasses.cpp

@@ -908,7 +908,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 	prepareBackground();
 
 	artifs[0] = new CArtifactsOfHero(Point(-334, 150));
-	artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart;
+	artifs[0]->commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
 	artifs[0]->commonInfo->participants.insert(artifs[0]);
 	artifs[0]->setHero(heroInst[0]);
 	artifs[1] = new CArtifactsOfHero(Point(96, 150));
@@ -1004,7 +1004,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 
 CExchangeWindow::~CExchangeWindow() //d-tor
 {
-	delete artifs[0]->commonInfo;
 	artifs[0]->commonInfo = nullptr;
 	artifs[1]->commonInfo = nullptr;
 }