Make Item follow PIMPL idiom.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-09-30 20:32:41 +02:00
parent 1eb1b04019
commit b006344d83
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 48 additions and 15 deletions

View File

@ -0,0 +1,36 @@
#include "Item.hpp"
namespace CreatureLib::Library {
struct Item::impl {
ArbUt::StringView _name;
ItemCategory _category;
BattleItemCategory _battleCategory;
int32_t _price;
std::unordered_set<uint32_t> _flags;
public:
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const std::unordered_set<uint32_t>& flags) noexcept
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline int32_t GetPrice() const noexcept { return _price; }
inline bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
inline bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
};
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags) noexcept
: _impl(new impl(name, category, battleCategory, price, flags)) {}
Item::~Item() = default;
const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); }
ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); }
BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); }
int32_t Item::GetPrice() const noexcept { return _impl->GetPrice(); }
bool Item::HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return _impl->HasFlag(flag); }
bool Item::HasFlag(uint32_t flag) const noexcept { return _impl->HasFlag(flag); }
}

View File

@ -6,25 +6,22 @@
namespace CreatureLib::Library { namespace CreatureLib::Library {
class Item { class Item {
protected: private:
ArbUt::StringView _name; struct impl;
ItemCategory _category; std::unique_ptr<impl> _impl;
BattleItemCategory _battleCategory;
int32_t _price;
std::unordered_set<uint32_t> _flags;
public: public:
inline Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
int32_t price, const std::unordered_set<uint32_t>& flags) noexcept const std::unordered_set<uint32_t>& flags) noexcept;
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {} virtual ~Item();
inline const ArbUt::StringView& GetName() const noexcept { return _name; } const ArbUt::StringView& GetName() const noexcept;
inline ItemCategory GetCategory() const noexcept { return _category; } ItemCategory GetCategory() const noexcept;
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; } BattleItemCategory GetBattleCategory() const noexcept;
inline int32_t GetPrice() const noexcept { return _price; } int32_t GetPrice() const noexcept;
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); } bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept;
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); } bool HasFlag(uint32_t flag) const noexcept;
}; };
} }