Make Item follow PIMPL idiom.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
1eb1b04019
commit
b006344d83
|
@ -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); }
|
||||
|
||||
}
|
|
@ -6,25 +6,22 @@
|
|||
|
||||
namespace CreatureLib::Library {
|
||||
class Item {
|
||||
protected:
|
||||
ArbUt::StringView _name;
|
||||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
private:
|
||||
struct impl;
|
||||
std::unique_ptr<impl> _impl;
|
||||
|
||||
public:
|
||||
inline Item(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) {}
|
||||
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept;
|
||||
virtual ~Item();
|
||||
|
||||
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; }
|
||||
const ArbUt::StringView& GetName() const noexcept;
|
||||
ItemCategory GetCategory() const noexcept;
|
||||
BattleItemCategory GetBattleCategory() const noexcept;
|
||||
int32_t GetPrice() const noexcept;
|
||||
|
||||
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
|
||||
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
|
||||
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept;
|
||||
bool HasFlag(uint32_t flag) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue