diff --git a/include/generic_object.hpp b/include/generic_object.hpp index 0d2e45d..298985e 100644 --- a/include/generic_object.hpp +++ b/include/generic_object.hpp @@ -47,8 +47,11 @@ namespace character { class Tools; + using billyObjects = std::variant; using billyEnums = std::variant; + static billyObjects new_object(const billyEnums &inputObject); + class GenericObject { public: virtual ~GenericObject() = default; @@ -59,22 +62,16 @@ namespace character { [[nodiscard]] virtual std::uint32_t add_damage() const noexcept = 0; - [[nodiscard]] virtual std::int32_t add_materiel(const characteristic::characType inType) const noexcept = 0; + [[nodiscard]] virtual std::uint32_t add_materiel(const characteristic::characType inType) const noexcept = 0; [[nodiscard]] virtual std::string_view to_string() const noexcept = 0; - - [[nodiscard]] virtual billyEnums get_type() const noexcept = 0; }; - 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; + friend billyObjects new_object(const billyEnums &inputObject); Weapons() = delete; @@ -86,11 +83,9 @@ namespace character { [[nodiscard]] std::uint32_t add_damage() const noexcept final; - [[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final; + [[nodiscard]] std::uint32_t add_materiel(const characteristic::characType inType) const noexcept final; - [[nodiscard]] std::string_view to_string() const noexcept final; - - [[nodiscard]] billyEnums get_type() const noexcept final { return type; } + [[nodiscard]] std::string_view to_string() const noexcept override; private: explicit Weapons(const weapons type) : type(type) {} @@ -100,7 +95,7 @@ namespace character { public: const equipments type{ equipments::Chainmail }; - friend billyObjects new_object(const billyEnums &inputObject) noexcept; + friend billyObjects new_object(const billyEnums &inputObject); Equipments() = delete; @@ -112,11 +107,9 @@ namespace character { [[nodiscard]] std::uint32_t add_damage() const noexcept final; - [[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final; + [[nodiscard]] std::uint32_t add_materiel(const characteristic::characType inType) const noexcept final; - [[nodiscard]] std::string_view to_string() const noexcept final; - - [[nodiscard]] billyEnums get_type() const noexcept final { return type; } + [[nodiscard]] std::string_view to_string() const noexcept override; private: explicit Equipments(const equipments type) : type(type) {} @@ -126,7 +119,7 @@ namespace character { public: const tools type{ tools::Fourche }; - friend billyObjects new_object(const billyEnums &inputObject) noexcept; + friend billyObjects new_object(const billyEnums &inputObject); Tools() = delete; @@ -138,11 +131,9 @@ namespace character { [[nodiscard]] std::uint32_t add_damage() const noexcept final; - [[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final; + [[nodiscard]] std::uint32_t add_materiel(const characteristic::characType inType) const noexcept final; - [[nodiscard]] std::string_view to_string() const noexcept final; - - [[nodiscard]] billyEnums get_type() const noexcept final { return type; } + [[nodiscard]] std::string_view to_string() const noexcept override; private: explicit Tools(const tools type) : type(type) {} diff --git a/src/generic_object.cpp b/src/generic_object.cpp index c83cccb..7d21f4b 100644 --- a/src/generic_object.cpp +++ b/src/generic_object.cpp @@ -30,7 +30,7 @@ namespace character { std::uint32_t Weapons::add_damage() const noexcept { return type == weapons::Morgenstern ? 1 : 0; } - std::int32_t Weapons::add_materiel(const characteristic::characType inType) const noexcept { + std::uint32_t Weapons::add_materiel(const characteristic::characType inType) const noexcept { switch (type) { case weapons::Sword: if (inType == characType::Habilete) { @@ -93,14 +93,12 @@ namespace character { std::uint32_t Equipments::add_damage() const noexcept { return 0; } - std::int32_t Equipments::add_materiel(const characteristic::characType inType) const noexcept { + std::uint32_t Equipments::add_materiel(const characteristic::characType inType) const noexcept { switch (type) { case equipments::Chainmail: - if (inType == characType::Habilete || - inType == characType::Adresse) { - return -1; - } - return inType == characType::Endurance ? 1 : 0; + return inType == characType::Habilete || + inType == characType::Adresse || + inType == characType::Endurance ? 1 : 0; case equipments::CookingPot: return inType == characType::Endurance ? 2 : 0; case equipments::PamphletTourist: @@ -129,7 +127,7 @@ namespace character { std::uint32_t Tools::add_damage() const noexcept { return 0; } - std::int32_t Tools::add_materiel(const characteristic::characType inType) const noexcept { + std::uint32_t Tools::add_materiel(const characteristic::characType inType) const noexcept { switch (type) { case tools::Fourche: switch (inType) { @@ -162,11 +160,11 @@ namespace character { } } - billyObjects new_object(const billyEnums &inputObject) noexcept { + billyObjects new_object(const billyEnums &inputObject) { 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 }}; } + [](const weapons input) { return billyObjects{ Weapons{ input }}; }, + [](const equipments input) { return billyObjects{ Equipments{ input }}; }, + [](const tools input) { return billyObjects{ Tools{ input }}; } }, inputObject); } }