mirror of
https://github.com/gelldur/EventBus.git
synced 2024-12-26 10:41:01 +08:00
Update cpp code for move and forward
This commit is contained in:
parent
8f6eb24549
commit
026889c86c
@ -32,17 +32,17 @@ public:
|
||||
EventBus& operator=(const EventBus&) = delete;
|
||||
|
||||
template <typename Event>
|
||||
constexpr void post(const Event& event)
|
||||
constexpr void post(Event&& event)
|
||||
{
|
||||
static_assert(Dexode::Internal::validateEvent<Event>(), "Invalid event");
|
||||
_base.template post<Event>(event);
|
||||
_base.template post<Event>(std::forward<Event>(event));
|
||||
}
|
||||
|
||||
template <typename Event>
|
||||
constexpr void postpone(const Event& event)
|
||||
constexpr void postpone(Event&& event)
|
||||
{
|
||||
static_assert(Dexode::Internal::validateEvent<Event>(), "Invalid event");
|
||||
_base.template postpone<Event>(event);
|
||||
_base.template postpone<Event>(std::forward<Event>(event));
|
||||
}
|
||||
|
||||
constexpr std::size_t processAll()
|
||||
@ -50,12 +50,12 @@ public:
|
||||
return processLimit(std::numeric_limits<std::size_t>::max());
|
||||
}
|
||||
|
||||
constexpr std::size_t processLimit(std::size_t maxCountOfEvents)
|
||||
constexpr std::size_t processLimit(const std::size_t maxCountOfEvents)
|
||||
{
|
||||
return _base.processLimit(maxCountOfEvents);
|
||||
}
|
||||
|
||||
constexpr std::size_t getPostponeEventCount() const
|
||||
[[nodiscard]] constexpr std::size_t getPostponeEventCount() const
|
||||
{
|
||||
return _base.getQueueEventCount();
|
||||
}
|
||||
|
@ -49,16 +49,17 @@ public:
|
||||
}
|
||||
|
||||
template <typename Event>
|
||||
void postpone(const Event& event)
|
||||
void postpone(Event&& event)
|
||||
{
|
||||
{
|
||||
std::unique_lock writeLock{_mutex};
|
||||
_eventQueue.push_back([this, event]() { post<Event>(event); });
|
||||
_eventQueue.push_back(
|
||||
[this, event = std::forward<Event>(event)]() { post<Event>(event); });
|
||||
}
|
||||
_eventWaiting.notify_one();
|
||||
}
|
||||
|
||||
std::size_t processLimit(const std::size_t maxCountOfEvents);
|
||||
std::size_t processLimit(std::size_t maxCountOfEvents);
|
||||
|
||||
std::size_t getPostponeEventCount() const
|
||||
{
|
||||
@ -83,10 +84,10 @@ public:
|
||||
}
|
||||
assert(dynamic_cast<Vector*>(eventListeners->second.get()));
|
||||
auto* vectorImpl = static_cast<Vector*>(eventListeners->second.get());
|
||||
vectorImpl->add(listenerID, callback);
|
||||
vectorImpl->add(listenerID, std::forward<std::function<void(const Event&)>>(callback));
|
||||
}
|
||||
|
||||
void unlistenAll(const std::uint32_t listenerID);
|
||||
void unlistenAll(std::uint32_t listenerID);
|
||||
|
||||
template <typename Event>
|
||||
void unlisten(const std::uint32_t listenerID)
|
||||
|
@ -46,9 +46,9 @@ public:
|
||||
}
|
||||
|
||||
template <typename Event>
|
||||
void postpone(const Event& event)
|
||||
void postpone(Event&& event)
|
||||
{
|
||||
_eventQueue.push_back([this, event]() { post<Event>(event); });
|
||||
_eventQueue.push_back([this, event = std::forward<Event>(event)]() { post<Event>(event); });
|
||||
}
|
||||
|
||||
std::size_t processLimit(const std::size_t maxCountOfEvents)
|
||||
@ -65,7 +65,7 @@ public:
|
||||
return processed;
|
||||
}
|
||||
|
||||
std::size_t getQueueEventCount() const noexcept
|
||||
[[nodiscard]] std::size_t getQueueEventCount() const noexcept
|
||||
{
|
||||
return _eventQueue.size();
|
||||
}
|
||||
@ -83,7 +83,7 @@ public:
|
||||
}
|
||||
assert(dynamic_cast<Vector*>(vector.get()));
|
||||
auto* vectorImpl = static_cast<Vector*>(vector.get());
|
||||
vectorImpl->add(listenerID, callback);
|
||||
vectorImpl->add(listenerID, std::forward<std::function<void(const Event&)>>(callback));
|
||||
}
|
||||
|
||||
void unlistenAll(const std::uint32_t listenerID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user