BillySheet/include/characteristic/characteristic.hpp

61 lines
1.7 KiB
C++
Raw Normal View History

2022-01-14 22:58:16 +01:00
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
#define BILLYSHEET_CHARACTERISTIC_HPP
#include <cstdint>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace character::characteristic {
class Characteristic {
protected:
const std::uint32_t base{ 0 };
std::uint32_t carac{ 0 };
std::uint32_t materiel{ 0 };
std::uint32_t additional{ 0 };
public:
Characteristic() noexcept = default;
2022-01-20 23:16:51 +01:00
Characteristic(const std::uint32_t base, const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept:
2022-01-14 22:58:16 +01:00
base(base), carac(carac), materiel(materiel), additional(additional) {}
2022-01-20 23:16:51 +01:00
Characteristic(const Characteristic &charac) noexcept = default;
Characteristic &operator=(const Characteristic &charac) noexcept {
const_cast<std::uint32_t &>(base) = charac.base;
carac = charac.carac;
materiel = charac.materiel;
additional = charac.additional;
return *this;
}
2022-01-14 22:58:16 +01:00
virtual ~Characteristic() noexcept = default;
[[nodiscard]] std::uint32_t get_base() const { return base; }
[[nodiscard]] std::uint32_t get_carac() const { return carac; }
[[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
[[nodiscard]] std::uint32_t get_additional() const { return additional; }
friend void from_json(const json &j, Characteristic &charac) {
const_cast<std::uint32_t &>(charac.base) = j.at("base");
charac.carac = j.at("carac");
charac.materiel = j.at("materiel");
charac.additional = j.at("additional");
}
};
2022-01-17 19:57:00 +01:00
static void to_json(json &j, const Characteristic &charac) {
2022-01-14 23:03:22 +01:00
j["base"] = charac.get_base();
j["carac"] = charac.get_carac();
j["materiel"] = charac.get_materiel();
j["additional"] = charac.get_additional();
2022-01-14 22:58:16 +01:00
}
}
#endif //BILLYSHEET_CHARACTERISTIC_HPP