From b657cd22aa64f24f2e0f9f31ef8a5d4e38a26a3a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 17:06:20 +0900 Subject: Event and Room: further abstract event pointers So that eventual switch from std::unique_ptr to some other pointer (as a case - QSharedPointer) would be as painless as possible. --- lib/events/event.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/events/event.cpp') diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 31520fc9..193250de 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -67,16 +67,17 @@ const QJsonObject Event::contentJson() const } template -inline BaseEventT* makeIfMatches(const QJsonObject&, const QString&) +inline event_ptr_tt makeIfMatches(const QJsonObject&, const QString&) { return nullptr; } template -inline BaseEventT* makeIfMatches(const QJsonObject& o, const QString& selector) +inline event_ptr_tt makeIfMatches(const QJsonObject& o, + const QString& selector) { if (selector == EventT::TypeId) - return new EventT(o); + return _impl::create(o); return makeIfMatches(o, selector); } @@ -86,11 +87,11 @@ EventPtr _impl::doMakeEvent(const QJsonObject& obj) { // Check more specific event types first if (auto e = doMakeEvent(obj)) - return EventPtr(move(e)); + return e; - return EventPtr { makeIfMatches( - obj, obj["type"].toString()) }; + obj, obj["type"].toString()); } RoomEvent::RoomEvent(Event::Type type) : Event(type) { } @@ -118,8 +119,7 @@ RoomEvent::RoomEvent(Type type, const QJsonObject& rep) auto redaction = unsignedData.value("redacted_because"); if (redaction.isObject()) { - _redactedBecause = - std::make_unique(redaction.toObject()); + _redactedBecause = _impl::create(redaction.toObject()); return; } -- cgit v1.2.3