From b52cfe5283936d0c2ee8eb7c8d70b1742b90cc9c Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Sun, 16 Jul 2017 12:58:05 +0300 Subject: [PATCH] Code style: use parentheses for creating heap-based objects (#344) --- AI/BattleAI/AttackPossibility.cpp | 2 +- client/CDefHandler.cpp | 2 +- client/CMT.cpp | 18 +++++++++--------- client/CPlayerInterface.cpp | 2 +- client/CPreGame.cpp | 6 +++--- client/Client.cpp | 4 ++-- client/battle/CBattleInterface.cpp | 2 +- client/windows/CAdvmapInterface.cpp | 4 ++-- client/windows/CCastleInterface.cpp | 6 +++--- client/windows/CHeroWindow.cpp | 4 ++-- client/windows/CKingdomInterface.cpp | 10 +++++----- client/windows/CWindowObject.cpp | 2 +- launcher/mainwindow_moc.cpp | 2 +- lib/CGameState.cpp | 14 +++++++------- lib/CGeneralTextHandler.cpp | 4 ++-- lib/CHeroHandler.cpp | 2 +- lib/CTownHandler.cpp | 6 +++--- lib/VCMI_Lib.cpp | 6 +++--- lib/filesystem/CCompressedStream.cpp | 2 +- lib/filesystem/Filesystem.cpp | 2 +- lib/mapObjects/CObjectClassesHandler.cpp | 2 +- lib/serializer/Connection.cpp | 4 ++-- scripting/erm/ERMInterpreter.cpp | 2 +- server/CGameHandler.cpp | 6 +++--- server/CVCMIServer.cpp | 2 +- test/CVcmiTestConfig.cpp | 2 +- 26 files changed, 59 insertions(+), 59 deletions(-) diff --git a/AI/BattleAI/AttackPossibility.cpp b/AI/BattleAI/AttackPossibility.cpp index f6a8faba2..bde5b2071 100644 --- a/AI/BattleAI/AttackPossibility.cpp +++ b/AI/BattleAI/AttackPossibility.cpp @@ -13,7 +13,7 @@ int AttackPossibility::damageDiff() const { if (!priorities) - priorities = new Priorities; + priorities = new Priorities(); const auto dealtDmgValue = priorities->stackEvaluator(enemy) * damageDealt; const auto receivedDmgValue = priorities->stackEvaluator(attack.attacker) * damageReceived; return dealtDmgValue - receivedDmgValue; diff --git a/client/CDefHandler.cpp b/client/CDefHandler.cpp index 66bccbf6c..ee83ba753 100644 --- a/client/CDefHandler.cpp +++ b/client/CDefHandler.cpp @@ -352,7 +352,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co CDefEssential * CDefHandler::essentialize() { - auto ret = new CDefEssential; + auto ret = new CDefEssential(); ret->ourImages = ourImages; notFreeImgs = true; return ret; diff --git a/client/CMT.cpp b/client/CMT.cpp index ec1dbcd65..f60e597a6 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -175,7 +175,7 @@ void init() if(!settings["session"]["headless"].Bool()) { pomtime.getDiff(); - CCS->curh = new CCursorHandler; + CCS->curh = new CCursorHandler(); graphics = new Graphics(); // should be before curh->init() CCS->curh->initCursor(); @@ -313,7 +313,7 @@ int main(int argc, char** argv) // Init old logging system and new (temporary) logging system CStopWatch total, pomtime; std::cout.flags(std::ios::unitbuf); - console = new CConsoleHandler; + console = new CConsoleHandler(); *console->cb = processCommand; console->start(); @@ -456,25 +456,25 @@ int main(int argc, char** argv) logGlobal->infoStream() <<"\tInitializing screen: "<videoh = new CEmptyVideoPlayer; + CCS->videoh = new CEmptyVideoPlayer(); #else if (!settings["session"]["headless"].Bool() && !vm.count("disable-video")) - CCS->videoh = new CVideoPlayer; + CCS->videoh = new CVideoPlayer(); else - CCS->videoh = new CEmptyVideoPlayer; + CCS->videoh = new CEmptyVideoPlayer(); #endif logGlobal->infoStream()<<"\tInitializing video: "<soundh = new CSoundHandler; + CCS->soundh = new CSoundHandler(); CCS->soundh->init(); CCS->soundh->setVolume(settings["general"]["sound"].Float()); - CCS->musich = new CMusicHandler; + CCS->musich = new CMusicHandler(); CCS->musich->init(); CCS->musich->setVolume(settings["general"]["music"].Float()); logGlobal->infoStream()<<"Initializing screen and sound handling: "<(false); - cingconsole = new CInGameConsole; + cingconsole = new CInGameConsole(); GH.terminate_cond.set(false); firstCall = 1; //if loading will be overwritten in serialize autosaveCount = 0; diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 6e80fd108..7ae38c20a 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -190,7 +190,7 @@ public: virtual ~CBaseForPGApply(){}; template static CBaseForPGApply *getApplier(const U * t=nullptr) { - return new CApplyOnPG; + return new CApplyOnPG(); } }; @@ -573,7 +573,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EGameM CServerHandler *sh = nullptr; if(isHost()) { - sh = new CServerHandler; + sh = new CServerHandler(); sh->startServer(); } @@ -722,7 +722,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EGameM *serv << &uso; } - applier = new CApplier; + applier = new CApplier(); registerTypesPregamePacks(*applier); serverHandlingThread = new boost::thread(&CSelectionScreen::handleConnection, this); } diff --git a/client/Client.cpp b/client/Client.cpp index a12c0b094..fef44695b 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -71,7 +71,7 @@ public: template static CBaseForCLApply *getApplier(const U * t=nullptr) { - return new CApplyOnCL; + return new CApplyOnCL(); } }; @@ -117,7 +117,7 @@ void CClient::init() connectionHandler.reset(); } pathInfo = nullptr; - applier = new CApplier; + applier = new CApplier(); registerTypesClientPacks1(*applier); registerTypesClientPacks2(*applier); IObjectInterface::cb = this; diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index d40172abf..968b261df 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -1383,7 +1383,7 @@ CBattleInterface::PossibleActions CBattleInterface::getCasterAction(const CSpell void CBattleInterface::castThisSpell(SpellID spellID) { - auto ba = new BattleAction; + auto ba = new BattleAction(); ba->actionType = Battle::HERO_SPELL; ba->additionalInfo = spellID; //spell number ba->destinationTile = -1; diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index aa81caf97..59f354b1f 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -715,7 +715,7 @@ CAdvMapInt::~CAdvMapInt() void CAdvMapInt::fshowOverview() { - GH.pushInt(new CKingdomInterface); + GH.pushInt(new CKingdomInterface()); } void CAdvMapInt::fworldViewBack() @@ -808,7 +808,7 @@ void CAdvMapInt::fshowSpellbok() void CAdvMapInt::fadventureOPtions() { - GH.pushInt(new CAdventureOptions); + GH.pushInt(new CAdventureOptions()); } void CAdvMapInt::fsystemOptions() diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 863492ea2..da12d406d 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1323,7 +1323,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): { OBJ_CONSTRUCTION_CAPTURING_ALL; - resdatabar = new CMinorResDataBar; + resdatabar = new CMinorResDataBar(); resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; Rect barRect(5, 556, 740, 18); @@ -1498,7 +1498,7 @@ CFortScreen::CFortScreen(const CGTownInstance * town): recAreas.push_back(new RecruitArea(positions[i].x, positions[i].y, town, i)); } - resdatabar = new CMinorResDataBar; + resdatabar = new CMinorResDataBar(); resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; @@ -1671,7 +1671,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner,std::string imagem) window = new CPicture(owner->town->town->clientInfo.guildWindow , 332, 76); - resdatabar = new CMinorResDataBar; + resdatabar = new CMinorResDataBar(); resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; Rect barRect(7, 556, 737, 18); diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index 3750e6150..23cb2ba77 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -40,7 +40,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root, const std::string & cachingStr) const { - TBonusListPtr out(new BonusList); + TBonusListPtr out(new BonusList()); TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero); TBonusListPtr bonusesFromPickedUpArtifact; @@ -50,7 +50,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero); } else - bonusesFromPickedUpArtifact = TBonusListPtr(new BonusList); + bonusesFromPickedUpArtifact = TBonusListPtr(new BonusList()); for(auto b : *bonusesFromPickedUpArtifact) *heroBonuses -= b; diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index f4a7c98e0..92558e686 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/client/windows/CKingdomInterface.cpp @@ -73,7 +73,7 @@ InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data) if (value) pos = pos | value->pos; - hover = new CHoverableArea; + hover = new CHoverableArea(); hover->hoverText = data->getHoverText(); hover->pos = pos; } @@ -599,7 +599,7 @@ void CKingdomInterface::generateMinesList(const std::vectorremoveUsedEvents(LCLICK|RCLICK); //fixes #890 - mines boxes ignore clicks } - incomeArea = new CHoverableArea; + incomeArea = new CHoverableArea(); incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68); incomeArea->hoverText = CGI->generaltexth->allTexts[255]; incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, Colors::WHITE, boost::lexical_cast(totalIncome)); @@ -866,9 +866,9 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero): OBJ_CONSTRUCTION_CAPTURING_ALL; artTabs.resize(3); - auto arts1 = new ArtSlotsTab; - auto arts2 = new ArtSlotsTab; - auto backpack = new BackpackTab; + auto arts1 = new ArtSlotsTab(); + auto arts2 = new ArtSlotsTab(); + auto backpack = new BackpackTab(); artTabs[0] = arts1; artTabs[1] = arts2; artTabs[2] = backpack; diff --git a/client/windows/CWindowObject.cpp b/client/windows/CWindowObject.cpp index 95e59f391..a8c2d8cdb 100644 --- a/client/windows/CWindowObject.cpp +++ b/client/windows/CWindowObject.cpp @@ -215,7 +215,7 @@ void CWindowObject::setShadow(bool on) blitAlphaRow(shadowRight, 0); //generate "shadow" object with these 3 pieces in it - shadow = new CIntObject; + shadow = new CIntObject(); shadow->addChild(new CPicture(shadowCorner, shadowPos.x, shadowPos.y)); shadow->addChild(new CPicture(shadowRight, shadowPos.x, shadowStart.y)); shadow->addChild(new CPicture(shadowBottom, shadowStart.x, shadowPos.y)); diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index e5794ac0f..0d954f722 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -21,7 +21,7 @@ void MainWindow::load() { - console = new CConsoleHandler; + console = new CConsoleHandler(); CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Launcher_log.txt", console); logConfig.configureDefault(); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 831dbc315..dfa42b72a 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -55,7 +55,7 @@ public: virtual ~CBaseForGSApply(){}; template static CBaseForGSApply *getApplier(const U * t=nullptr) { - return new CApplyOnGS; + return new CApplyOnGS(); } }; @@ -295,10 +295,10 @@ static CGObjectInstance * createObject(Obj id, int subid, int3 pos, PlayerColor break; } case Obj::TOWN: - nobj = new CGTownInstance; + nobj = new CGTownInstance(); break; default: //rest of objects - nobj = new CGObjectInstance; + nobj = new CGObjectInstance(); break; } nobj->ID = id; @@ -679,10 +679,10 @@ int CGameState::getDate(Date::EDateType mode) const CGameState::CGameState() { gs = this; - applierGs = new CApplier; + applierGs = new CApplier(); registerTypesClientPacks1(*applierGs); registerTypesClientPacks2(*applierGs); - //objCaller = new CObjectCallersHandler; + //objCaller = new CObjectCallersHandler(); globalEffects.setDescription("Global effects"); globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS); day = 0; @@ -2968,7 +2968,7 @@ void InfoAboutHero::initFromHero(const CGHeroInstance *h, InfoAboutHero::EInfoLe if(detailed) { //include details about hero - details = new Details; + details = new Details(); details->luck = h->LuckVal(); details->morale = h->MoraleVal(); details->mana = h->mana; @@ -3022,7 +3022,7 @@ void InfoAboutTown::initFromTown(const CGTownInstance *t, bool detailed) if(detailed) { //include details about hero - details = new Details; + details = new Details(); TResources income = t->dailyIncome(); details->goldIncome = income[Res::GOLD]; details->customRes = t->hasBuilt(BuildingID::RESOURCE_SILO); diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index bfa804ad2..f9148edf2 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -269,8 +269,8 @@ float CLegacyConfigParser::readNumber() std::istringstream stream(input); - if (input.find(',') != std::string::npos) // code to handle conversion with comma as decimal separator - stream.imbue(std::locale(std::locale(), new LocaleWithComma)); + if(input.find(',') != std::string::npos) // code to handle conversion with comma as decimal separator + stream.imbue(std::locale(std::locale(), new LocaleWithComma())); float result; if ( !(stream >> result) ) diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 2592b0307..17c0c6f22 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -294,7 +294,7 @@ CHeroHandler::CHeroHandler() CHero * CHeroHandler::loadFromJson(const JsonNode & node, const std::string & identifier) { - auto hero = new CHero; + auto hero = new CHero(); hero->identifier = identifier; hero->sex = node["female"].Bool(); hero->special = node["special"].Bool(); diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 1667afa7f..9618406eb 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -327,7 +327,7 @@ void CTownHandler::loadBuildingRequirements(CBuilding * building, const JsonNode void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source) { - auto ret = new CBuilding; + auto ret = new CBuilding(); static const std::string modes [] = {"normal", "auto", "special", "grail"}; @@ -406,7 +406,7 @@ void CTownHandler::loadBuildings(CTown * town, const JsonNode & source) void CTownHandler::loadStructure(CTown &town, const std::string & stringID, const JsonNode & source) { - auto ret = new CStructure; + auto ret = new CStructure(); ret->building = nullptr; ret->buildable = nullptr; @@ -706,7 +706,7 @@ CFaction * CTownHandler::loadFromJson(const JsonNode &source, const std::string if (!source["town"].isNull()) { - faction->town = new CTown; + faction->town = new CTown(); faction->town->faction = faction; loadTown(*faction->town, source["town"]); } diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index e527265fe..f5ef270b7 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -35,7 +35,7 @@ LibClasses * VLC = nullptr; DLL_LINKAGE void preinitDLL(CConsoleHandler *Console) { console = Console; - VLC = new LibClasses; + VLC = new LibClasses(); try { VLC->loadFilesystem(); @@ -169,8 +169,8 @@ LibClasses::LibClasses() void LibClasses::callWhenDeserializing() { - // FIXME: check if any of these are needed - //generaltexth = new CGeneralTextHandler; + //FIXME: check if any of these are needed + //generaltexth = new CGeneralTextHandler(); //generaltexth->load(); //arth->load(true); //modh->recreateHandlers(); diff --git a/lib/filesystem/CCompressedStream.cpp b/lib/filesystem/CCompressedStream.cpp index 361df3f77..e44d083d4 100644 --- a/lib/filesystem/CCompressedStream.cpp +++ b/lib/filesystem/CCompressedStream.cpp @@ -93,7 +93,7 @@ CCompressedStream::CCompressedStream(std::unique_ptr stream, bool assert(gzipStream); // Allocate inflate state - inflateState = new z_stream; + inflateState = new z_stream(); inflateState->zalloc = Z_NULL; inflateState->zfree = Z_NULL; inflateState->opaque = Z_NULL; diff --git a/lib/filesystem/Filesystem.cpp b/lib/filesystem/Filesystem.cpp index 190f5d845..a8efbff62 100644 --- a/lib/filesystem/Filesystem.cpp +++ b/lib/filesystem/Filesystem.cpp @@ -126,7 +126,7 @@ ISimpleResourceLoader * CResourceHandler::createInitial() { //temporary filesystem that will be used to initialize main one. //used to solve several case-sensivity issues like Mp3 vs MP3 - auto initialLoader = new CFilesystemList; + auto initialLoader = new CFilesystemList(); //recurse only into specific directories auto recurseInDir = [&](std::string URI, int depth) diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index e9a22fe14..665f26564 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -26,7 +26,7 @@ CObjectClassesHandler::CObjectClassesHandler() { #define SET_HANDLER_CLASS(STRING, CLASSNAME) handlerConstructors[STRING] = std::make_shared; -#define SET_HANDLER(STRING, TYPENAME) handlerConstructors[STRING] = std::make_shared > +#define SET_HANDLER(STRING, TYPENAME) handlerConstructors[STRING] = std::make_shared> // list of all known handlers, hardcoded for now since the only way to add new objects is via C++ code //Note: should be in sync with registerTypesMapObjectTypes function diff --git a/lib/serializer/Connection.cpp b/lib/serializer/Connection.cpp index 0af175e74..7e536be92 100644 --- a/lib/serializer/Connection.cpp +++ b/lib/serializer/Connection.cpp @@ -50,8 +50,8 @@ void CConnection::init() oser & std::string("Aiya!\n") & name & myEndianess; //identify ourselves iser & pom & pom & contactEndianess; logNetwork->infoStream() << "Established connection with "<path().string()); - FileInfo * finfo = new FileInfo; + FileInfo * finfo = new FileInfo(); finfo->filename = dir->path().string(); std::vector buf = ep.parseFile(); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index dd4e085fd..d578565c5 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -86,7 +86,7 @@ public: virtual ~CBaseForGHApply(){} template static CBaseForGHApply *getApplier(const U * t=nullptr) { - return new CApplyOnGH; + return new CApplyOnGH(); } }; @@ -1397,7 +1397,7 @@ CGameHandler::CGameHandler(void) QID = 1; //gs = nullptr; IObjectInterface::cb = this; - applier = new CApplier; + applier = new CApplier(); registerTypesServerPacks(*applier); visitObjectAfterVictory = false; @@ -6057,7 +6057,7 @@ void CGameHandler::setBattleResult(BattleResult::EResult resultType, int victori % battleResult.data->result % resultType).str()); return; } - auto br = new BattleResult; + auto br = new BattleResult(); br->result = resultType; br->winner = victoriusSide; //surrendering side loses gs->curB->calculateCasualties(br->casualties); diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index b23fce373..08e12bb02 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -615,7 +615,7 @@ int main(int argc, char** argv) signal(SIGSEGV, handleLinuxSignal); #endif - console = new CConsoleHandler; + console = new CConsoleHandler(); CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Server_log.txt", console); logConfig.configureDefault(); logGlobal->info(NAME); diff --git a/test/CVcmiTestConfig.cpp b/test/CVcmiTestConfig.cpp index 4f30cd550..a9caff9ec 100644 --- a/test/CVcmiTestConfig.cpp +++ b/test/CVcmiTestConfig.cpp @@ -23,7 +23,7 @@ CVcmiTestConfig::CVcmiTestConfig() { - console = new CConsoleHandler; + console = new CConsoleHandler(); CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Test_log.txt", console); logConfig.configureDefault(); preinitDLL(console);