From d746b3eccec08c5b6efbe8d0c294907f14d88f13 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 26 May 2020 16:38:55 +0200 Subject: [PATCH] Make staticlib in battle library an unique ptr. --- CInterface/Battling/BattleLibrary.cpp | 2 +- src/Battling/Library/BattleLibrary.cpp | 2 -- src/Battling/Library/BattleLibrary.hpp | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CInterface/Battling/BattleLibrary.cpp b/CInterface/Battling/BattleLibrary.cpp index db478ac..02bd86a 100644 --- a/CInterface/Battling/BattleLibrary.cpp +++ b/CInterface/Battling/BattleLibrary.cpp @@ -18,7 +18,7 @@ export void CreatureLib_BattleLibrary_Destruct(const BattleLibrary* p) { delete #define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \ export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); } -SIMPLE_GET_FUNC(BattleLibrary, GetStaticLib, const CreatureLib::Library::DataLibrary*); +SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetStaticLib, const CreatureLib::Library::DataLibrary*); SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetStatCalculator, const BattleStatCalculator*); SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetDamageLibrary, const DamageLibrary*); SIMPLE_GET_FUNC_SMART_PTR(BattleLibrary, GetMiscLibrary, const MiscLibrary*); diff --git a/src/Battling/Library/BattleLibrary.cpp b/src/Battling/Library/BattleLibrary.cpp index 4cdb9d7..4d0af15 100644 --- a/src/Battling/Library/BattleLibrary.cpp +++ b/src/Battling/Library/BattleLibrary.cpp @@ -15,8 +15,6 @@ BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* staticLib, AssertNotNull(_miscLibrary); } -BattleLibrary::~BattleLibrary() { delete _staticLib; } - const std::unique_ptr& BattleLibrary::GetSettings() const noexcept { return _staticLib->GetSettings(); } diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index b9802eb..86ad12b 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -11,7 +11,7 @@ namespace CreatureLib::Battling { class BattleLibrary { protected: - const Library::DataLibrary* _staticLib = nullptr; + std::unique_ptr _staticLib = nullptr; std::unique_ptr _statCalculator = nullptr; std::unique_ptr _damageLibrary = nullptr; std::unique_ptr _experienceLibrary = nullptr; @@ -22,8 +22,8 @@ namespace CreatureLib::Battling { BattleLibrary(const Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary, ScriptResolver* scriptResolver, MiscLibrary* miscLibrary); - ~BattleLibrary(); - inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; } + ~BattleLibrary() = default; + inline const std::unique_ptr& GetStaticLib() const noexcept { return _staticLib; } [[nodiscard]] const std::unique_ptr& GetSettings() const noexcept; [[nodiscard]] const std::unique_ptr& GetSpeciesLibrary() const noexcept;