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 {
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue