aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/event.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/events/event.h b/lib/events/event.h
index 2a03f77a..a205b1b4 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -140,9 +140,10 @@ namespace QMatrixClient
{
public:
template <typename FnT>
- static void addMethod(FnT&& method)
+ static auto addMethod(FnT&& method)
{
factories().emplace_back(std::forward<FnT>(method));
+ return 0;
}
/** Chain two type factories
@@ -156,8 +157,7 @@ namespace QMatrixClient
template <typename EventT>
static auto chainFactory()
{
- addMethod(&EventT::factory_t::make);
- return 0;
+ return addMethod(&EventT::factory_t::make);
}
static event_ptr_tt<BaseEventT> make(const QJsonObject& json,
@@ -190,9 +190,10 @@ namespace QMatrixClient
* \sa loadEvent, Event::type
*/
template <typename EventT>
- inline void setupFactory()
+ inline auto setupFactory()
{
- EventT::factory_t::addMethod(
+ qDebug(EVENTS) << "Adding factory method for" << EventT::matrixTypeId();
+ return EventT::factory_t::addMethod(
[] (const QJsonObject& json, const QString& jsonMatrixType)
{
return EventT::matrixTypeId() == jsonMatrixType
@@ -200,6 +201,13 @@ namespace QMatrixClient
});
}
+ template <typename EventT>
+ inline auto registerEventType()
+ {
+ static const auto _ = setupFactory<EventT>();
+ return _;
+ }
+
// === Event ===
class Event
@@ -264,7 +272,7 @@ namespace QMatrixClient
#define REGISTER_EVENT_TYPE(_Type) \
namespace { \
[[gnu::unused]] \
- static const auto _factoryAdded##_Type = ( setupFactory<_Type>(), 0); \
+ static const auto _factoryAdded##_Type = registerEventType<_Type>(); \
} \
// End of macro