Serialize and deserialize.
This commit is contained in:
parent
e762ab05c6
commit
7b6eca1067
6 changed files with 96 additions and 60 deletions
50
include/characteristic/characteristic.hpp
Normal file
50
include/characteristic/characteristic.hpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#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;
|
||||
|
||||
Characteristic(const std::uint32_t base, const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) :
|
||||
base(base), carac(carac), materiel(materiel), additional(additional) {}
|
||||
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
void to_json(json &j, const Characteristic &charac) {
|
||||
j.emplace("base", charac.get_base());
|
||||
j.emplace("carac", charac.get_carac());
|
||||
j.emplace("materiel", charac.get_materiel());
|
||||
j.emplace("additional", charac.get_additional());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //BILLYSHEET_CHARACTERISTIC_HPP
|
||||
Loading…
Add table
Add a link
Reference in a new issue