BillySheet/include/generic_object.hpp

154 lines
4.2 KiB
C++

//
// Created by postaron on 01/09/24.
//
#ifndef BILLYSHEET_GENERIC_OBJECT_HPP
#define BILLYSHEET_GENERIC_OBJECT_HPP
#include <cstdint>
#include <variant>
#include <string>
#include <string_view>
#include "characteristic/characteristic.hpp"
// helper type for the visitor
template<typename... Ts>
struct overloaded : Ts ... { using Ts::operator()...; };
template<typename... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
namespace character {
using namespace std::string_literals;
enum class weapons : std::uint8_t {
Sword = 0,
Lance = 1,
Morgenstern = 2,
Bow = 3
};
enum class equipments : std::uint8_t {
Chainmail = 4,
CookingPot = 5,
PamphletTourist = 6,
MedicKit = 7
};
enum class tools : std::uint8_t {
Fourche = 8,
Dagger = 9,
RockClimbingKit = 10,
SackOfGrain = 11
};
class Weapons;
class Equipments;
class Tools;
using billyEnums = std::variant<weapons, equipments, tools>;
class GenericObject {
public:
virtual ~GenericObject() = default;
[[nodiscard]] virtual std::uint32_t add_armor() const noexcept = 0;
[[nodiscard]] virtual std::uint32_t add_critique() const noexcept = 0;
[[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::string_view to_string() const noexcept = 0;
[[nodiscard]] virtual billyEnums get_type() const noexcept = 0;
};
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;
Weapons() = delete;
~Weapons() final = default;
[[nodiscard]] std::uint32_t add_armor() const noexcept final;
[[nodiscard]] std::uint32_t add_critique() const noexcept final;
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
[[nodiscard]] std::int32_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; }
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;
Equipments() = delete;
~Equipments() final = default;
[[nodiscard]] std::uint32_t add_armor() const noexcept final;
[[nodiscard]] std::uint32_t add_critique() const noexcept final;
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
[[nodiscard]] std::int32_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; }
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;
Tools() = delete;
~Tools() final = default;
[[nodiscard]] std::uint32_t add_armor() const noexcept final;
[[nodiscard]] std::uint32_t add_critique() const noexcept final;
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
[[nodiscard]] std::int32_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; }
private:
explicit Tools(const tools type) : type(type) {}
};
} // character
#endif //BILLYSHEET_GENERIC_OBJECT_HPP