Using svector

This commit is contained in:
Pcornat 2024-02-29 12:23:30 +01:00
parent e6bec5c0f2
commit a164593cd8
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
2 changed files with 8 additions and 11 deletions

View File

@ -10,6 +10,7 @@
#include <functional> #include <functional>
#include <variant> #include <variant>
#include <string_view> #include <string_view>
#include <ankerl/svector.h>
#include "characteristic/characteristic.hpp" #include "characteristic/characteristic.hpp"
// helper type for the visitor // helper type for the visitor
@ -45,7 +46,7 @@ namespace character {
class BillyObjects final { class BillyObjects final {
public: public:
using billyObject = std::variant<weapons, equipments, tools>; using billyObject = std::variant<weapons, equipments, tools>;
using container = std::array<billyObject, 3>; using container = ankerl::svector<billyObject, 3>;
static constexpr std::string_view sword{ "Sword" }; static constexpr std::string_view sword{ "Sword" };
static constexpr std::string_view lance{ "Lance" }; static constexpr std::string_view lance{ "Lance" };
@ -68,9 +69,7 @@ namespace character {
void pop_object(CharacterSheet &sheet) noexcept; void pop_object(CharacterSheet &sheet) noexcept;
[[nodiscard]] std::pair<const container &, std::int8_t> get_objects() const noexcept { [[nodiscard]] const container &get_objects() const noexcept { return objects; }
return { objects, end_object };
}
// void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; // void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept;
@ -78,7 +77,6 @@ namespace character {
container objects; container objects;
std::plus<std::uint32_t> plus; std::plus<std::uint32_t> plus;
std::minus<std::uint32_t> minus; std::minus<std::uint32_t> minus;
std::uint8_t end_object{ 0 };
static void change_carac_weapon(const weapons &arg, static void change_carac_weapon(const weapons &arg,
CharacterSheet &sheet, CharacterSheet &sheet,

View File

@ -9,9 +9,8 @@ namespace character {
using characteristic::Characteristic; using characteristic::Characteristic;
void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept { void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept {
if (end_object < 3) { if (objects.size() < 3) {
objects.at(end_object) = object; objects.emplace_back(object);
++end_object;
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete); auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse); auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
@ -49,9 +48,9 @@ namespace character {
} }
void BillyObjects::pop_object(CharacterSheet &sheet) noexcept { void BillyObjects::pop_object(CharacterSheet &sheet) noexcept {
if (end_object > 0) { if (!objects.empty()) {
const auto &obj = objects.at(end_object - 1); const billyObject obj = objects.back();
--end_object; objects.pop_back();
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete); auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse); auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);