aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common/Event2.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-01-01 22:20:21 +0800
committercrupest <crupest@outlook.com>2024-01-18 21:12:28 +0800
commitdf799bf394fa63dc9f39a5b09fe21c16b1cc8a57 (patch)
treec9efa5b7a53545e2e1b7a9dff765817208911a7a /include/cru/common/Event2.h
parentf79fc16b29a32c21461490a6482eada7baa9d7f8 (diff)
downloadcru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.tar.gz
cru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.tar.bz2
cru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.zip
NEED TEST: fix compile errors of Event2 and create init test.
Diffstat (limited to 'include/cru/common/Event2.h')
-rw-r--r--include/cru/common/Event2.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/include/cru/common/Event2.h b/include/cru/common/Event2.h
index 5c3a330a..7d7bda82 100644
--- a/include/cru/common/Event2.h
+++ b/include/cru/common/Event2.h
@@ -51,7 +51,8 @@ class EventHandlerToken {
static_assert(is_event2_v<TEvent2>, "TEvent2 must be Event2 class.");
public:
- EventHandlerToken(ObjectResolver<TEvent2> event_resolver, int token_value);
+ EventHandlerToken(ObjectResolver<TEvent2> event_resolver, int token_value)
+ : event_resolver_(std::move(event_resolver)), token_value_(token_value) {}
ObjectResolver<TEvent2> GetEventResolver() const { return event_resolver_; }
int GetTokenValue() const { return token_value_; }
@@ -82,17 +83,17 @@ class Event2 : public SelfResolvable<Event2<TArgument, TResult>> {
public:
using HandlerToken = EventHandlerToken<Event2>;
using Context = EventContext<TArgument, TResult>;
- using Handler = std::function<void(Context&)>;
+ using Handler = std::function<void(Context*)>;
using SpyOnlyHandler = std::function<void()>;
template <typename TFunc>
static std::enable_if_t<std::invocable<TFunc>, Handler> WrapAsHandler(
TFunc&& handler) {
- return Handler([h = std::forward<TFunc>(handler)](Context&) { h(); });
+ return Handler([h = std::forward<TFunc>(handler)](Context*) { h(); });
}
template <typename TFunc>
- static std::enable_if_t<std::invocable<TFunc, Context&>, Handler>
+ static std::enable_if_t<std::invocable<TFunc, Context*>, Handler>
WrapAsHandler(TFunc&& handler) {
return Handler(std::forward<TFunc>(handler));
}
@@ -138,19 +139,19 @@ class Event2 : public SelfResolvable<Event2<TArgument, TResult>> {
TResult Raise() {
Context context;
- RunInContext(context);
+ RunInContext(&context);
return context.TakeResult();
}
TResult Raise(TArgument argument) {
Context context(std::move(argument));
- RunInContext(context);
+ RunInContext(&context);
return context.TakeResult();
}
TResult Raise(TArgument argument, TResult result) {
Context context(std::move(argument), std::move(result));
- RunInContext(context);
+ RunInContext(&context);
return context.TakeResult();
}