From ebd1cc2f0502435b133359139832ffc6b913f0e1 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 20:34:54 +0100 Subject: [PATCH 1/6] Add constexpr --- include/characteristic.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/characteristic.hpp b/include/characteristic.hpp index 65a208d..4affc87 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -29,7 +29,7 @@ namespace character::characteristic { std::uint32_t materiel{ 0 }; std::uint32_t additional{ 0 }; - static std::uint32_t get_base(const characType inType) noexcept { + static constexpr std::uint32_t get_base(const characType inType) noexcept { switch (inType) { case characType::Adresse: return 1; @@ -44,21 +44,21 @@ namespace character::characteristic { public: const characType type{ characType::Adresse }; - Characteristic() noexcept = default; + constexpr Characteristic() noexcept = default; - Characteristic(const characType inType, - const std::uint32_t carac, - const std::uint32_t materiel, - const std::uint32_t additional) : + constexpr Characteristic(const characType inType, + const std::uint32_t carac, + const std::uint32_t materiel, + const std::uint32_t additional) : base(get_base(inType)), carac(carac), materiel(materiel), additional(additional), type(inType) { (void) get_total(); } - explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {} + constexpr explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {} - Characteristic(const Characteristic &charac) noexcept = default; + constexpr Characteristic(const Characteristic &charac) noexcept = default; Characteristic &operator=(const Characteristic &charac) noexcept { const_cast(base) = charac.base; From 3c68557549ae9191e5d93a9b79804b07cb006db3 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 20:35:34 +0100 Subject: [PATCH 2/6] Remove useless namespace --- include/characteristic.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/characteristic.hpp b/include/characteristic.hpp index 4affc87..a453040 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -21,7 +21,7 @@ namespace character::characteristic { class Characteristic { protected: - friend character::BillyObjects; + friend BillyObjects; using defaultValue = std::numeric_limits; mutable std::int32_t total{ defaultValue::max() }; const std::uint32_t base{ 0 }; From ea1206e58cd3445e6170eec4b4895edb33e104ca Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 20:35:51 +0100 Subject: [PATCH 3/6] Add documentation --- include/characteristic.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/characteristic.hpp b/include/characteristic.hpp index a453040..3a144db 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -12,6 +12,10 @@ namespace character { } namespace character::characteristic { + + /*! + * \brief Different characteristic type + */ enum class characType : std::uint8_t { Adresse = 0, Endurance = 1, @@ -19,16 +23,34 @@ namespace character::characteristic { Habilete = 3 }; + /*! + * \brief This class represents a characteristic for Billy (one of characType) + */ class Characteristic { protected: friend BillyObjects; using defaultValue = std::numeric_limits; + + //! Total point for this charac mutable std::int32_t total{ defaultValue::max() }; + + //! Base value const std::uint32_t base{ 0 }; + + //! Value depending of the characType for this characteristic. std::uint32_t carac{ 0 }; + + //! Value changed from a billyObjects (billyEnums) possessed std::uint32_t materiel{ 0 }; + + //! Additional value when creating the character std::uint32_t additional{ 0 }; + /*! + * \brief Get base value depending of the characType + * \param inType Characteristic type used to get base number + * \return Base value depending of the characType + */ static constexpr std::uint32_t get_base(const characType inType) noexcept { switch (inType) { case characType::Adresse: From 66911014f08ce8c4e2c51b1f5558bc631d212efd Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 20:36:08 +0100 Subject: [PATCH 4/6] Add new line at the end of file --- include/characteristic.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/characteristic.hpp b/include/characteristic.hpp index 3a144db..f4d886d 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -131,4 +131,4 @@ namespace character::characteristic { } -#endif //BILLYSHEET_CHARACTERISTIC_HPP \ No newline at end of file +#endif //BILLYSHEET_CHARACTERISTIC_HPP From f06227f02ead31b72442d71acd48f1dabae8119c Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 22:10:11 +0100 Subject: [PATCH 5/6] Removing useless intermediate variables. --- include/billy_objects.hpp | 6 +----- src/billy_objects.cpp | 28 +++++++--------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index d03879a..58ec363 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -74,11 +74,7 @@ namespace character { static void change_carac(const billyObjects &arg, CharacterSheet &sheet, - characteristic::Characteristic &localHabilete, - characteristic::Characteristic &localAdresse, - characteristic::Characteristic &localEndurance, - characteristic::Characteristic &localChance, - const std::function &operation) noexcept; + const std::function &operation) noexcept; }; } diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 7fd747c..526ba41 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -40,18 +40,13 @@ namespace character { const auto &object = sheet.objects[objType]; sheet.available_objects.erase(objType); - auto &local_habilete = static_cast(sheet.habilete); - auto &local_adresse = static_cast(sheet.adresse); - auto &local_endurance = static_cast(sheet.endurance); - auto &local_chance = static_cast(sheet.chance); - std::visit(overloaded{ [&](const weapons &) { ++sheet.nb_weapons; }, [&](const equipments &) { ++sheet.nb_equipments; }, [&](const tools &) { ++sheet.nb_tools; }, }, objType); - change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus); + change_carac(object, sheet, plus); return true; } return false; @@ -63,18 +58,13 @@ namespace character { sheet.objects.erase(objToErase); sheet.available_objects.insert(objToErase); - auto &local_habilete = static_cast(sheet.habilete); - auto &local_adresse = static_cast(sheet.adresse); - auto &local_endurance = static_cast(sheet.endurance); - auto &local_chance = static_cast(sheet.chance); - std::visit(overloaded{ [&](const weapons &) { --sheet.nb_weapons; }, [&](const equipments &) { --sheet.nb_equipments; }, [&](const tools &) { --sheet.nb_tools; } }, objToErase); - change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus); + change_carac(obj, sheet, minus); return true; } return false; @@ -86,16 +76,12 @@ namespace character { void BillyObjects::change_carac(const billyObjects &arg, CharacterSheet &sheet, - Characteristic &localHabilete, - Characteristic &localAdresse, - Characteristic &localEndurance, - Characteristic &localChance, - const std::function &operation) + const std::function &operation) noexcept { - localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type)); - localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type)); - localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type)); - localChance.materiel = operation(localChance.materiel, arg->add_materiel(localChance.type)); + sheet.habilete.materiel = operation(sheet.habilete.materiel, arg->add_materiel(sheet.habilete.type)); + sheet.adresse.materiel = operation(sheet.adresse.materiel, arg->add_materiel(sheet.adresse.type)); + sheet.endurance.materiel = operation(sheet.endurance.materiel, arg->add_materiel(sheet.endurance.type)); + sheet.chance.materiel = operation(sheet.chance.materiel, arg->add_materiel(sheet.chance.type)); sheet.armor = operation(sheet.armor, arg->add_armor()); sheet.damage = operation(sheet.armor, arg->add_damage()); sheet.critique = operation(sheet.critique, arg->add_critique()); From 79d575da10adeadc8e71b2154205cce5dd3a8785 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 27 Feb 2026 22:10:35 +0100 Subject: [PATCH 6/6] Documentation --- include/billy_objects.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index 58ec363..f09b282 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -55,8 +55,22 @@ namespace character { static void from_json(const json &j, container &billy); + /*! + * \brief It inserts the object inside the sheet. + * + * This method changes values inside the sheet according to the book's rules. + * \param sheet sheet to insert object into + * \param objType the object to insert + * \return true: object inserted, false otherwise + */ [[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept; + /*! + * \brief + * \param sheet sheet to erase object from + * \param objToErase the object to erase + * \return true: object erased, false otherwise + */ [[nodiscard]] bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept; [[nodiscard]] static bool is_full(const CharacterSheet &sheet) noexcept; @@ -72,6 +86,12 @@ namespace character { std::minus minus; + /*! + * \brief + * \param arg object used to change values + * \param sheet sheet to change + * \param operation Operation to apply to change values + */ static void change_carac(const billyObjects &arg, CharacterSheet &sheet, const std::function &operation) noexcept;