Update Perks to shared

Maybe we would like to share perks to achieve something between event buses
This commit is contained in:
Dawid Drozd 2020-03-28 19:45:26 +01:00
parent a58aa21934
commit 9cab181cab
2 changed files with 4 additions and 4 deletions

View File

@ -6,7 +6,7 @@
namespace dexode::eventbus::perk
{
PerkEventBus::RegisterHelper PerkEventBus::addPerk(std::unique_ptr<Perk> perk)
PerkEventBus::RegisterHelper PerkEventBus::addPerk(std::shared_ptr<Perk> perk)
{
auto* local = perk.get();
_perks.push_back(std::move(perk));

View File

@ -46,13 +46,13 @@ public:
{}
};
RegisterHelper addPerk(std::unique_ptr<Perk> perk);
RegisterHelper addPerk(std::shared_ptr<Perk> perk);
template <typename T>
T* getPerk()
{
auto found =
std::find_if(_perks.begin(), _perks.end(), [](const std::unique_ptr<Perk>& perk) {
std::find_if(_perks.begin(), _perks.end(), [](const std::shared_ptr<Perk>& perk) {
return dynamic_cast<T*>(perk.get()) != nullptr;
});
if(found != _perks.end())
@ -66,7 +66,7 @@ protected:
bool postponeEvent(PostponeHelper& postponeCall) override;
private:
std::vector<std::unique_ptr<Perk>> _perks;
std::vector<std::shared_ptr<Perk>> _perks;
std::vector<std::function<perk::Flag(PostponeHelper&)>> _onPrePostpone;
std::vector<std::function<perk::Flag(PostponeHelper&)>> _onPostPostpone;
};