Make DataLibrary use unique_ptr.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-24 19:01:47 +02:00
parent c056ddc6b3
commit b17c0648ff
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 30 additions and 60 deletions

View File

@ -11,7 +11,7 @@ export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, Librar
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);

View File

@ -24,25 +24,25 @@ BattleLibrary::~BattleLibrary() {
delete _miscLibrary;
}
const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const noexcept {
const std::unique_ptr<CreatureLib::Library::LibrarySettings>& BattleLibrary::GetSettings() const noexcept {
return _staticLib->GetSettings();
}
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const noexcept { return _statCalculator; }
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const noexcept {
const std::unique_ptr<CreatureLib::Library::SpeciesLibrary>& BattleLibrary::GetSpeciesLibrary() const noexcept {
return _staticLib->GetSpeciesLibrary();
}
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const noexcept {
const std::unique_ptr<CreatureLib::Library::ItemLibrary>& BattleLibrary::GetItemLibrary() const noexcept {
return _staticLib->GetItemLibrary();
}
const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const noexcept {
const std::unique_ptr<CreatureLib::Library::AttackLibrary>& BattleLibrary::GetAttackLibrary() const noexcept {
return _staticLib->GetAttackLibrary();
}
const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const noexcept {
const std::unique_ptr<CreatureLib::Library::TypeLibrary>& BattleLibrary::GetTypeLibrary() const noexcept {
return _staticLib->GetTypeLibrary();
}

View File

@ -25,12 +25,12 @@ namespace CreatureLib::Battling {
~BattleLibrary();
inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; }
[[nodiscard]] const Library::LibrarySettings* GetSettings() const noexcept;
[[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const noexcept;
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const noexcept;
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const noexcept;
[[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const noexcept;
[[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const noexcept {
[[nodiscard]] const std::unique_ptr<Library::LibrarySettings>& GetSettings() const noexcept;
[[nodiscard]] const std::unique_ptr<Library::SpeciesLibrary>& GetSpeciesLibrary() const noexcept;
[[nodiscard]] const std::unique_ptr<Library::ItemLibrary>& GetItemLibrary() const noexcept;
[[nodiscard]] const std::unique_ptr<Library::AttackLibrary>& GetAttackLibrary() const noexcept;
[[nodiscard]] const std::unique_ptr<Library::TypeLibrary>& GetTypeLibrary() const noexcept;
[[nodiscard]] const std::unique_ptr<Library::GrowthRateLibrary>& GetGrowthRateLibrary() const noexcept {
return _staticLib->GetGrowthRates();
}

View File

@ -14,27 +14,3 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu
AssertNotNull(_growthRates)
AssertNotNull(_typeLibrary)
}
const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const noexcept {
return _settings;
}
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const noexcept {
return _species;
}
const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const noexcept {
return _attacks;
}
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const noexcept {
return _items;
}
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const noexcept {
return _growthRates;
}
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const noexcept {
return _typeLibrary;
}

View File

@ -14,32 +14,26 @@ namespace CreatureLib::Library {
*/
class DataLibrary {
private:
const LibrarySettings* _settings;
const SpeciesLibrary* _species;
const AttackLibrary* _attacks;
const ItemLibrary* _items;
const GrowthRateLibrary* _growthRates;
const TypeLibrary* _typeLibrary;
const std::unique_ptr<LibrarySettings> _settings;
const std::unique_ptr<SpeciesLibrary> _species;
const std::unique_ptr<AttackLibrary> _attacks;
const std::unique_ptr<ItemLibrary> _items;
const std::unique_ptr<GrowthRateLibrary> _growthRates;
const std::unique_ptr<TypeLibrary> _typeLibrary;
public:
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
virtual ~DataLibrary() {
delete _species;
delete _attacks;
delete _items;
delete _growthRates;
delete _typeLibrary;
}
virtual ~DataLibrary() {}
[[nodiscard]] const LibrarySettings* GetSettings() const noexcept;
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const noexcept;
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const noexcept;
[[nodiscard]] const ItemLibrary* GetItemLibrary() const noexcept;
[[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const noexcept;
[[nodiscard]] const TypeLibrary* GetTypeLibrary() const noexcept;
[[nodiscard]] const std::unique_ptr<LibrarySettings>& GetSettings() const noexcept { return _settings; }
[[nodiscard]] const std::unique_ptr<SpeciesLibrary>& GetSpeciesLibrary() const noexcept { return _species; }
[[nodiscard]] const std::unique_ptr<AttackLibrary>& GetAttackLibrary() const noexcept { return _attacks; }
[[nodiscard]] const std::unique_ptr<ItemLibrary>& GetItemLibrary() const noexcept { return _items; }
[[nodiscard]] const std::unique_ptr<GrowthRateLibrary>& GetGrowthRates() const noexcept { return _growthRates; }
[[nodiscard]] const std::unique_ptr<TypeLibrary>& GetTypeLibrary() const noexcept { return _typeLibrary; }
};
}

View File

@ -30,7 +30,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
}
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -52,7 +52,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
}
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -74,7 +74,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
}
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -96,7 +96,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
}
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));