Make Growth Rate library use unique_ptr
This commit is contained in:
parent
aba56d2fdd
commit
ecf1c47a53
|
@ -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<const GrowthRate>(rate)});
|
||||
}
|
||||
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) {
|
||||
_growthRates.insert({hash, rate});
|
||||
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "GrowthRate.hpp"
|
||||
|
@ -12,17 +13,13 @@ using ConstString = Arbutils::CaseInsensitiveConstString;
|
|||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
private:
|
||||
std::unordered_map<uint32_t, GrowthRate*> _growthRates;
|
||||
std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>> _growthRates;
|
||||
|
||||
public:
|
||||
GrowthRateLibrary(size_t initialCapacity = 10)
|
||||
: _growthRates(std::unordered_map<uint32_t, GrowthRate*>(initialCapacity)) {}
|
||||
: _growthRates(std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>>(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;
|
||||
|
|
Loading…
Reference in New Issue