Skip to content

Commit

Permalink
- migrated boost::function/ref/bind to std:: variants
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee1 committed Aug 4, 2014
1 parent d535a09 commit 5139378
Show file tree
Hide file tree
Showing 38 changed files with 319 additions and 319 deletions.
2 changes: 1 addition & 1 deletion AI/BattleAI/BattleAI.cpp
Expand Up @@ -165,7 +165,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
{
ThreatMap threatsToUs(stack);
auto dists = cbc->battleGetDistances(stack);
const EnemyInfo &ei= *range::min_element(targets.unreachableEnemies, boost::bind(isCloser, _1, _2, boost::ref(dists)));
const EnemyInfo &ei= *range::min_element(targets.unreachableEnemies, std::bind(isCloser, _1, _2, std::ref(dists)));
if(distToNearestNeighbour(ei.s->position, dists) < GameConstants::BFIELD_SIZE)
{
return goTowards(stack, ei.s->position);
Expand Down
2 changes: 1 addition & 1 deletion AI/StupidAI/StupidAI.cpp
Expand Up @@ -166,7 +166,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
else if(enemiesUnreachable.size()) //due to #955 - a buggy battle may occur when there are no enemies
{
assert(enemiesUnreachable.size());
const EnemyInfo &ei= *std::min_element(enemiesUnreachable.begin(), enemiesUnreachable.end(), boost::bind(isCloser, _1, _2, boost::ref(dists)));
const EnemyInfo &ei= *std::min_element(enemiesUnreachable.begin(), enemiesUnreachable.end(), std::bind(isCloser, _1, _2, std::ref(dists)));
assert(ei.s);
if(distToNearestNeighbour(ei.s->position, dists) < GameConstants::BFIELD_SIZE)
{
Expand Down
4 changes: 2 additions & 2 deletions Global.h
Expand Up @@ -89,7 +89,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#define BOOST_THREAD_VERSION 3
#endif
#define BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE 1
//#define BOOST_BIND_NO_PLACEHOLDERS
#define BOOST_BIND_NO_PLACEHOLDERS

#include <boost/algorithm/string.hpp>
#include <boost/assign.hpp>
Expand Down Expand Up @@ -127,7 +127,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
using std::shared_ptr;
using std::unique_ptr;
using std::make_shared;
//using namespace std::placeholders;
using namespace std::placeholders;
namespace range = boost::range;

/* ---------------------------------------------------------------------------- */
Expand Down
12 changes: 6 additions & 6 deletions client/AdventureMapClasses.cpp
Expand Up @@ -97,11 +97,11 @@ CList::CList(int Size, Point position, std::string btnUp, std::string btnDown, s
list = new CListBox(create, destroy, Point(1,scrollUp->pos.h), Point(0, 32), size, listAmount);

//assign callback only after list was created
scrollUp->callback = boost::bind(&CListBox::moveToPrev, list);
scrollDown = new CAdventureMapButton(CGI->generaltexth->zelp[helpDown], boost::bind(&CListBox::moveToNext, list), 0, scrollUp->pos.h + 32*size, btnDown);
scrollUp->callback = std::bind(&CListBox::moveToPrev, list);
scrollDown = new CAdventureMapButton(CGI->generaltexth->zelp[helpDown], std::bind(&CListBox::moveToNext, list), 0, scrollUp->pos.h + 32*size, btnDown);

scrollDown->callback += boost::bind(&CList::update, this);
scrollUp->callback += boost::bind(&CList::update, this);
scrollDown->callback += std::bind(&CList::update, this);
scrollUp->callback += std::bind(&CList::update, this);

update();
}
Expand Down Expand Up @@ -236,7 +236,7 @@ CIntObject * CHeroList::createHeroItem(size_t index)
}

CHeroList::CHeroList(int size, Point position, std::string btnUp, std::string btnDown):
CList(size, position, btnUp, btnDown, LOCPLINT->wanderingHeroes.size(), 303, 304, boost::bind(&CHeroList::createHeroItem, this, _1))
CList(size, position, btnUp, btnDown, LOCPLINT->wanderingHeroes.size(), 303, 304, std::bind(&CHeroList::createHeroItem, this, _1))
{
}

Expand Down Expand Up @@ -321,7 +321,7 @@ std::string CTownList::CTownItem::getHoverText()
}

CTownList::CTownList(int size, Point position, std::string btnUp, std::string btnDown):
CList(size, position, btnUp, btnDown, LOCPLINT->towns.size(), 306, 307, boost::bind(&CTownList::createTownItem, this, _1))
CList(size, position, btnUp, btnDown, LOCPLINT->towns.size(), 306, 307, std::bind(&CTownList::createTownItem, this, _1))
{
}

Expand Down
38 changes: 19 additions & 19 deletions client/CAdvmapInterface.cpp
Expand Up @@ -364,34 +364,34 @@ CAdvMapInt::CAdvMapInt():
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
std::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),

underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
std::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),

questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
std::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),

sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
std::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),

moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
std::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),

spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
std::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),

advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
std::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),

sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
std::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),

nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
std::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),

endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
std::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),

heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD),
townList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD),
Expand All @@ -405,7 +405,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
pos.h = screen->h;
position = int3(0,0,0);
selection = nullptr;
townList.onSelect = boost::bind(&CAdvMapInt::selectionChanged,this);
townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this);
adventureInt=this;
bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
scrollingDir = 0;
Expand Down Expand Up @@ -528,7 +528,7 @@ void CAdvMapInt::fendTurn()
for (int i = 0; i < LOCPLINT->wanderingHeroes.size(); i++)
if (!isHeroSleeping(LOCPLINT->wanderingHeroes[i]) && (LOCPLINT->wanderingHeroes[i]->movement > 0))
{
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[55], boost::bind(&CAdvMapInt::endingTurn, this), 0, false);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[55], std::bind(&CAdvMapInt::endingTurn, this), 0, false);
return;
}
}
Expand Down Expand Up @@ -1529,19 +1529,19 @@ CAdventureOptions::CAdventureOptions():
{
OBJ_CONSTRUCTION_CAPTURING_ALL;

exit = new CAdventureMapButton("","",boost::bind(&CAdventureOptions::close, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
exit = new CAdventureMapButton("","",std::bind(&CAdventureOptions::close, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);

scenInfo = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 198, "ADVINFO.DEF",SDLK_i);
scenInfo = new CAdventureMapButton("","", std::bind(&CAdventureOptions::close, this), 24, 198, "ADVINFO.DEF",SDLK_i);
scenInfo->callback += CAdventureOptions::showScenarioInfo;
//viewWorld = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
//viewWorld = new CAdventureMapButton("","",std::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);

puzzle = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 81, "ADVPUZ.DEF");
puzzle->callback += boost::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT);
puzzle = new CAdventureMapButton("","", std::bind(&CAdventureOptions::close, this), 24, 81, "ADVPUZ.DEF");
puzzle->callback += std::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT);

dig = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 139, "ADVDIG.DEF");
dig = new CAdventureMapButton("","", std::bind(&CAdventureOptions::close, this), 24, 139, "ADVDIG.DEF");
if(const CGHeroInstance *h = adventureInt->curHero())
dig->callback += boost::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h);
dig->callback += std::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h);
else
dig->block(true);
}
Expand Down
2 changes: 1 addition & 1 deletion client/CAnimation.cpp
Expand Up @@ -1528,7 +1528,7 @@ void CCreatureAnim::reset()

void CCreatureAnim::startPreview(bool warMachine)
{
callback = boost::bind(&CCreatureAnim::loopPreview, this, warMachine);
callback = std::bind(&CCreatureAnim::loopPreview, this, warMachine);
}

void CCreatureAnim::clearAndSet(EAnimType type)
Expand Down
26 changes: 13 additions & 13 deletions client/CCastleInterface.cpp
Expand Up @@ -764,7 +764,7 @@ void CCastleBuildings::enterCastleGate()
}
auto titlePic = new CPicture (LOCPLINT->castleInt->bicons->ourImages[BuildingID::CASTLE_GATE].bitmap, 0,0, false);//will be deleted by selection window
GH.pushInt (new CObjectListWindow(availableTowns, titlePic, CGI->generaltexth->jktexts[40],
CGI->generaltexth->jktexts[41], boost::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)));
CGI->generaltexth->jktexts[41], std::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)));
}

void CCastleBuildings::enterDwelling(int level)
Expand Down Expand Up @@ -836,7 +836,7 @@ void CCastleBuildings::enterTownHall()
else
{
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[673]);
(dynamic_cast<CInfoWindow*>(GH.topInt()))->buttons[0]->callback += boost::bind(&CCastleBuildings::openTownHall, this);
(dynamic_cast<CInfoWindow*>(GH.topInt()))->buttons[0]->callback += std::bind(&CCastleBuildings::openTownHall, this);
}
}
else
Expand Down Expand Up @@ -881,12 +881,12 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
income = new CLabel(195, 443, FONT_SMALL, CENTER);
icon = new CAnimImage("ITPT", 0, 0, 15, 387);

exit = new CAdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CCastleInterface::close,this), 744, 544, "TSBTNS", SDLK_RETURN);
exit = new CAdventureMapButton(CGI->generaltexth->tcommands[8], "", std::bind(&CCastleInterface::close,this), 744, 544, "TSBTNS", SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
exit->setOffset(4);

split = new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick,garr), 744, 382, "TSBTNS.DEF");
split->callback += boost::bind(&HeroSlots::splitClicked, heroes);
split = new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", std::bind(&CGarrisonInt::splitClick,garr), 744, 382, "TSBTNS.DEF");
split->callback += std::bind(&HeroSlots::splitClicked, heroes);
garr->addSplitBtn(split);

Rect barRect(9, 182, 732, 18);
Expand All @@ -898,7 +898,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
townlist->select(from);

townlist->select(town); //this will scroll list to select current town
townlist->onSelect = boost::bind(&CCastleInterface::townChange, this);
townlist->onSelect = std::bind(&CCastleInterface::townChange, this);

recreateIcons();
CCS->musich->playMusic(town->town->clientInfo.musicTheme, true);
Expand Down Expand Up @@ -1305,7 +1305,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):

title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings.at(BuildingID(town->hallLevel()+BuildingID::VILLAGE_HALL))->Name());
exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "",
boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN);
std::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);

auto & boxList = town->town->clientInfo.hallSlots;
Expand Down Expand Up @@ -1408,12 +1408,12 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
if(!rightClick)
{ //normal window
buy = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[595]) % building->Name()),
"", boost::bind(&CBuildWindow::buyFunc,this), 45, 446,"IBUY30", SDLK_RETURN);
"", std::bind(&CBuildWindow::buyFunc,this), 45, 446,"IBUY30", SDLK_RETURN);
buy->borderColor = Colors::METALLIC_GOLD;
buy->borderEnabled = true;

cancel = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name()),
"", boost::bind(&CBuildWindow::close,this), 290, 445, "ICANCEL", SDLK_ESCAPE);
"", std::bind(&CBuildWindow::close,this), 290, 445, "ICANCEL", SDLK_ESCAPE);
cancel->borderColor = Colors::METALLIC_GOLD;
cancel->borderEnabled = true;
buy->block(state!=7 || LOCPLINT->playerID != town->tempOwner);
Expand Down Expand Up @@ -1445,7 +1445,7 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::WHITE, fortBuilding->Name());

std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name());
exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN);
exit = new CAdventureMapButton(text, "", std::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);

std::vector<Point> positions;
Expand Down Expand Up @@ -1655,7 +1655,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner,std::string imagem)
Rect barRect(7, 556, 737, 18);
statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false));

exit = new CAdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN);
exit = new CAdventureMapButton(CGI->generaltexth->allTexts[593],"",std::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);

std::vector<std::vector<Point> > positions;
Expand Down Expand Up @@ -1732,10 +1732,10 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, Art
boost::lexical_cast<std::string>(CGI->arth->artifacts[aid]->price));

std::string text = boost::str(boost::format(CGI->generaltexth->allTexts[595]) % creature->nameSing);
buy = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 42, 312,"IBUY30.DEF",SDLK_RETURN);
buy = new CAdventureMapButton(text,"",std::bind(&CBlacksmithDialog::close, this), 42, 312,"IBUY30.DEF",SDLK_RETURN);

text = boost::str(boost::format(CGI->generaltexth->allTexts[596]) % creature->nameSing);
cancel = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE);
cancel = new CAdventureMapButton(text,"",std::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE);

if(possible)
buy->callback += [=]{ LOCPLINT->cb->buyArtifact(LOCPLINT->cb->getHero(hid),aid); };
Expand Down

3 comments on commit 5139378

@alexvins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tabs for indentation.

@IvanSavenko
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viciious can you test MSVC compilation and create pull request with fixes? Preferably using refactoring/guiClasses branch as base (it may have more compile issues)

( this cases should probably be replaced with lambdas)

@viciious
Copy link
Contributor

@viciious viciious commented on 5139378 Aug 20, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.