浏览代码

get rid of boost::assign

AlexVinS 11 年之前
父节点
当前提交
54453aee73

+ 7 - 1
Global.h

@@ -126,7 +126,6 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
 #define BOOST_BIND_NO_PLACEHOLDERS
 
 #include <boost/algorithm/string.hpp>
-#include <boost/assign.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/current_function.hpp>
 #include <boost/crc.hpp>
@@ -676,6 +675,13 @@ namespace vstd
 		boost::sort(vec);
 		vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
 	}
+	
+	template <typename T>
+	void concatenate(std::vector<T> &dest, const std::vector<T> &src)
+	{
+		dest.reserve(dest.size() + src.size());
+		dest.insert(dest.end(), src.begin(), src.end());	
+	}
 
 	using boost::math::round;
 }

+ 1 - 2
client/windows/CAdvmapInterface.cpp

@@ -55,7 +55,6 @@
 
 #define ADVOPT (conf.go()->ac)
 using namespace boost::logic;
-using namespace boost::assign;
 using namespace CSDL_Ext;
 
 CAdvMapInt *adventureInt;
@@ -692,7 +691,7 @@ bool CAdvMapInt::isHeroSleeping(const CGHeroInstance *hero)
 void CAdvMapInt::setHeroSleeping(const CGHeroInstance *hero, bool sleep)
 {
 	if (sleep)
-		LOCPLINT->sleepingHeroes += hero;
+		LOCPLINT->sleepingHeroes.push_back(hero); //FIXME: should we check for existence?
 	else
 		LOCPLINT->sleepingHeroes -= hero;
 	updateNextHero(nullptr);

+ 19 - 16
client/windows/CCastleInterface.cpp

@@ -32,8 +32,6 @@
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 
-using namespace boost::assign;
-
 /*
  * CCastleInterface.cpp, part of VCMI engine
  *
@@ -1449,15 +1447,20 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
 	exit = new CButton(Point(748, 556), "TPMAGE1", CButton::tooltip(text), [&]{ close(); }, SDLK_RETURN);
 	exit->assignedKeys.insert(SDLK_ESCAPE);
 
-	std::vector<Point> positions;
-	positions += Point(10,  22), Point(404, 22),
-	             Point(10, 155), Point(404,155),
-	             Point(10, 288), Point(404,288);
+	std::vector<Point> positions =
+	{
+		Point(10,  22), Point(404, 22),
+		Point(10, 155), Point(404,155),
+		Point(10, 288), Point(404,288)
+	};
 
 	if (fortSize == GameConstants::CREATURES_PER_TOWN)
-		positions += Point(206,421);
+		positions.push_back(Point(206,421));
 	else
-		positions += Point(10, 421), Point(404,421);
+	{
+		positions.push_back(Point(10, 421));
+		positions.push_back(Point(404,421));
+	}		
 
 	for (ui32 i=0; i<fortSize; i++)
 	{
@@ -1658,14 +1661,14 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner,std::string imagem)
 	exit = new CButton(Point(748, 556), "TPMAGE1.DEF", CButton::tooltip(CGI->generaltexth->allTexts[593]), [&]{ close(); }, SDLK_RETURN);
 	exit->assignedKeys.insert(SDLK_ESCAPE);
 
-	std::vector<std::vector<Point> > positions;
-
-	positions.resize(5);
-	positions[0] += Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445);
-	positions[1] += Point(48,53),   Point(48,147),  Point(48,241),  Point(48,335),  Point(48,429);
-	positions[2] += Point(570,82),  Point(672,82),  Point(570,157), Point(672,157);
-	positions[3] += Point(183,42),  Point(183,148), Point(183,253);
-	positions[4] += Point(491,325), Point(591,325);
+	static const std::vector<std::vector<Point> > positions = 
+	{
+		{Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445)},
+		{Point(48,53),   Point(48,147),  Point(48,241),  Point(48,335),  Point(48,429)},
+		{Point(570,82),  Point(672,82),  Point(570,157), Point(672,157)},
+		{Point(183,42),  Point(183,148), Point(183,253)},
+		{Point(491,325), Point(591,325)}
+	};
 
 	for(size_t i=0; i<owner->town->town->mageLevel; i++)
 	{

+ 0 - 1
client/windows/CHeroWindow.cpp

@@ -39,7 +39,6 @@
  *
  */
 
-using namespace boost::assign;
 
 const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root /*= nullptr*/, const std::string &cachingStr /*= ""*/) const
 {

+ 11 - 8
client/windows/CTradeWindow.cpp

@@ -471,8 +471,6 @@ std::vector<int> *CTradeWindow::getItemsIds(bool Left)
 
 void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const
 {
-	using namespace boost::assign;
-
 	if(mode == EMarketMode::ARTIFACT_EXP && !Left)
 	{
 		//22 boxes, 5 in row, last row: two boxes centered
@@ -484,10 +482,10 @@ void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType typ
 		dy = 70;
 		for (int i = 0; i < 4 ; i++)
 			for (int j = 0; j < 5 ; j++)
-				poss += Rect(x + dx*j, y + dy*i, w, h);
+				poss.push_back(Rect(x + dx*j, y + dy*i, w, h));
 
-		poss += Rect(x + dx*1.5, y + dy*4, w, h);
-		poss += Rect(x + dx*2.5, y + dy*4, w, h);
+		poss.push_back(Rect(x + dx*1.5, y + dy*4, w, h));
+		poss.push_back(Rect(x + dx*2.5, y + dy*4, w, h));
 	}
 	else
 	{
@@ -498,10 +496,15 @@ void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType typ
 		int h, w, x, y, dx, dy;
 		int leftToRightOffset;
 		getBaseForPositions(type, dx, dy, x, y, h, w, !Left, leftToRightOffset);
-
-		poss += genRect(h, w, x, y), genRect(h, w, x + dx, y), genRect(h, w, x + 2*dx, y),
+		
+		const std::vector<Rect> tmp = 
+		{
+			genRect(h, w, x, y), genRect(h, w, x + dx, y), genRect(h, w, x + 2*dx, y),
 			genRect(h, w, x, y + dy), genRect(h, w, x + dx, y + dy), genRect(h, w, x + 2*dx, y + dy),
-			genRect(h, w, x + dx, y + 2*dy);
+			genRect(h, w, x + dx, y + 2*dy)			
+		};
+		
+		vstd::concatenate(poss, tmp);
 
 		if(!Left)
 		{

+ 0 - 1
client/windows/GUIClasses.cpp

@@ -61,7 +61,6 @@
  *
  */
 
-using namespace boost::assign;
 using namespace CSDL_Ext;
 
 std::list<CFocusable*> CFocusable::focusables;

+ 12 - 4
lib/CArtHandler.cpp

@@ -23,8 +23,6 @@
 
 #include "mapObjects/CObjectClassesHandler.h"
 
-using namespace boost::assign;
-
 // Note: list must match entries in ArtTraits.txt
 #define ART_POS_LIST    \
 	ART_POS(SPELLBOOK)  \
@@ -277,13 +275,23 @@ ArtifactPosition CArtHandler::stringToSlot(std::string slotName)
 
 void CArtHandler::addSlot(CArtifact * art, const std::string & slotID)
 {
+	static const std::vector<ArtifactPosition> miscSlots = 
+	{
+		ArtifactPosition::MISC1, ArtifactPosition::MISC2, ArtifactPosition::MISC3, ArtifactPosition::MISC4, ArtifactPosition::MISC5
+	};
+	
+	static const std::vector<ArtifactPosition> ringSlots =
+	{
+		ArtifactPosition::LEFT_RING, ArtifactPosition::RIGHT_RING
+	};
+	
 	if (slotID == "MISC")
 	{
-		art->possibleSlots[ArtBearer::HERO] += ArtifactPosition::MISC1, ArtifactPosition::MISC2, ArtifactPosition::MISC3, ArtifactPosition::MISC4, ArtifactPosition::MISC5;
+		vstd::concatenate(art->possibleSlots[ArtBearer::HERO], miscSlots);
 	}
 	else if (slotID == "RING")
 	{
-		art->possibleSlots[ArtBearer::HERO] += ArtifactPosition::LEFT_RING, ArtifactPosition::RIGHT_RING;
+		vstd::concatenate(art->possibleSlots[ArtBearer::HERO], ringSlots);
 	}
 	else
 	{

+ 0 - 1
lib/CBuildingHandler.cpp

@@ -14,7 +14,6 @@
 
 BuildingID CBuildingHandler::campToERMU( int camp, int townType, std::set<BuildingID> builtBuildings )
 {
-	using namespace boost::assign;
 	static const std::vector<BuildingID> campToERMU = 
 	{
 		BuildingID::TOWN_HALL, BuildingID::CITY_HALL,

+ 0 - 2
lib/CCreatureHandler.cpp

@@ -11,8 +11,6 @@
 
 #include "mapObjects/CObjectClassesHandler.h"
 
-using namespace boost::assign;
-
 /*
  * CCreatureHandler.cpp, part of VCMI engine
  *

+ 0 - 2
lib/CSpellHandler.cpp

@@ -26,8 +26,6 @@ namespace SpellConfig
 
 }
 
-using namespace boost::assign;
-
 namespace SRSLPraserHelpers
 {
 	static int XYToHex(int x, int y)

+ 0 - 2
lib/mapObjects/CArmedInstance.cpp

@@ -16,8 +16,6 @@
 #include "../CGeneralTextHandler.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 void CArmedInstance::randomizeArmy(int type)
 {
 	for (auto & elem : stacks)

+ 0 - 2
lib/mapObjects/CBank.cpp

@@ -19,8 +19,6 @@
 #include "../IGameCallback.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 ///helpers
 static std::string & visitedTxt(const bool visited)
 {

+ 8 - 7
lib/mapObjects/CGHeroInstance.cpp

@@ -22,8 +22,6 @@
 #include "../CGameState.h"
 #include "../CCreatureHandler.h"
 
-using namespace boost::assign;
-
 ///helpers
 static void showInfoDialog(const PlayerColor playerID, const ui32 txtID, const ui16 soundID)
 {
@@ -1050,9 +1048,10 @@ int CGHeroInstance::getBoatType() const
 
 void CGHeroInstance::getOutOffsets(std::vector<int3> &offsets) const
 {
-	static int3 dirs[] = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0), int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) };
-	for (auto & dir : dirs)
-		offsets += dir;
+	offsets = 
+	{ 
+		int3(0,1,0), int3(0,-1,0), int3(-1,0,0), int3(+1,0,0), int3(1,1,0), int3(-1,1,0), int3(1,-1,0), int3(-1,-1,0) 
+	};
 }
 
 int CGHeroInstance::getSpellCost(const CSpell *sp) const
@@ -1162,8 +1161,10 @@ std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills()
 	}
 	if (!skillsInfo.magicSchoolCounter)
 	{
-		std::vector<SecondarySkill> ss;
-		ss += SecondarySkill::FIRE_MAGIC, SecondarySkill::AIR_MAGIC, SecondarySkill::WATER_MAGIC, SecondarySkill::EARTH_MAGIC;
+		std::vector<SecondarySkill> ss =
+		{
+			SecondarySkill::FIRE_MAGIC, SecondarySkill::AIR_MAGIC, SecondarySkill::WATER_MAGIC, SecondarySkill::EARTH_MAGIC
+		};
 
 		std::shuffle(ss.begin(), ss.end(), skillsInfo.rand.getStdGenerator());
 

+ 0 - 2
lib/mapObjects/CGMarket.cpp

@@ -18,8 +18,6 @@
 #include "../CCreatureHandler.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 ///helpers
 static void openWindow(const OpenWindow::EWindow type, const int id1, const int id2 = -1)
 {

+ 0 - 2
lib/mapObjects/CGPandoraBox.cpp

@@ -18,8 +18,6 @@
 #include "../StartInfo.h"
 #include "../IGameCallback.h"
 
-using namespace boost::assign;
-
 ///helpers
 static void showInfoDialog(const PlayerColor playerID, const ui32 txtID, const ui16 soundID)
 {

+ 1 - 3
lib/mapObjects/CGTownInstance.cpp

@@ -18,8 +18,6 @@
 #include "../IGameCallback.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
 std::vector<int> CGTownInstance::universitySkills;
 
@@ -676,7 +674,7 @@ bool CGTownInstance::passableFor(PlayerColor color) const
 
 void CGTownInstance::getOutOffsets( std::vector<int3> &offsets ) const
 {
-	offsets += int3(-1,2,0), int3(-3,2,0);
+	offsets = {int3(-1,2,0), int3(-3,2,0)};
 }
 
 void CGTownInstance::removeCapitols (PlayerColor owner) const

+ 1 - 1
lib/mapObjects/CGTownInstance.h

@@ -205,7 +205,7 @@ public:
 	//int3 getSightCenter() const override; //"center" tile from which the sight distance is calculated
 	int getSightRadious() const override; //returns sight distance
 	int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
-	void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
+	void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed. Parameter will be cleared
 	int getMarketEfficiency() const override; //=market count
 	bool allowsTrade(EMarketMode::EMarketMode mode) const;
 	std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;

+ 0 - 2
lib/mapObjects/CObjectHandler.cpp

@@ -21,8 +21,6 @@
 
 #include "CObjectClassesHandler.h"
 
-using namespace boost::assign;
-
 IGameCallback * IObjectInterface::cb = nullptr;
 
 ///helpers

+ 0 - 2
lib/mapObjects/CQuest.cpp

@@ -20,8 +20,6 @@
 #include "../IGameCallback.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 std::map <PlayerColor, std::set <ui8> > CGKeys::playerKeyMap;
 
 ///helpers

+ 4 - 4
lib/mapObjects/MiscObjects.cpp

@@ -21,8 +21,6 @@
 #include "../IGameCallback.h"
 #include "../CGameState.h"
 
-using namespace boost::assign;
-
 std::map<Obj, std::map<int, std::vector<ObjectInstanceID> > > CGTeleport::objs;
 std::vector<std::pair<ObjectInstanceID, ObjectInstanceID> > CGTeleport::gates;
 std::map <si32, std::vector<ObjectInstanceID> > CGMagi::eyelist;
@@ -1419,9 +1417,11 @@ void CGShipyard::getOutOffsets( std::vector<int3> &offsets ) const
 	// H J L K I
 	// A x S x B
 	// C E G F D
-	offsets += int3(-3,0,0), int3(1,0,0), //AB
+	offsets = {
+		int3(-3,0,0), int3(1,0,0), //AB
 		int3(-3,1,0), int3(1,1,0), int3(-2,1,0), int3(0,1,0), int3(-1,1,0), //CDEFG
-		int3(-3,-1,0), int3(1,-1,0), int3(-2,-1,0), int3(0,-1,0), int3(-1,-1,0); //HIJKL
+		int3(-3,-1,0), int3(1,-1,0), int3(-2,-1,0), int3(0,-1,0), int3(-1,-1,0) //HIJKL
+	}; 
 }
 
 void CGShipyard::onHeroVisit( const CGHeroInstance * h ) const