From 97acdeeb4249bf4b8660425d080de4499266895b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 8 Jul 2018 09:08:02 +0900 Subject: TimelineItem: get(); validating viewAs<>() Having get() allows to work with TimelineItem as a smart pointer. --- lib/room.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/room.h b/lib/room.h index 975e6caf..7216d625 100644 --- a/lib/room.h +++ b/lib/room.h @@ -54,8 +54,9 @@ namespace QMatrixClient } const RoomEvent* event() const { return rawPtr(evt); } + const RoomEvent* get() const { return event(); } template - const EventT* viewAs() const { return weakPtrCast(evt); } + const EventT* viewAs() const { return eventCast(evt); } const RoomEventPtr& operator->() const { return evt; } const RoomEvent& operator*() const { return *evt; } index_t index() const { return idx; } @@ -67,6 +68,14 @@ namespace QMatrixClient RoomEventPtr evt; index_t idx; }; + + template<> + inline const StateEventBase* TimelineItem::viewAs() const + { + return evt->isStateEvent() ? weakPtrCast(evt) + : nullptr; + } + inline QDebug& operator<<(QDebug& d, const TimelineItem& ti) { QDebugStateSaver dss(d); -- cgit v1.2.3