From 9993a0ea50165fd70f75b68c329ea045fb51d7f4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 4 Nov 2018 16:07:53 +0900 Subject: Support dumping Events to QDebug --- lib/events/event.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index 5b33628f..76e77cf6 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -257,8 +257,18 @@ namespace QMatrixClient return fromJson(contentJson()[key]); } + friend QDebug operator<<(QDebug dbg, const Event& e) + { + QDebugStateSaver _dss { dbg }; + dbg.noquote().nospace() + << e.matrixType() << '(' << e.type() << "): "; + e.dumpTo(dbg); + return dbg; + } + virtual bool isStateEvent() const { return false; } virtual bool isCallEvent() const { return false; } + virtual void dumpTo(QDebug dbg) const; protected: QJsonObject& editJson() { return _json; } -- cgit v1.2.3 From 6ca6dde46b9c72fc8833bc6fb81614fb705424f2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 11 Nov 2018 15:24:13 +0900 Subject: Improvements in comments - registerEventType(): comment the cryptic _ variable - Room::postEvent: document the return value - Room::Private: upgrade comments to doc-comments - even though in Private, they still are helpful to show hints in IDEs. - General cleanup --- lib/events/event.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index 76e77cf6..c51afcc4 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -209,7 +209,7 @@ namespace QMatrixClient inline auto registerEventType() { static const auto _ = setupFactory(); - return _; + return _; // Only to facilitate usage in static initialisation } // === Event === -- cgit v1.2.3 From a23fa6df08008f4a3f7437efa8afe839a102dc8e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 6 Jan 2019 17:43:37 +0900 Subject: visit(): pass decayed event types to is() So that is<> could be specialised for some types. --- lib/events/event.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index c51afcc4..d7ac4292 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -208,6 +208,9 @@ namespace QMatrixClient template inline auto registerEventType() { + // Initialise exactly once, even if this function is called twice for + // the same type (for whatever reason - you never know the ways of + // static initialisation is done). static const auto _ = setupFactory(); return _; // Only to facilitate usage in static initialisation } @@ -337,7 +340,8 @@ namespace QMatrixClient -> decltype(static_cast(&*eptr)) { Q_ASSERT(eptr); - return is(*eptr) ? static_cast(&*eptr) : nullptr; + return is>(*eptr) + ? static_cast(&*eptr) : nullptr; } // A single generic catch-all visitor @@ -369,7 +373,7 @@ namespace QMatrixClient visit(const BaseEventT& event, FnT&& visitor) { using event_type = fn_arg_t; - if (is(event)) + if (is>(event)) visitor(static_cast(event)); } @@ -383,7 +387,7 @@ namespace QMatrixClient fn_return_t&& defaultValue = {}) { using event_type = fn_arg_t; - if (is(event)) + if (is>(event)) return visitor(static_cast(event)); return std::forward>(defaultValue); } @@ -396,7 +400,7 @@ namespace QMatrixClient FnTs&&... visitors) { using event_type1 = fn_arg_t; - if (is(event)) + if (is>(event)) return visitor1(static_cast(event)); return visit(event, std::forward(visitor2), std::forward(visitors)...); -- cgit v1.2.3 From e3d2edbea279da8c3ed19b9faa77a287b6a65faf Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 18 May 2019 21:48:04 +0900 Subject: event.h: add doc-comments; deprecate ptrCast() --- lib/events/event.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/events/event.h') diff --git a/lib/events/event.h b/lib/events/event.h index d7ac4292..b7bbd83e 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -32,19 +32,23 @@ namespace QMatrixClient template using event_ptr_tt = std::unique_ptr; + /// Unwrap a plain pointer from a smart pointer template - inline EventT* rawPtr(const event_ptr_tt& ptr) // unwrap + inline EventT* rawPtr(const event_ptr_tt& ptr) { return ptr.get(); } + /// Unwrap a plain pointer and downcast it to the specified type template inline TargetEventT* weakPtrCast(const event_ptr_tt& ptr) { return static_cast(rawPtr(ptr)); } + /// Re-wrap a smart pointer to base into a smart pointer to derived template + [[deprecated("Consider using eventCast() or visit() instead")]] inline event_ptr_tt ptrCast(event_ptr_tt&& ptr) { return unique_ptr_cast(ptr); -- cgit v1.2.3