Creating easily objects

This commit is contained in:
Pcornat 2024-10-30 16:43:07 +01:00
parent f7862f09f9
commit 0b2467475a
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
2 changed files with 3 additions and 22 deletions

View File

@ -68,13 +68,11 @@ namespace character {
using billyObjects = std::unique_ptr<GenericObject>;
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

View File

@ -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);
}
}