From 5a14994645e14390a797aa0b250f70a8372ec7f4 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 6 Feb 2026 18:05:23 +0100 Subject: [PATCH 1/2] Adding noexcept for constructors of billyObjects --- include/generic_object.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/generic_object.hpp b/include/generic_object.hpp index 72c0353..da3422c 100644 --- a/include/generic_object.hpp +++ b/include/generic_object.hpp @@ -78,7 +78,7 @@ namespace character { public: const weapons type{ weapons::Sword }; - explicit Weapons(const weapons type) : type(type) {} + explicit Weapons(const weapons type) noexcept : type(type) {} Weapons() = delete; @@ -101,7 +101,7 @@ namespace character { public: const equipments type{ equipments::Chainmail }; - explicit Equipments(const equipments type) : type(type) {} + explicit Equipments(const equipments type) noexcept : type(type) {} Equipments() = delete; @@ -124,7 +124,7 @@ namespace character { public: const tools type{ tools::Fourche }; - explicit Tools(const tools type) : type(type) {} + explicit Tools(const tools type) noexcept : type(type) {} Tools() = delete; @@ -144,4 +144,4 @@ namespace character { }; } // character -#endif //BILLYSHEET_GENERIC_OBJECT_HPP \ No newline at end of file +#endif //BILLYSHEET_GENERIC_OBJECT_HPP From db8b482f74de52cf8cd191a38d85e7e7cc5e7500 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 6 Feb 2026 18:05:36 +0100 Subject: [PATCH 2/2] A to_string method for enums --- include/billy_objects.hpp | 2 ++ src/billy_objects.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index 46152e9..d03879a 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -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 billyEnums &object) noexcept; + static void to_json(json &j, const container &billy); static void from_json(const json &j, container &billy); diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 52cf96d..7fd747c 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -113,6 +113,15 @@ namespace character { 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) { for (const auto &element: j) { const std::uint32_t key = element[0].get();