diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-14 18:41:55 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-14 18:41:55 +0900 |
commit | c5f480355c7d4c000a4ee73fd7f8107a9a9340c2 (patch) | |
tree | d7a8f51e75230aa48cd243ef40b17ced70c0216b /jobs | |
parent | bb14969dfa5e9e8a26a005a7f804f21a62460f68 (diff) | |
download | libquotient-c5f480355c7d4c000a4ee73fd7f8107a9a9340c2.tar.gz libquotient-c5f480355c7d4c000a4ee73fd7f8107a9a9340c2.zip |
Move all internal event pointers to std::unique_ptr<>
This causes the following changes along the way:
- Owning<> template is decommissioned.
- event.h has been rearranged, and Event/RoomEvent::fromJson static methods have been replaced with an external makeEvent<> function template. A side effect of that is that one cannot use a factory with a type other than the one it's defined for (i.e. you cannot call makeEvent<TypingEvent>) but that feature has been out of use for long anyway.
- Room::doAddNewMessageEvents() and Room::doAddHistoricalMessageEvents() have been removed, giving place to Room::onAddNewTimelineEvents() and Room::onAddHistoricalTimelineEvents(). The most important difference is that all code that must be executed now resides in addNewMessageEvents() (it moved from Room to Room::Private) and classes inheriting from Room are not obliged to call the overridden function from the overriding function (they can do it but those functions have empty bodies in Room). This was a long overdue change, and owning pointers simply mandated it. Room::onAddNewTimelineEvents/onAddHistoricalTimelineEvents should not do anything with the passed range in terms of ownership, it's just a way to allow the derived class to update his data in due course.
- Room::Private::dropDuplicateEvents() and Room::Private::insertEvents(), notably, have been updated to work with owning pointers. insertEvents() move()s pointers to the timeline, while dropDuplicateEvents uses remove_if instead of stable_partition and doesn't explicitly delete event objects.
Also, a bugfix: Event accidentally had not virtual destructor for quite a long time. According to the standard, deleting an object through a pointer to a base class without a virtual destructor leads to UB. So the fact that libqmatrixclient clients even worked all these months is mere coincidence and compiler authors good will :-D
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/roommessagesjob.cpp | 6 | ||||
-rw-r--r-- | jobs/roommessagesjob.h | 2 | ||||
-rw-r--r-- | jobs/syncjob.h | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp index 9af1b3a6..e5568f17 100644 --- a/jobs/roommessagesjob.cpp +++ b/jobs/roommessagesjob.cpp @@ -23,7 +23,7 @@ using namespace QMatrixClient; class RoomMessagesJob::Private { public: - Owning<RoomEvents> events; + RoomEvents events; QString end; }; @@ -46,9 +46,9 @@ RoomMessagesJob::~RoomMessagesJob() delete d; } -RoomEvents RoomMessagesJob::releaseEvents() +RoomEvents&& RoomMessagesJob::releaseEvents() { - return d->events.release(); + return move(d->events); } QString RoomMessagesJob::end() const diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h index 9680d52c..7b3fd9c9 100644 --- a/jobs/roommessagesjob.h +++ b/jobs/roommessagesjob.h @@ -34,7 +34,7 @@ namespace QMatrixClient FetchDirection dir = FetchDirection::Backward); virtual ~RoomMessagesJob(); - RoomEvents releaseEvents(); + RoomEvents&& releaseEvents(); QString end() const; protected: diff --git a/jobs/syncjob.h b/jobs/syncjob.h index 08bd773e..e9288486 100644 --- a/jobs/syncjob.h +++ b/jobs/syncjob.h @@ -30,7 +30,7 @@ namespace QMatrixClient { public: template <typename EventT> - class Batch : public Owning<EventsBatch<EventT>> + class Batch : public EventsBatch<EventT> { public: explicit Batch(QString k) : jsonKey(std::move(k)) { } |