From 0b2467475a306e4e2559c982ceb688a3c03668f8 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 16:43:07 +0100 Subject: [PATCH] Creating easily objects --- include/generic_object.hpp | 17 +++-------------- src/generic_object.cpp | 8 -------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/include/generic_object.hpp b/include/generic_object.hpp index 0d2e45d..3c5aa94 100644 --- a/include/generic_object.hpp +++ b/include/generic_object.hpp @@ -68,13 +68,11 @@ namespace character { using billyObjects = std::unique_ptr; - static billyObjects new_object(const billyEnums &inputObject) noexcept; - class Weapons final : virtual public GenericObject { public: const weapons type{ weapons::Sword }; - friend billyObjects new_object(const billyEnums &inputObject) noexcept; + explicit Weapons(const weapons type) : type(type) {} Weapons() = delete; @@ -91,16 +89,13 @@ namespace character { [[nodiscard]] std::string_view to_string() const noexcept final; [[nodiscard]] billyEnums get_type() const noexcept final { return type; } - - private: - explicit Weapons(const weapons type) : type(type) {} }; class Equipments final : virtual public GenericObject { public: const equipments type{ equipments::Chainmail }; - friend billyObjects new_object(const billyEnums &inputObject) noexcept; + explicit Equipments(const equipments type) : type(type) {} Equipments() = delete; @@ -117,16 +112,13 @@ namespace character { [[nodiscard]] std::string_view to_string() const noexcept final; [[nodiscard]] billyEnums get_type() const noexcept final { return type; } - - private: - explicit Equipments(const equipments type) : type(type) {} }; class Tools final : virtual public GenericObject { public: const tools type{ tools::Fourche }; - friend billyObjects new_object(const billyEnums &inputObject) noexcept; + explicit Tools(const tools type) : type(type) {} Tools() = delete; @@ -143,9 +135,6 @@ namespace character { [[nodiscard]] std::string_view to_string() const noexcept final; [[nodiscard]] billyEnums get_type() const noexcept final { return type; } - - private: - explicit Tools(const tools type) : type(type) {} }; } // character diff --git a/src/generic_object.cpp b/src/generic_object.cpp index a09f2c9..5bc6bc9 100644 --- a/src/generic_object.cpp +++ b/src/generic_object.cpp @@ -165,12 +165,4 @@ namespace character { return sackOfGrain; } } - - billyObjects new_object(const billyEnums &inputObject) noexcept { - return std::visit(overloaded{ - [](const weapons input) { return billyObjects{ new Weapons{ input }}; }, - [](const equipments input) { return billyObjects{ new Equipments{ input }}; }, - [](const tools input) { return billyObjects{ new Tools{ input }}; } - }, inputObject); - } }