A to_string method for enums

This commit is contained in:
Pcornat 2026-02-06 18:05:36 +01:00
commit db8b482f74
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
2 changed files with 11 additions and 0 deletions

View file

@ -49,6 +49,8 @@ namespace character {
static std::string_view billy_object_to_string(const billyObjects &object) noexcept; static std::string_view billy_object_to_string(const billyObjects &object) noexcept;
static std::string_view billy_object_to_string(const billyEnums &object) noexcept;
static void to_json(json &j, const container &billy); static void to_json(json &j, const container &billy);
static void from_json(const json &j, container &billy); static void from_json(const json &j, container &billy);

View file

@ -113,6 +113,15 @@ namespace character {
return object->to_string(); return object->to_string();
} }
std::string_view BillyObjects::billy_object_to_string(const billyEnums &object) noexcept {
return std::visit(overloaded{
[](const weapons &obj) { return Weapons{ obj }.to_string(); },
[](const equipments &obj) { return Equipments{ obj }.to_string(); },
[](const tools &obj) { return Tools{ obj }.to_string(); },
},
object);
}
void BillyObjects::from_json(const json &j, container &billy) { void BillyObjects::from_json(const json &j, container &billy) {
for (const auto &element: j) { for (const auto &element: j) {
const std::uint32_t key = element[0].get<std::uint32_t>(); const std::uint32_t key = element[0].get<std::uint32_t>();