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 {
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;
};
}