aboutsummaryrefslogtreecommitdiff
path: root/lib/events/event.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events/event.h')
-rw-r--r--lib/events/event.h30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/events/event.h b/lib/events/event.h
index 4e2b1071..396406f1 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -26,8 +26,32 @@ namespace QMatrixClient
template <typename EventT>
using event_ptr_tt = std::unique_ptr<EventT>;
+ template <typename EventT>
+ inline EventT* rawPtr(const event_ptr_tt<EventT>& ptr)
+ {
+ return ptr.get();
+ }
+
+ template <typename TargetEventT, typename EventT>
+ inline TargetEventT* weakPtr(const event_ptr_tt<EventT>& ptr)
+ {
+ return static_cast<TargetEventT*>(rawPtr(ptr));
+ }
+
+ template <typename TargetT, typename SourceT>
+ inline event_ptr_tt<TargetT> ptrCast(event_ptr_tt<SourceT>&& ptr)
+ {
+ return unique_ptr_cast<TargetT>(ptr);
+ }
+
namespace _impl
{
+ template <typename EventT, typename... ArgTs>
+ inline event_ptr_tt<EventT> create(ArgTs&&... args)
+ {
+ return std::make_unique<EventT>(std::forward<ArgTs>(args)...);
+ }
+
template <typename EventT>
event_ptr_tt<EventT> doMakeEvent(const QJsonObject& obj);
}
@@ -94,7 +118,7 @@ namespace QMatrixClient
{
auto e = _impl::doMakeEvent<EventT>(obj);
if (!e)
- e = std::make_unique<EventT>(EventType::Unknown, obj);
+ e = _impl::create<EventT>(EventType::Unknown, obj);
return e;
}
@@ -174,9 +198,9 @@ namespace QMatrixClient
QString roomId() const;
QString senderId() const;
bool isRedacted() const { return bool(_redactedBecause); }
- const RedactionEvent* redactedBecause() const
+ const event_ptr_tt<RedactionEvent>& redactedBecause() const
{
- return _redactedBecause.get();
+ return _redactedBecause;
}
QString redactionReason() const;
const QString& transactionId() const { return _txnId; }