diff --git a/AI/BattleAI/BattleExchangeVariant.h b/AI/BattleAI/BattleExchangeVariant.h index 6c8e0b448..2cfba35d0 100644 --- a/AI/BattleAI/BattleExchangeVariant.h +++ b/AI/BattleAI/BattleExchangeVariant.h @@ -56,10 +56,7 @@ struct EvaluationResult class BattleExchangeVariant { public: - BattleExchangeVariant() - :dpsScore(0), attackerValue() - { - } + BattleExchangeVariant(): dpsScore(0) {} int64_t trackAttack(const AttackPossibility & ap, HypotheticBattle & state); @@ -92,10 +89,7 @@ private: std::vector turnOrder; public: - BattleExchangeEvaluator(std::shared_ptr cb, std::shared_ptr env) - :cb(cb), reachabilityMap(), env(env), turnOrder() - { - } + BattleExchangeEvaluator(std::shared_ptr cb, std::shared_ptr env): cb(cb), env(env) {} EvaluationResult findBestTarget(const battle::Unit * activeStack, PotentialTargets & targets, HypotheticBattle & hb); int64_t calculateExchange(const AttackPossibility & ap, PotentialTargets & targets, HypotheticBattle & hb); diff --git a/AI/Nullkiller/AIUtility.h b/AI/Nullkiller/AIUtility.h index d06da7958..06dd99dc2 100644 --- a/AI/Nullkiller/AIUtility.h +++ b/AI/Nullkiller/AIUtility.h @@ -54,7 +54,7 @@ using namespace tbb; -typedef std::pair> dwellingContent; +using dwellingContent = std::pair>; namespace NKAI { @@ -305,10 +305,10 @@ public: public: using ptr_type = std::unique_ptr; - SharedPool(std::function()> elementFactory) - : elementFactory(elementFactory), pool(), sync(), instance_tracker(new SharedPool*(this)) + SharedPool(std::function()> elementFactory): + elementFactory(elementFactory), pool(), instance_tracker(new SharedPool *(this)) {} - + void add(std::unique_ptr t) { boost::lock_guard lock(sync); diff --git a/AI/Nullkiller/Analyzers/ArmyManager.h b/AI/Nullkiller/Analyzers/ArmyManager.h index 5b71bda48..b6f27adf9 100644 --- a/AI/Nullkiller/Analyzers/ArmyManager.h +++ b/AI/Nullkiller/Analyzers/ArmyManager.h @@ -32,13 +32,8 @@ struct SlotInfo struct ArmyUpgradeInfo { std::vector resultingArmy; - uint64_t upgradeValue; + uint64_t upgradeValue = 0; TResources upgradeCost; - - ArmyUpgradeInfo() - : resultingArmy(), upgradeValue(0), upgradeCost() - { - } }; class DLL_EXPORT IArmyManager //: public: IAbstractManager diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.h b/AI/Nullkiller/Analyzers/BuildAnalyzer.h index 820442a72..43049b295 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.h +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.h @@ -62,8 +62,11 @@ public: HeroRole townRole; bool hasSomethingToBuild; - TownDevelopmentInfo(const CGTownInstance* town) - :town(town), armyStrength(0), toBuild(), townDevelopmentCost(), requiredResources(), townRole(HeroRole::SCOUT), hasSomethingToBuild(false) + TownDevelopmentInfo(const CGTownInstance * town): + town(town), + armyStrength(0), + townRole(HeroRole::SCOUT), + hasSomethingToBuild(false) { } diff --git a/AI/Nullkiller/Analyzers/ObjectClusterizer.h b/AI/Nullkiller/Analyzers/ObjectClusterizer.h index c8137bba9..bc4118917 100644 --- a/AI/Nullkiller/Analyzers/ObjectClusterizer.h +++ b/AI/Nullkiller/Analyzers/ObjectClusterizer.h @@ -22,7 +22,7 @@ struct ClusterObjectInfo uint8_t turn; }; -typedef tbb::concurrent_hash_map ClusterObjects; +using ClusterObjects = tbb::concurrent_hash_map; struct ObjectCluster { @@ -36,11 +36,8 @@ public: } void addObject(const CGObjectInstance * object, const AIPath & path, float priority); - - ObjectCluster(const CGObjectInstance * blocker) - :objects(), blocker(blocker) - { - } + + ObjectCluster(const CGObjectInstance * blocker): blocker(blocker) {} ObjectCluster() : ObjectCluster(nullptr) { @@ -50,7 +47,7 @@ public: const CGObjectInstance * calculateCenter() const; }; -typedef tbb::concurrent_hash_map> ClusterMap; +using ClusterMap = tbb::concurrent_hash_map>; class ObjectClusterizer { @@ -67,10 +64,7 @@ public: std::vector> getLockedClusters() const; const CGObjectInstance * getBlocker(const AIPath & path) const; - ObjectClusterizer(const Nullkiller * ai) - :nearObjects(), farObjects(), blockedObjects(), ai(ai) - { - } + ObjectClusterizer(const Nullkiller * ai): ai(ai) {} private: bool shouldVisitObject(const CGObjectInstance * obj) const; diff --git a/AI/Nullkiller/Engine/DeepDecomposer.h b/AI/Nullkiller/Engine/DeepDecomposer.h index 7d11764e8..2f971f4cf 100644 --- a/AI/Nullkiller/Engine/DeepDecomposer.h +++ b/AI/Nullkiller/Engine/DeepDecomposer.h @@ -22,7 +22,7 @@ struct GoalHash } }; -typedef std::unordered_map TGoalHashSet; +using TGoalHashSet = std::unordered_map; class DeepDecomposer { diff --git a/AI/Nullkiller/Engine/FuzzyHelper.h b/AI/Nullkiller/Engine/FuzzyHelper.h index a3a2f2955..b203916ad 100644 --- a/AI/Nullkiller/Engine/FuzzyHelper.h +++ b/AI/Nullkiller/Engine/FuzzyHelper.h @@ -28,7 +28,7 @@ private: TacticalAdvantageEngine tacticalAdvantageEngine; public: - FuzzyHelper(const Nullkiller * ai) : ai(ai), tacticalAdvantageEngine() {} + FuzzyHelper(const Nullkiller * ai): ai(ai) {} ui64 estimateBankDanger(const CBank * bank); //TODO: move to another class? diff --git a/AI/Nullkiller/Goals/AbstractGoal.h b/AI/Nullkiller/Goals/AbstractGoal.h index 7c4788e72..a5b170c9f 100644 --- a/AI/Nullkiller/Goals/AbstractGoal.h +++ b/AI/Nullkiller/Goals/AbstractGoal.h @@ -81,9 +81,9 @@ namespace Goals bool operator<(const TSubgoal & rhs) const; }; - typedef std::shared_ptr TTask; - typedef std::vector TTaskVec; - typedef std::vector TGoalVec; + using TTask = std::shared_ptr; + using TTaskVec = std::vector; + using TGoalVec = std::vector; //method chaining + clone pattern #define SETTER(type, field) AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;}; @@ -107,8 +107,7 @@ namespace Goals const CGTownInstance *town; SETTER(CGTownInstance *, town) int bid; SETTER(int, bid) - AbstractGoal(EGoals goal = EGoals::INVALID) - : goalType(goal), hero() + AbstractGoal(EGoals goal = EGoals::INVALID): goalType(goal) { isAbstract = false; value = 0; diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.h b/AI/Nullkiller/Pathfinding/AINodeStorage.h index 2f77422d8..10989da5d 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.h +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.h @@ -205,14 +205,14 @@ public: inline void updateAINode(CGPathNode * node, std::function updater) { - auto aiNode = static_cast(node); + auto * aiNode = static_cast(node); updater(aiNode); } inline const CGHeroInstance * getHero(const CGPathNode * node) const { - auto aiNode = getAINode(node); + const auto * aiNode = getAINode(node); return aiNode->actor->hero; } diff --git a/AI/Nullkiller/Pathfinding/Actors.h b/AI/Nullkiller/Pathfinding/Actors.h index cf450dfbc..a4009caa8 100644 --- a/AI/Nullkiller/Pathfinding/Actors.h +++ b/AI/Nullkiller/Pathfinding/Actors.h @@ -32,9 +32,7 @@ public: virtual bool needsLastStack() const override; std::shared_ptr getActorAction() const; - HeroExchangeArmy() : CArmedInstance(true), armyCost(), requireBuyArmy(false) - { - } + HeroExchangeArmy(): CArmedInstance(true), requireBuyArmy(false) {} }; struct ExchangeResult diff --git a/AI/VCAI/AIUtility.h b/AI/VCAI/AIUtility.h index 475346f21..656bb39ab 100644 --- a/AI/VCAI/AIUtility.h +++ b/AI/VCAI/AIUtility.h @@ -23,9 +23,9 @@ class CCallback; struct creInfo; -typedef const int3 & crint3; -typedef const std::string & crstring; -typedef std::pair> dwellingContent; +using crint3 = const int3 &; +using crstring = const std::string &; +using dwellingContent = std::pair>; const int GOLD_MINE_PRODUCTION = 1000, WOOD_ORE_MINE_PRODUCTION = 2, RESOURCE_MINE_PRODUCTION = 1; const int ACTUAL_RESOURCE_COUNT = 7; diff --git a/AI/VCAI/Goals/AbstractGoal.h b/AI/VCAI/Goals/AbstractGoal.h index 677a53a18..ed4fc9430 100644 --- a/AI/VCAI/Goals/AbstractGoal.h +++ b/AI/VCAI/Goals/AbstractGoal.h @@ -76,7 +76,7 @@ namespace Goals //TODO: serialize? }; - typedef std::vector TGoalVec; + using TGoalVec = std::vector; //method chaining + clone pattern #define VSETTER(type, field) virtual AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;}; @@ -121,8 +121,7 @@ namespace Goals TSubgoal parent; VSETTER(TSubgoal, parent) EvaluationContext evaluationContext; VSETTER(EvaluationContext, evaluationContext) - AbstractGoal(EGoals goal = EGoals::INVALID) - : goalType(goal), evaluationContext() + AbstractGoal(EGoals goal = EGoals::INVALID): goalType(goal) { priority = 0; isElementar = false; diff --git a/AI/VCAI/Pathfinding/AINodeStorage.h b/AI/VCAI/Pathfinding/AINodeStorage.h index b63ffc25e..98486612f 100644 --- a/AI/VCAI/Pathfinding/AINodeStorage.h +++ b/AI/VCAI/Pathfinding/AINodeStorage.h @@ -19,8 +19,6 @@ class CCallback; -extern boost::thread_specific_ptr cb; //for templates - struct AIPathNode : public CGPathNode { uint32_t chainMask; diff --git a/client/CMusicHandler.h b/client/CMusicHandler.h index 9c909c347..3594cf37d 100644 --- a/client/CMusicHandler.h +++ b/client/CMusicHandler.h @@ -14,7 +14,7 @@ struct _Mix_Music; struct SDL_RWops; -typedef struct _Mix_Music Mix_Music; +using Mix_Music = struct _Mix_Music; struct Mix_Chunk; class CAudioBase { diff --git a/client/Client.h b/client/Client.h index b4a89e089..9bdd3a020 100644 --- a/client/Client.h +++ b/client/Client.h @@ -61,8 +61,8 @@ namespace boost { class thread; } template class ThreadSafeVector { - typedef std::vector TVector; - typedef boost::unique_lock TLock; + using TVector = std::vector; + using TLock = boost::unique_lock; TVector items; boost::mutex mx; boost::condition_variable cond; diff --git a/client/battle/CreatureAnimation.h b/client/battle/CreatureAnimation.h index 610b397fd..2e7ac4a7f 100644 --- a/client/battle/CreatureAnimation.h +++ b/client/battle/CreatureAnimation.h @@ -68,7 +68,7 @@ namespace AnimationControls class CreatureAnimation : public CIntObject { public: - typedef std::function TSpeedController; + using TSpeedController = std::function; private: std::string name; diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index a1fbc9e37..768476758 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -80,7 +80,7 @@ private: std::vector> disposed; std::atomic continueEventHandling; - typedef std::list CIntObjectList; + using CIntObjectList = std::list; //active GUI elements (listening for events CIntObjectList lclickable; @@ -107,11 +107,9 @@ private: public: void handleElementActivate(CIntObject * elem, ui16 activityFlag); void handleElementDeActivate(CIntObject * elem, ui16 activityFlag); - public: //objs to blit std::vector> objsToBlit; - /// returns current position of mouse cursor, relative to vcmi window const Point & getCursorPosition() const; diff --git a/client/gui/CIntObject.h b/client/gui/CIntObject.h index ff26c96d4..6ecd276bd 100644 --- a/client/gui/CIntObject.h +++ b/client/gui/CIntObject.h @@ -17,7 +17,7 @@ struct SDL_Surface; class CGuiHandler; class CPicture; -typedef int32_t SDL_Keycode; +using SDL_Keycode = int32_t; using boost::logic::tribool; diff --git a/client/renderSDL/CTrueTypeFont.h b/client/renderSDL/CTrueTypeFont.h index 407d083f5..bd3fc4a53 100644 --- a/client/renderSDL/CTrueTypeFont.h +++ b/client/renderSDL/CTrueTypeFont.h @@ -17,7 +17,7 @@ VCMI_LIB_NAMESPACE_END class CBitmapFont; -typedef struct _TTF_Font TTF_Font; +using TTF_Font = struct _TTF_Font; class CTrueTypeFont : public IFont { diff --git a/client/renderSDL/SDL_Extensions.h b/client/renderSDL/SDL_Extensions.h index 417010ea1..528e52681 100644 --- a/client/renderSDL/SDL_Extensions.h +++ b/client/renderSDL/SDL_Extensions.h @@ -45,8 +45,8 @@ SDL_Color toSDL(const ColorRGBA & color); void setColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors); void setAlpha(SDL_Surface * bg, int value); -typedef void (*TColorPutter)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B); -typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B, const uint8_t & A); +using TColorPutter = void (*)(uint8_t *&, const uint8_t &, const uint8_t &, const uint8_t &); +using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &, const uint8_t &, const uint8_t &); void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst); void blitAt(SDL_Surface * src, const Rect & pos, SDL_Surface * dst); @@ -57,23 +57,23 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_ void blitSurface(SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dest); void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest); - void fillSurface(SDL_Surface *dst, const SDL_Color & color); - void fillRect(SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color); + void fillSurface(SDL_Surface * dst, const SDL_Color & color); + void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color); - void updateRect(SDL_Surface *surface, const Rect & rect); + void updateRect(SDL_Surface * surface, const Rect & rect); - void putPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const uint8_t & R, const uint8_t & G, const uint8_t & B, uint8_t A = 255); + void putPixelWithoutRefresh(SDL_Surface * ekran, const int & x, const int & y, const uint8_t & R, const uint8_t & G, const uint8_t & B, uint8_t A = 255); void putPixelWithoutRefreshIfInSurf(SDL_Surface *ekran, const int & x, const int & y, const uint8_t & R, const uint8_t & G, const uint8_t & B, uint8_t A = 255); SDL_Surface * verticalFlip(SDL_Surface * toRot); //vertical flip SDL_Surface * horizontalFlip(SDL_Surface * toRot); //horizontal flip - uint32_t getPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); + uint32_t getPixel(SDL_Surface * surface, const int & x, const int & y, bool colorByte = false); bool isTransparent(SDL_Surface * srf, int x, int y); //checks if surface is transparent at given position - bool isTransparent(SDL_Surface * srf, const Point & position); //checks if surface is transparent at given position + bool isTransparent(SDL_Surface * srf, const Point & position); //checks if surface is transparent at given position - uint8_t *getPxPtr(const SDL_Surface * const &srf, const int x, const int y); - TColorPutter getPutterFor(SDL_Surface * const &dest, int incrementing); //incrementing: -1, 0, 1 - TColorPutterAlpha getPutterAlphaFor(SDL_Surface * const &dest, int incrementing); //incrementing: -1, 0, 1 + uint8_t * getPxPtr(const SDL_Surface * const & srf, const int x, const int y); + TColorPutter getPutterFor(SDL_Surface * const & dest, int incrementing); //incrementing: -1, 0, 1 + TColorPutterAlpha getPutterAlphaFor(SDL_Surface * const & dest, int incrementing); //incrementing: -1, 0, 1 template int blit8bppAlphaTo24bppT(const SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dstPoint); //blits 8 bpp surface with alpha channel to 24 bpp surface @@ -84,8 +84,8 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_ void drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2); void drawLineDashed(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color); - void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color &color, int depth = 1); - void drawBorder(SDL_Surface * sur, const Rect &r, const SDL_Color &color, int depth = 1); + void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color & color, int depth = 1); + void drawBorder(SDL_Surface * sur, const Rect & r, const SDL_Color & color, int depth = 1); void setPlayerColor(SDL_Surface * sur, PlayerColor player); //sets correct color of flags; -1 for neutral SDL_Surface * newSurface(int w, int h, SDL_Surface * mod); //creates new surface, with flags/format same as in surface given @@ -97,18 +97,18 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_ //scale surface to required size. //nearest neighbour algorithm - SDL_Surface * scaleSurfaceFast(SDL_Surface *surf, int width, int height); + SDL_Surface * scaleSurfaceFast(SDL_Surface * surf, int width, int height); // bilinear filtering. Uses fallback to scaleSurfaceFast in case of indexed surfaces - SDL_Surface * scaleSurface(SDL_Surface *surf, int width, int height); + SDL_Surface * scaleSurface(SDL_Surface * surf, int width, int height); template - void convertToGrayscaleBpp( SDL_Surface * surf, const Rect & rect ); + void convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect); void convertToGrayscale(SDL_Surface * surf, const Rect & rect); - bool isResolutionSupported(const std::vector & resolutions, const Point toTest ); + bool isResolutionSupported(const std::vector & resolutions, const Point toTest); std::vector getSupportedResolutions(); - std::vector getSupportedResolutions( int displayIndex); + std::vector getSupportedResolutions(int displayIndex); void setColorKey(SDL_Surface * surface, SDL_Color color); @@ -118,13 +118,13 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_ void setDefaultColorKeyPresize(SDL_Surface * surface); /// helper that will safely set and un-set ClipRect for SDL_Surface - class CClipRectGuard : boost::noncopyable + class CClipRectGuard: boost::noncopyable { SDL_Surface * surf; Rect oldRect; + public: - CClipRectGuard(SDL_Surface * surface, const Rect & rect): - surf(surface) + CClipRectGuard(SDL_Surface * surface, const Rect & rect): surf(surface) { CSDL_Ext::getClipRect(surf, oldRect); CSDL_Ext::setClipRect(surf, rect); diff --git a/client/renderSDL/SDL_PixelAccess.h b/client/renderSDL/SDL_PixelAccess.h index f61946ba9..ddd91a663 100644 --- a/client/renderSDL/SDL_PixelAccess.h +++ b/client/renderSDL/SDL_PixelAccess.h @@ -47,7 +47,7 @@ namespace Channels static void STRONG_INLINE set(uint8_t *ptr, uint8_t value) { - uint16_t * const pixel = (uint16_t*)ptr; + auto * const pixel = (uint16_t *)ptr; uint8_t subpx = value >> (8 - bits); *pixel = (*pixel & ~mask) | ((subpx << shift) & mask ); } @@ -226,7 +226,7 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(uint8_t *&ptr, const u if(incrementPtr == -1) ptr -= 2; - uint16_t * const px = (uint16_t*)ptr; + auto * const px = (uint16_t *)ptr; *px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color if(incrementPtr == 1) diff --git a/client/widgets/ObjectLists.h b/client/widgets/ObjectLists.h index 9930f5fe7..f60e4cc3b 100644 --- a/client/widgets/ObjectLists.h +++ b/client/widgets/ObjectLists.h @@ -25,7 +25,7 @@ class CAnimation; class CObjectList : public CIntObject { public: - typedef std::function(size_t)> CreateFunc; + using CreateFunc = std::function(size_t)>; private: CreateFunc createObject; diff --git a/client/windows/InfoWindows.h b/client/windows/InfoWindows.h index a179c26df..0bc3bc584 100644 --- a/client/windows/InfoWindows.h +++ b/client/windows/InfoWindows.h @@ -45,8 +45,8 @@ public: class CInfoWindow : public CSimpleWindow { public: - typedef std::vector > > TButtonsInfo; - typedef std::vector> TCompsInfo; + using TButtonsInfo = std::vector>>; + using TCompsInfo = std::vector>; QueryID ID; //for identification std::shared_ptr text; std::vector> buttons; diff --git a/include/vcmi/spells/Magic.h b/include/vcmi/spells/Magic.h index af69982f2..20a21541e 100644 --- a/include/vcmi/spells/Magic.h +++ b/include/vcmi/spells/Magic.h @@ -52,7 +52,7 @@ enum class AimType class DLL_LINKAGE Problem { public: - typedef int Severity; + using Severity = int; enum ESeverity { diff --git a/include/vstd/RNG.h b/include/vstd/RNG.h index 9a8653141..53c323bcb 100644 --- a/include/vstd/RNG.h +++ b/include/vstd/RNG.h @@ -15,8 +15,8 @@ VCMI_LIB_NAMESPACE_BEGIN namespace vstd { -typedef std::function TRandI64; -typedef std::function TRand; +using TRandI64 = std::function; +using TRand = std::function; class DLL_LINKAGE RNG { diff --git a/lib/BattleFieldHandler.h b/lib/BattleFieldHandler.h index ecc8ef227..1e8a17d10 100644 --- a/lib/BattleFieldHandler.h +++ b/lib/BattleFieldHandler.h @@ -36,8 +36,12 @@ public: { } - BattleFieldInfo(BattleField battlefield, std::string identifier) - :bonuses(), isSpecial(false), battlefield(battlefield), identifier(identifier), graphics(), icon(), iconIndex(battlefield.getNum()), impassableHexes(), name(identifier) + BattleFieldInfo(BattleField battlefield, std::string identifier): + isSpecial(false), + battlefield(battlefield), + identifier(identifier), + iconIndex(battlefield.getNum()), + name(identifier) { } diff --git a/lib/CBonusTypeHandler.h b/lib/CBonusTypeHandler.h index 3cb68dfb3..acfe49c76 100644 --- a/lib/CBonusTypeHandler.h +++ b/lib/CBonusTypeHandler.h @@ -19,7 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN class JsonNode; -typedef Bonus::BonusType BonusTypeID; +using BonusTypeID = Bonus::BonusType; class DLL_LINKAGE CBonusType { diff --git a/lib/CConfigHandler.h b/lib/CConfigHandler.h index a4676af6c..2c85bef57 100644 --- a/lib/CConfigHandler.h +++ b/lib/CConfigHandler.h @@ -171,7 +171,7 @@ namespace config GUIOptions *current; // pointer to current gui options public: - typedef std::map, GUIOptions > GuiOptionsMap; + using GuiOptionsMap = std::map, GUIOptions>; GuiOptionsMap guiOptions; void init(); CConfigHandler(); diff --git a/lib/CCreatureSet.h b/lib/CCreatureSet.h index 2530e8b5c..c1011b85f 100644 --- a/lib/CCreatureSet.h +++ b/lib/CCreatureSet.h @@ -163,22 +163,18 @@ public: } }; -typedef std::map TSlots; -typedef std::map> TSimpleSlots; +using TSlots = std::map; +using TSimpleSlots = std::map>; -typedef std::pair TPairCreatureSlot; -typedef std::map TMapCreatureSlot; +using TPairCreatureSlot = std::pair; +using TMapCreatureSlot = std::map; struct DLL_LINKAGE CreatureSlotComparer { bool operator()(const TPairCreatureSlot & lhs, const TPairCreatureSlot & rhs); }; -typedef std::priority_queue< - TPairCreatureSlot, - std::vector, - CreatureSlotComparer -> TCreatureQueue; +using TCreatureQueue = std::priority_queue, CreatureSlotComparer>; class IArmyDescriptor { diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index e1ae5b740..5db6ff54f 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -198,10 +198,9 @@ public: if(!h.saving) { - for(auto i = 0; i < secSkillProbability.size(); i++) - if(secSkillProbability[i] < 0) - secSkillProbability[i] = 0; - } + for(int & i : secSkillProbability) + vstd::amax(i, 0); + } } EAlignment getAlignment() const; }; diff --git a/lib/CModHandler.h b/lib/CModHandler.h index e1a8bdec2..04eb645cb 100644 --- a/lib/CModHandler.h +++ b/lib/CModHandler.h @@ -310,7 +310,7 @@ public: missingMods(std::move(_missingMods)) { std::ostringstream _ss; - for(auto & m : missingMods) + for(const auto & m : missingMods) _ss << m.first << ' ' << m.second << std::endl; message = _ss.str(); } diff --git a/lib/CPathfinder.h b/lib/CPathfinder.h index aef8dc2ee..b8c55b157 100644 --- a/lib/CPathfinder.h +++ b/lib/CPathfinder.h @@ -42,7 +42,7 @@ struct DLL_LINKAGE NodeComparer struct DLL_LINKAGE CGPathNode { - typedef EPathfindingLayer ELayer; + using ELayer = EPathfindingLayer; enum ENodeAction : ui8 { @@ -151,10 +151,7 @@ struct DLL_LINKAGE CGPathNode return turns < 255; } - typedef boost::heap::fibonacci_heap< - CGPathNode *, - boost::heap::compare> - > TFibHeap; + using TFibHeap = boost::heap::fibonacci_heap>>; TFibHeap::handle_type pqHandle; TFibHeap* pq; @@ -173,7 +170,7 @@ struct DLL_LINKAGE CGPath struct DLL_LINKAGE CPathsInfo { - typedef EPathfindingLayer ELayer; + using ELayer = EPathfindingLayer; const CGHeroInstance * hero; int3 hpos; @@ -484,7 +481,7 @@ public: private: CGameState * gamestate; - typedef EPathfindingLayer ELayer; + using ELayer = EPathfindingLayer; std::shared_ptr config; diff --git a/lib/CRandomGenerator.h b/lib/CRandomGenerator.h index 0b14c65ee..5b76adcb1 100644 --- a/lib/CRandomGenerator.h +++ b/lib/CRandomGenerator.h @@ -14,11 +14,11 @@ VCMI_LIB_NAMESPACE_BEGIN -typedef std::mt19937 TGenerator; -typedef std::uniform_int_distribution TIntDist; -typedef std::uniform_int_distribution TInt64Dist; -typedef std::uniform_real_distribution TRealDist; -typedef std::function TRandI; +using TGenerator = std::mt19937; +using TIntDist = std::uniform_int_distribution; +using TInt64Dist = std::uniform_int_distribution; +using TRealDist = std::uniform_real_distribution; +using TRandI = std::function; /// The random generator randomly generates integers and real numbers("doubles") between /// a given range. This is a header only class and mainly a wrapper for diff --git a/lib/CStack.h b/lib/CStack.h index 920bf2d47..753a8a855 100644 --- a/lib/CStack.h +++ b/lib/CStack.h @@ -121,7 +121,7 @@ public: if(extSlot == SlotID::COMMANDER_SLOT_PLACEHOLDER) { - auto hero = dynamic_cast(army); + const auto * hero = dynamic_cast(army); assert(hero); base = hero->commander; } diff --git a/lib/CThreadHelper.h b/lib/CThreadHelper.h index a4eaf8f8b..aaa3e67f3 100644 --- a/lib/CThreadHelper.h +++ b/lib/CThreadHelper.h @@ -17,7 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN class DLL_LINKAGE CThreadHelper { public: - typedef std::function Task; + using Task = std::function; CThreadHelper(std::vector > *Tasks, int Threads); void run(); private: diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 7bc7a6d43..407260154 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -43,7 +43,7 @@ class DLL_LINKAGE CBuilding std::string identifier; public: - typedef LogicalExpression TRequired; + using TRequired = LogicalExpression; CTown * town; // town this building belongs to TResources resources; diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 199311e88..ca36e747a 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -1325,11 +1325,11 @@ enum class EHealPower : ui8 }; // Typedef declarations -typedef si64 TExpType; -typedef si32 TBonusSubtype; -typedef si32 TQuantity; +using TExpType = si64; +using TBonusSubtype = si32; +using TQuantity = si32; -typedef int TRmgTemplateZoneId; +using TRmgTemplateZoneId = int; #undef ID_LIKE_CLASS_COMMON #undef ID_LIKE_OPERATORS diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 43ba4f4e5..cd695d7d0 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -25,14 +25,14 @@ class IPropagator; class IUpdater; class BonusList; -typedef std::shared_ptr TBonusListPtr; -typedef std::shared_ptr TConstBonusListPtr; -typedef std::shared_ptr TLimiterPtr; -typedef std::shared_ptr TPropagatorPtr; -typedef std::shared_ptr TUpdaterPtr; -typedef std::set TNodes; -typedef std::set TCNodes; -typedef std::vector TNodesVector; +using TBonusListPtr = std::shared_ptr; +using TConstBonusListPtr = std::shared_ptr; +using TLimiterPtr = std::shared_ptr; +using TPropagatorPtr = std::shared_ptr; +using TUpdaterPtr = std::shared_ptr; +using TNodes = std::set; +using TCNodes = std::set; +using TNodesVector = std::vector; class CSelector : std::function { @@ -548,7 +548,7 @@ struct DLL_LINKAGE BonusParams { bool isConverted; Bonus::BonusType type = Bonus::NONE; TBonusSubtype subtype = -1; - std::string subtypeStr = ""; + std::string subtypeStr; bool subtypeRelevant = false; Bonus::ValueType valueType = Bonus::BASE_NUMBER; bool valueTypeRelevant = false; @@ -569,7 +569,7 @@ private: class DLL_LINKAGE BonusList { public: - typedef std::vector> TInternalContainer; + using TInternalContainer = std::vector>; private: TInternalContainer bonuses; @@ -577,11 +577,11 @@ private: void changed() const; public: - typedef TInternalContainer::const_reference const_reference; - typedef TInternalContainer::value_type value_type; + using const_reference = TInternalContainer::const_reference; + using value_type = TInternalContainer::value_type; - typedef TInternalContainer::const_iterator const_iterator; - typedef TInternalContainer::iterator iterator; + using const_iterator = TInternalContainer::const_iterator; + using iterator = TInternalContainer::iterator; BonusList(bool BelongsToTree = false); BonusList(const BonusList &bonusList); @@ -628,9 +628,8 @@ public: void remove_if(Predicate pred) { BonusList newList; - for (ui32 i = 0; i < bonuses.size(); i++) + for(const auto & b : bonuses) { - auto b = bonuses[i]; if (!pred(b.get())) newList.push_back(b); } diff --git a/lib/IHandlerBase.h b/lib/IHandlerBase.h index 5d4008a6f..f513f3593 100644 --- a/lib/IHandlerBase.h +++ b/lib/IHandlerBase.h @@ -97,7 +97,7 @@ public: objects.push_back(object); - for(auto type_name : getTypeNames()) + for(const auto & type_name : getTypeNames()) registerObject(scope, type_name, name, object->getIndex()); } @@ -108,7 +108,7 @@ public: assert(objects[index] == nullptr); // ensure that this id was not loaded before objects[index] = object; - for(auto type_name : getTypeNames()) + for(const auto & type_name : getTypeNames()) registerObject(scope, type_name, name, object->getIndex()); } diff --git a/lib/JsonDetail.h b/lib/JsonDetail.h index 6ea5913bb..b817b8961 100644 --- a/lib/JsonDetail.h +++ b/lib/JsonDetail.h @@ -116,10 +116,10 @@ namespace Validation std::string makeErrorMessage(const std::string &message); }; - typedef std::function TFormatValidator; - typedef std::unordered_map TFormatMap; - typedef std::function TFieldValidator; - typedef std::unordered_map TValidatorMap; + using TFormatValidator = std::function; + using TFormatMap = std::unordered_map; + using TFieldValidator = std::function; + using TValidatorMap = std::unordered_map; /// map of known fields in schema const TValidatorMap & getKnownFieldsFor(JsonNode::JsonType type); diff --git a/lib/JsonNode.h b/lib/JsonNode.h index ba2275ece..d15ea509b 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -13,8 +13,8 @@ VCMI_LIB_NAMESPACE_BEGIN class JsonNode; -typedef std::map JsonMap; -typedef std::vector JsonVector; +using JsonMap = std::map; +using JsonVector = std::vector; struct Bonus; class CSelector; diff --git a/lib/LogicalExpression.h b/lib/LogicalExpression.h index a94108e3c..6bc3f36fa 100644 --- a/lib/LogicalExpression.h +++ b/lib/LogicalExpression.h @@ -30,19 +30,14 @@ namespace LogicalExpressionDetail }; template class Element; - typedef Element OperatorAny; - typedef Element OperatorAll; - typedef Element OperatorNone; + using OperatorAny = Element; + using OperatorAll = Element; + using OperatorNone = Element; - typedef ContainedClass Value; + using Value = ContainedClass; /// Variant that contains all possible elements from logical expression - typedef std::variant< - OperatorAll, - OperatorAny, - OperatorNone, - Value - > Variant; + using Variant = std::variant; /// Variant element, contains list of expressions to which operation "tag" should be applied template @@ -73,7 +68,7 @@ namespace LogicalExpressionDetail template class TestVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; std::function classTest; @@ -119,7 +114,7 @@ namespace LogicalExpressionDetail template class PossibilityVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; protected: std::function satisfiabilityTest; @@ -167,7 +162,7 @@ namespace LogicalExpressionDetail template class SatisfiabilityVisitor : public PossibilityVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; public: SatisfiabilityVisitor(std::function satisfiabilityTest, @@ -202,7 +197,7 @@ namespace LogicalExpressionDetail template class FalsifiabilityVisitor : public PossibilityVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; public: FalsifiabilityVisitor(std::function satisfiabilityTest, @@ -238,8 +233,8 @@ namespace LogicalExpressionDetail template class CandidatesVisitor { - typedef ExpressionBase Base; - typedef std::vector TValueList; + using Base = ExpressionBase; + using TValueList = std::vector; TestVisitor classTest; @@ -288,7 +283,7 @@ namespace LogicalExpressionDetail template class ForEachVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; std::function visitor; @@ -315,7 +310,7 @@ namespace LogicalExpressionDetail template class MinimizingVisitor { - typedef ExpressionBase Base; + using Base = ExpressionBase; public: typename Base::Variant operator()(const typename Base::Value & element) const @@ -360,7 +355,7 @@ namespace LogicalExpressionDetail template class Reader { - typedef ExpressionBase Base; + using Base = ExpressionBase; std::function classParser; @@ -400,7 +395,7 @@ namespace LogicalExpressionDetail template class Writer { - typedef ExpressionBase Base; + using Base = ExpressionBase; std::function classPrinter; @@ -445,7 +440,7 @@ namespace LogicalExpressionDetail template class Printer { - typedef ExpressionBase Base; + using Base = ExpressionBase; std::function classPrinter; std::unique_ptr> statusTest; @@ -510,30 +505,27 @@ namespace LogicalExpressionDetail template class LogicalExpression { - typedef LogicalExpressionDetail::ExpressionBase Base; + using Base = LogicalExpressionDetail::ExpressionBase; + public: /// Type of values used in expressions, same as ContainedClass - typedef typename Base::Value Value; + using Value = typename Base::Value; /// Operators for use in expressions, all include vectors with operands - typedef typename Base::OperatorAny OperatorAny; - typedef typename Base::OperatorAll OperatorAll; - typedef typename Base::OperatorNone OperatorNone; + using OperatorAny = typename Base::OperatorAny; + using OperatorAll = typename Base::OperatorAll; + using OperatorNone = typename Base::OperatorNone; /// one expression entry - typedef typename Base::Variant Variant; + using Variant = typename Base::Variant; private: Variant data; public: /// Base constructor - LogicalExpression() - {} + LogicalExpression() = default; /// Constructor from variant or (implicitly) from Operator* types - LogicalExpression(const Variant & data): - data(data) - { - } + LogicalExpression(const Variant & data): data(data) {} /// Constructor that receives JsonNode as input and function that can parse Value instances LogicalExpression(const JsonNode & input, std::function parser) diff --git a/lib/ResourceSet.h b/lib/ResourceSet.h index 611b24e8d..6d879f715 100644 --- a/lib/ResourceSet.h +++ b/lib/ResourceSet.h @@ -161,8 +161,8 @@ public: ResourceSet & operator=(const TResource &rhs) { - for(int i = 0; i < container.size(); i++) - container.at(i) = rhs; + for(int & i : container) + i = rhs; return *this; } diff --git a/lib/StartInfo.h b/lib/StartInfo.h index 96acfa2b8..052f5ccf5 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -76,7 +76,7 @@ struct DLL_LINKAGE StartInfo EMode mode; ui8 difficulty; //0=easy; 4=impossible - typedef std::map TPlayerInfos; + using TPlayerInfos = std::map; TPlayerInfos playerInfos; //color indexed ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack) @@ -84,7 +84,7 @@ struct DLL_LINKAGE StartInfo ui32 mapfileChecksum; //0 if not relevant ui8 turnTime; //in minutes, 0=unlimited std::string mapname; // empty for random map, otherwise name of the map or savegame - bool createRandomMap() const { return mapGenOptions.get() != nullptr; } + bool createRandomMap() const { return mapGenOptions != nullptr; } std::shared_ptr mapGenOptions; std::shared_ptr campState; diff --git a/lib/UnlockGuard.h b/lib/UnlockGuard.h index 51ec8541d..39fb8ebb8 100644 --- a/lib/UnlockGuard.h +++ b/lib/UnlockGuard.h @@ -114,7 +114,7 @@ namespace vstd : unlock_guard >(); } - typedef unlock_guard > unlock_shared_guard; + using unlock_shared_guard = unlock_guard>; } VCMI_LIB_NAMESPACE_END diff --git a/lib/filesystem/Filesystem.h b/lib/filesystem/Filesystem.h index cdbff4f27..a6b894ab0 100644 --- a/lib/filesystem/Filesystem.h +++ b/lib/filesystem/Filesystem.h @@ -21,8 +21,8 @@ class JsonNode; /// Helper class that allows generation of a ISimpleResourceLoader entry out of Json config(s) class DLL_LINKAGE CFilesystemGenerator { - typedef std::function TLoadFunctor; - typedef std::map TLoadFunctorMap; + using TLoadFunctor = std::function; + using TLoadFunctorMap = std::map; CFilesystemList * filesystem; std::string prefix; diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index 910ee3f16..36e234108 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/lib/mapObjects/CObjectClassesHandler.h @@ -241,7 +241,7 @@ public: } }; -typedef std::shared_ptr TObjectTypeHandler; +using TObjectTypeHandler = std::shared_ptr; /// Class responsible for creation of adventure map objects of specific type class DLL_LINKAGE ObjectClass @@ -283,7 +283,7 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase std::map > handlerConstructors; /// container with H3 templates, used only during loading, no need to serialize it - typedef std::multimap, std::shared_ptr> TTemplatesContainer; + using TTemplatesContainer = std::multimap, std::shared_ptr>; TTemplatesContainer legacyTemplates; TObjectTypeHandler loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index); diff --git a/lib/mapObjects/CommonConstructors.h b/lib/mapObjects/CommonConstructors.h index de0a25c82..1513d293f 100644 --- a/lib/mapObjects/CommonConstructors.h +++ b/lib/mapObjects/CommonConstructors.h @@ -197,7 +197,7 @@ struct BankConfig } }; -typedef std::vector> TPossibleGuards; +using TPossibleGuards = std::vector>; template struct DLL_LINKAGE PossibleReward diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index 158e69a50..493727567 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -189,11 +189,9 @@ protected: class DLL_LINKAGE CGArtifact : public CArmedInstance { public: - CArtifactInstance *storedArtifact; + CArtifactInstance * storedArtifact = nullptr; std::string message; - CGArtifact() : CArmedInstance() {storedArtifact = nullptr;}; - void onHeroVisit(const CGHeroInstance * h) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 2c5aa3596..56dff77e3 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -160,7 +160,7 @@ struct DLL_LINKAGE EventCondition } }; -typedef LogicalExpression EventExpression; +using EventExpression = LogicalExpression; struct DLL_LINKAGE EventEffect { diff --git a/lib/mapping/CMapEditManager.h b/lib/mapping/CMapEditManager.h index 04a52b39a..b072d1828 100644 --- a/lib/mapping/CMapEditManager.h +++ b/lib/mapping/CMapEditManager.h @@ -46,7 +46,7 @@ public: void setUndoCallback(std::function functor); private: - typedef std::list > TStack; + using TStack = std::list>; void doOperation(TStack & fromStack, TStack & toStack, bool doUndo); const CMapOperation * peek(const TStack & stack) const; diff --git a/lib/mapping/MapEditUtils.h b/lib/mapping/MapEditUtils.h index dd45b95e7..474c2d946 100644 --- a/lib/mapping/MapEditUtils.h +++ b/lib/mapping/MapEditUtils.h @@ -212,7 +212,7 @@ struct DLL_LINKAGE TerrainViewPattern class DLL_LINKAGE CTerrainViewPatternConfig : public boost::noncopyable { public: - typedef std::vector TVPVector; + using TVPVector = std::vector; CTerrainViewPatternConfig(); diff --git a/lib/rmg/CMapGenerator.h b/lib/rmg/CMapGenerator.h index 162aeb406..39c66204d 100644 --- a/lib/rmg/CMapGenerator.h +++ b/lib/rmg/CMapGenerator.h @@ -26,7 +26,7 @@ class RmgMap; class CMap; class Zone; -typedef std::vector JsonVector; +using JsonVector = std::vector; /// The map generator creates a map randomly. class DLL_LINKAGE CMapGenerator: public Load::Progress diff --git a/lib/rmg/CZonePlacer.h b/lib/rmg/CZonePlacer.h index 34e24f6f9..4914739ec 100644 --- a/lib/rmg/CZonePlacer.h +++ b/lib/rmg/CZonePlacer.h @@ -22,10 +22,10 @@ class CRandomGenerator; class RmgMap; class Zone; -typedef std::vector>> TZoneVector; -typedef std::map> TZoneMap; -typedef std::map, float3> TForceVector; -typedef std::map, float> TDistanceVector; +using TZoneVector = std::vector>>; +using TZoneMap = std::map>; +using TForceVector = std::map, float3>; +using TDistanceVector = std::map, float>; class CZonePlacer { diff --git a/lib/rmg/ConnectionsPlacer.h b/lib/rmg/ConnectionsPlacer.h index ac577b687..80a8780d7 100644 --- a/lib/rmg/ConnectionsPlacer.h +++ b/lib/rmg/ConnectionsPlacer.h @@ -30,7 +30,7 @@ public: protected: void collectNeighbourZones(); - + protected: std::vector dConnections, dCompleted; std::map dNeighbourZones; diff --git a/lib/rmg/ObjectManager.h b/lib/rmg/ObjectManager.h index d3ef132dc..f8d3775dc 100644 --- a/lib/rmg/ObjectManager.h +++ b/lib/rmg/ObjectManager.h @@ -20,7 +20,7 @@ class CGObjectInstance; class ObjectTemplate; class CGCreature; -typedef std::pair TDistance; +using TDistance = std::pair; struct DistanceMaximizeFunctor { bool operator()(const TDistance & lhs, const TDistance & rhs) const @@ -38,11 +38,10 @@ public: WEIGHT = 0x00000001, DISTANCE = 0x00000010 }; - + public: MODIFICATOR(ObjectManager); - void process() override; void init() override; diff --git a/lib/rmg/ObstaclePlacer.h b/lib/rmg/ObstaclePlacer.h index b18a1bae0..8776abfb1 100644 --- a/lib/rmg/ObstaclePlacer.h +++ b/lib/rmg/ObstaclePlacer.h @@ -43,9 +43,9 @@ public: protected: int getWeightedObjects(const int3 & tile, const CMap * map, CRandomGenerator & rand, std::list & allObjects, std::vector> & weightedObjects); - typedef std::vector> ObstacleVector; + using ObstacleVector = std::vector>; std::map obstaclesBySize; - typedef std::pair ObstaclePair; + using ObstaclePair = std::pair; std::vector possibleObstacles; }; diff --git a/lib/rmg/RmgMap.h b/lib/rmg/RmgMap.h index 1144d0d22..8c52ac0a5 100644 --- a/lib/rmg/RmgMap.h +++ b/lib/rmg/RmgMap.h @@ -72,7 +72,7 @@ public: private: void assertOnMap(const int3 &tile) const; //throws - + private: Zones zones; std::map zonesPerFaction; diff --git a/lib/rmg/RoadPlacer.h b/lib/rmg/RoadPlacer.h index 092f3499f..1f4651f87 100644 --- a/lib/rmg/RoadPlacer.h +++ b/lib/rmg/RoadPlacer.h @@ -31,7 +31,7 @@ public: protected: bool createRoad(const int3 & dst); void drawRoads(bool secondary = false); //actually updates tiles - + protected: rmg::Tileset roadNodes; //tiles to be connected with roads rmg::Area roads; //all tiles with roads diff --git a/lib/rmg/TownPlacer.h b/lib/rmg/TownPlacer.h index cdcf5eeef..374df621d 100644 --- a/lib/rmg/TownPlacer.h +++ b/lib/rmg/TownPlacer.h @@ -32,9 +32,8 @@ protected: void placeTowns(ObjectManager & manager); bool placeMines(ObjectManager & manager); int3 placeMainTown(ObjectManager & manager, CGTownInstance & town); - + protected: - int totalTowns = 0; }; diff --git a/lib/rmg/TreasurePlacer.h b/lib/rmg/TreasurePlacer.h index 03968e308..cbaad3a9f 100644 --- a/lib/rmg/TreasurePlacer.h +++ b/lib/rmg/TreasurePlacer.h @@ -56,9 +56,8 @@ protected: ObjectInfo * getRandomObject(ui32 desiredValue, ui32 currentValue, ui32 maxValue, bool allowLargeObjects); std::vector prepareTreasurePile(const CTreasureInfo & treasureInfo); rmg::Object constructTreasurePile(const std::vector & treasureInfos, bool densePlacement = false); - - -protected: + +protected: std::vector possibleObjects; int minGuardedValue = 0; diff --git a/lib/rmg/WaterAdopter.h b/lib/rmg/WaterAdopter.h index ef47d3fa8..2f09241da 100644 --- a/lib/rmg/WaterAdopter.h +++ b/lib/rmg/WaterAdopter.h @@ -29,7 +29,7 @@ public: protected: void createWater(EWaterContent::EWaterContent waterContent); - + protected: rmg::Area noWaterArea, waterArea; TRmgTemplateZoneId waterZoneId; diff --git a/lib/rmg/WaterProxy.h b/lib/rmg/WaterProxy.h index de50f7354..7fd1a3361 100644 --- a/lib/rmg/WaterProxy.h +++ b/lib/rmg/WaterProxy.h @@ -49,8 +49,8 @@ protected: bool placeShipyard(Zone & land, const Lake & lake, si32 guard, RouteInfo & info); bool placeBoat(Zone & land, const Lake & lake, RouteInfo & info); - -protected: + +protected: std::vector lakes; //disconnected parts of zone. Used to work with water zones std::map lakeMap; //map tile on lakeId which is position of lake in lakes array +1 }; diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index c8a2588f8..c11e9b764 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -98,7 +98,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase } else { - auto hero = dynamic_cast(armedObj); + auto * hero = dynamic_cast(armedObj); assert(hero); assert(hero->commander); data = hero->commander; @@ -158,7 +158,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase public: const std::type_info * loadPtr(CLoaderBase &ar, void *data, ui32 pid) const override //data is pointer to the ACTUAL POINTER { - BinaryDeserializer &s = static_cast(ar); + auto & s = static_cast(ar); T *&ptr = *static_cast(data); //create new object under pointer @@ -217,7 +217,7 @@ public: assert( fileVersion != 0 ); ////that const cast is evil because it allows to implicitly overwrite const objects when deserializing typedef typename std::remove_const::type nonConstT; - nonConstT &hlp = const_cast(data); + auto & hlp = const_cast(data); hlp.serialize(*this,fileVersion); } template < typename T, typename std::enable_if < std::is_array::value, int >::type = 0 > @@ -301,7 +301,7 @@ public: if(smartPointerSerialization) { load( pid ); //get the id - std::map::iterator i = loadedPointers.find(pid); //lookup + auto i = loadedPointers.find(pid); //lookup if(i != loadedPointers.end()) { @@ -327,7 +327,7 @@ public: } else { - auto app = applier.getApplier(tid); + auto * app = applier.getApplier(tid); if(app == nullptr) { logGlobal->error("load %d %d - no loader exists", tid, pid); diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index df0da5ed5..d6f48a0dc 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -100,7 +100,7 @@ class DLL_LINKAGE BinarySerializer : public CSaverBase public: void savePtr(CSaverBase &ar, const void *data) const override { - BinarySerializer &s = static_cast(ar); + auto & s = static_cast(ar); const T *ptr = static_cast(data); //T is most derived known type, it's time to call actual serialize @@ -210,7 +210,7 @@ public: // We might have an object that has multiple inheritance and store it via the non-first base pointer. // Therefore, all pointers need to be normalized to the actual object address. auto actualPointer = typeList.castToMostDerived(data); - std::map::iterator i = savedPointers.find(actualPointer); + auto i = savedPointers.find(actualPointer); if(i != savedPointers.end()) { //this pointer has been already serialized - write only it's id @@ -275,28 +275,28 @@ public: template void save(const std::set &data) { - std::set &d = const_cast &>(data); + auto & d = const_cast &>(data); ui32 length = (ui32)d.size(); save(length); - for(typename std::set::iterator i=d.begin();i!=d.end();i++) + for(auto i = d.begin(); i != d.end(); i++) save(*i); } template void save(const std::unordered_set &data) { - std::unordered_set &d = const_cast &>(data); + auto & d = const_cast &>(data); ui32 length = (ui32)d.size(); *this & length; - for(typename std::unordered_set::iterator i=d.begin();i!=d.end();i++) + for(auto i = d.begin(); i != d.end(); i++) save(*i); } template void save(const std::list &data) { - std::list &d = const_cast &>(data); + auto & d = const_cast &>(data); ui32 length = (ui32)d.size(); *this & length; - for(typename std::list::iterator i=d.begin();i!=d.end();i++) + for(auto i = d.begin(); i != d.end(); i++) save(*i); } void save(const std::string &data) @@ -314,7 +314,7 @@ public: void save(const std::map &data) { *this & ui32(data.size()); - for(typename std::map::const_iterator i=data.begin();i!=data.end();i++) + for(auto i = data.begin(); i != data.end(); i++) { save(i->first); save(i->second); @@ -324,7 +324,7 @@ public: void save(const std::multimap &data) { *this & ui32(data.size()); - for(typename std::map::const_iterator i = data.begin(); i != data.end(); i++) + for(auto i = data.begin(); i != data.end(); i++) { save(i->first); save(i->second); diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index 2e0d83731..8f20822bd 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -76,7 +76,7 @@ class DLL_LINKAGE CSerializer vectors[&typeid(T)] = VectorizedObjectInfo(Vector, idRetriever); } - typedef std::map TTypeVecMap; + using TTypeVecMap = std::map; TTypeVecMap vectors; //entry must be a pointer to vector containing pointers to the objects of key type public: @@ -94,7 +94,7 @@ public: myType = &typeid(T); - TTypeVecMap::iterator i = vectors.find(myType); + auto i = vectors.find(myType); if(i == vectors.end()) return nullptr; else @@ -134,8 +134,8 @@ public: template struct is_serializeable { - typedef char (&Yes)[1]; - typedef char (&No)[2]; + using Yes = char (&)[1]; + using No = char (&)[2]; template static Yes test(U * data, S* arg1 = 0, @@ -149,42 +149,42 @@ struct is_serializeable template //metafunction returning CGObjectInstance if T is its derivate or T elsewise struct VectorizedTypeFor { - typedef typename + using type = typename //if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else boost::mpl::identity - > >::type type; + >>::type; }; template struct VectorizedIDType { - typedef typename + using type = typename //if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else if - boost::mpl::eval_if, + boost::mpl::eval_if, boost::mpl::identity, //else boost::mpl::identity - > > > > > >::type type; + >>>>>>::type; }; /// Base class for deserializers diff --git a/lib/serializer/CTypeList.h b/lib/serializer/CTypeList.h index a4a9f8a6b..fc5b7c0ac 100644 --- a/lib/serializer/CTypeList.h +++ b/lib/serializer/CTypeList.h @@ -66,17 +66,18 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable { //public: struct TypeDescriptor; - typedef std::shared_ptr TypeInfoPtr; - typedef std::weak_ptr WeakTypeInfoPtr; + using TypeInfoPtr = std::shared_ptr; + using WeakTypeInfoPtr = std::weak_ptr; struct TypeDescriptor { ui16 typeID; const char *name; std::vector children, parents; }; - typedef boost::shared_mutex TMutex; - typedef boost::unique_lock TUniqueLock; - typedef boost::shared_lock TSharedLock; + using TMutex = boost::shared_mutex; + using TUniqueLock = boost::unique_lock; + using TSharedLock = boost::shared_lock; + private: mutable TMutex mx; @@ -103,7 +104,7 @@ private: if(!casters.count(castingPair)) THROW_FORMAT("Cannot find caster for conversion %s -> %s which is needed to cast %s -> %s", from->name % to->name % fromArg->name() % toArg->name()); - auto &caster = casters.at(castingPair); + const auto & caster = casters.at(castingPair); ptr = (*caster.*CastingFunction)(ptr); //Why does unique_ptr not have operator->* ..? } @@ -150,7 +151,7 @@ public: template void * castToMostDerived(const TInput * inputPtr) const { - auto &baseType = typeid(typename std::remove_cv::type); + const auto & baseType = typeid(typename std::remove_cv::type); auto derivedType = getTypeInfo(inputPtr); if (strcmp(baseType.name(), derivedType->name()) == 0) @@ -166,7 +167,7 @@ public: template std::any castSharedToMostDerived(const std::shared_ptr inputPtr) const { - auto &baseType = typeid(typename std::remove_cv::type); + const auto & baseType = typeid(typename std::remove_cv::type); auto derivedType = getTypeInfo(inputPtr.get()); if (!strcmp(baseType.name(), derivedType->name())) diff --git a/lib/serializer/Connection.h b/lib/serializer/Connection.h index b1dfcf51f..518223246 100644 --- a/lib/serializer/Connection.h +++ b/lib/serializer/Connection.h @@ -14,8 +14,8 @@ #if BOOST_VERSION >= 107000 // Boost version >= 1.70 #include -typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp > TSocket; -typedef boost::asio::basic_socket_acceptor < boost::asio::ip::tcp > TAcceptor; +using TSocket = boost::asio::basic_stream_socket; +using TAcceptor = boost::asio::basic_socket_acceptor; #else namespace boost { diff --git a/lib/serializer/JsonSerializeFormat.h b/lib/serializer/JsonSerializeFormat.h index f001f6c43..918918a3d 100644 --- a/lib/serializer/JsonSerializeFormat.h +++ b/lib/serializer/JsonSerializeFormat.h @@ -461,7 +461,7 @@ private: void doSerializeInternal(const std::string & fieldName, VType & value, const std::optional & defaultValue, Args... args) { const std::optional tempDefault = defaultValue ? std::optional(static_cast(defaultValue.value())) : std::nullopt; - IType temp = static_cast(value); + auto temp = static_cast(value); serializeInternal(fieldName, temp, tempDefault, args...); @@ -476,7 +476,7 @@ private: { if(value) { - IType temp = static_cast(value.value()); + auto temp = static_cast(value.value()); pushField(fieldName); serializeInternal(temp, args...); pop(); @@ -518,7 +518,7 @@ void JsonArraySerializer::syncSize(Container & c, JsonNode::JsonType type) template void JsonArraySerializer::serializeInt(const size_t index, T & value) { - int64_t temp = static_cast(value); + auto temp = static_cast(value); serializeInt64(index, temp); diff --git a/lib/spells/CSpellHandler.h b/lib/spells/CSpellHandler.h index 60b3386a9..7c0bf8a81 100644 --- a/lib/spells/CSpellHandler.h +++ b/lib/spells/CSpellHandler.h @@ -92,8 +92,8 @@ public: } }; - typedef AnimationItem TAnimation; - typedef std::vector TAnimationQueue; + using TAnimation = AnimationItem; + using TAnimationQueue = std::vector; struct DLL_LINKAGE AnimationInfo { diff --git a/lib/vcmi_endian.h b/lib/vcmi_endian.h index e270b8eec..c1a81357d 100644 --- a/lib/vcmi_endian.h +++ b/lib/vcmi_endian.h @@ -34,13 +34,13 @@ PACKED_STRUCT_BEGIN struct unaligned_Uint32 { ui32 val; } PACKED_STRUCT_END; static inline ui16 read_unaligned_u16(const void *p) { - const struct unaligned_Uint16 *v = reinterpret_cast(p); + const auto * v = reinterpret_cast(p); return v->val; } static inline ui32 read_unaligned_u32(const void *p) { - const struct unaligned_Uint32 *v = reinterpret_cast(p); + const auto * v = reinterpret_cast(p); return v->val; } diff --git a/scripting/lua/LuaCallWrapper.h b/scripting/lua/LuaCallWrapper.h index 2876102e3..eb785fa26 100644 --- a/scripting/lua/LuaCallWrapper.h +++ b/scripting/lua/LuaCallWrapper.h @@ -31,7 +31,7 @@ struct Gens : Gens {}; template struct Gens<0, S...> { - typedef Seq type; + using type = Seq; }; template diff --git a/scripting/lua/LuaStack.h b/scripting/lua/LuaStack.h index dd5ce9497..fd273eada 100644 --- a/scripting/lua/LuaStack.h +++ b/scripting/lua/LuaStack.h @@ -100,7 +100,7 @@ public: return; } - UData * ptr = static_cast(raw); + auto * ptr = static_cast(raw); *ptr = value; luaL_getmetatable(L, KEY); diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 77f34cf98..d13abea69 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -79,8 +79,8 @@ public: struct CasualtiesAfterBattle { - typedef std::pair TStackAndItsNewCount; - typedef std::map TSummoned; + using TStackAndItsNewCount = std::pair; + using TSummoned = std::map; enum {ERASE = -1}; const CArmedInstance * army; std::vector newStackCounts; diff --git a/server/CQuery.h b/server/CQuery.h index 9c7c92ddd..089e1c256 100644 --- a/server/CQuery.h +++ b/server/CQuery.h @@ -26,7 +26,7 @@ class CObjectVisitQuery; class CQuery; class Queries; -typedef std::shared_ptr QueryPtr; +using QueryPtr = std::shared_ptr; // This class represents any kind of prolonged interaction that may need to do something special after it is over. // It does not necessarily has to be "query" requiring player action, it can be also used internally within server.