From ecf1c47a53c29437d05caf2e21e33b82d24d8b35 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 26 May 2020 14:58:16 +0200 Subject: [PATCH] Make Growth Rate library use unique_ptr --- src/Library/GrowthRates/GrowthRateLibrary.cpp | 4 ++-- src/Library/GrowthRates/GrowthRateLibrary.hpp | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Library/GrowthRates/GrowthRateLibrary.cpp b/src/Library/GrowthRates/GrowthRateLibrary.cpp index 0d582ea..7b3be6e 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.cpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.cpp @@ -37,9 +37,9 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t h void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ConstString& name, CreatureLib::Library::GrowthRate* rate) { - _growthRates.insert({name, rate}); + _growthRates.insert({name, std::unique_ptr(rate)}); } void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) { - _growthRates.insert({hash, rate}); + _growthRates.insert({hash, std::unique_ptr(rate)}); } diff --git a/src/Library/GrowthRates/GrowthRateLibrary.hpp b/src/Library/GrowthRates/GrowthRateLibrary.hpp index de74d93..27f3e9d 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.hpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "GrowthRate.hpp" @@ -12,17 +13,13 @@ using ConstString = Arbutils::CaseInsensitiveConstString; namespace CreatureLib::Library { class GrowthRateLibrary { private: - std::unordered_map _growthRates; + std::unordered_map> _growthRates; public: GrowthRateLibrary(size_t initialCapacity = 10) - : _growthRates(std::unordered_map(initialCapacity)) {} + : _growthRates(std::unordered_map>(initialCapacity)) {} - virtual ~GrowthRateLibrary() { - for (auto gr : _growthRates) { - delete gr.second; - } - } + virtual ~GrowthRateLibrary() = default; [[nodiscard]] uint8_t CalculateLevel(const ConstString& growthRate, uint32_t experience) const; [[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const;