From 8e9e89846f75cae907bb9c2c6868dcb0f37896ae Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 20 Nov 2018 13:25:07 +0900 Subject: eventloader.h: drop unneeded #include --- lib/events/eventloader.h | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 3ee9a181..cd2f9149 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -19,7 +19,6 @@ #pragma once #include "stateevent.h" -#include "converters.h" namespace QMatrixClient { namespace _impl { -- cgit v1.2.3 From 3392e66fd015e191b01f6e3fc6839edc3948e31f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 8 Dec 2018 15:36:04 +0900 Subject: Refactor toJson/fillJson Both now use through a common JsonConverter<> template class with its base definition tuned for structs/QJsonObjects and specialisations for non-object types. This new implementation doesn't work with virtual fillJson functions yet (so EventContent classes still use toJson as a member function) and does not cope quite well with non-constructible objects (you have to specialise JsonConverter<> rather than, more intuitively, JsonObjectConverter<>), but overall is more streamlined compared to the previous implementation. It also fixes one important issue that pushed for a rewrite: the previous implementation was not working with structure hierarchies at all so (in particular) the Filter part of CS API was totally disfunctional. --- lib/events/eventloader.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index cd2f9149..da663392 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -57,11 +57,15 @@ namespace QMatrixClient { matrixType); } - template struct FromJsonObject> + template struct JsonConverter> { - auto operator()(const QJsonObject& jo) const + static auto load(const QJsonValue& jv) { - return loadEvent(jo); + return loadEvent(jv.toObject()); + } + static auto load(const QJsonDocument& jd) + { + return loadEvent(jd.object()); } }; } // namespace QMatrixClient -- cgit v1.2.3 From aacc4bcb4a487871daae6717f77605aaba444341 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:26:57 +0100 Subject: style: apply .clang-format to all .cpp and .h files --- lib/events/eventloader.h | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index da663392..a19a83b6 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -1,20 +1,20 @@ /****************************************************************************** -* Copyright (C) 2018 Kitsune Ral -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * Copyright (C) 2018 Kitsune Ral + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #pragma once @@ -57,8 +57,7 @@ namespace QMatrixClient { matrixType); } - template struct JsonConverter> - { + template struct JsonConverter> { static auto load(const QJsonValue& jv) { return loadEvent(jv.toObject()); -- cgit v1.2.3 From cbb4f219d5c79f81706019c0679222d5ccee4a4c Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 6 Jul 2019 19:59:34 +0900 Subject: loadStateEvent() --- lib/events/eventloader.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index da663392..d0fa60a2 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -32,7 +32,8 @@ namespace QMatrixClient { } } - /** Create an event with proper type from a JSON object + /*! Create an event with proper type from a JSON object + * * Use this factory template to detect the type from the JSON object * contents (the detected event type should derive from the template * parameter type) and create an event object of that type. @@ -44,7 +45,8 @@ namespace QMatrixClient { fullJson[TypeKeyL].toString()); } - /** Create an event from a type string and content JSON + /*! Create an event from a type string and content JSON + * * Use this factory template to resolve the C++ type from the Matrix * type string in \p matrixType and create an event of that type that has * its content part set to \p content. @@ -57,6 +59,20 @@ namespace QMatrixClient { matrixType); } + /*! Create a state event from a type string, content JSON and state key + * + * Use this factory to resolve the C++ type from the Matrix type string + * in \p matrixType and create a state event of that type with content part + * set to \p content and state key set to \p stateKey (empty by default). + */ + inline StateEventPtr loadStateEvent(const QString& matrixType, + const QJsonObject& content, + const QString& stateKey = {}) + { + return _impl::loadEvent( + basicStateEventJson(matrixType, content, stateKey), matrixType); + } + template struct JsonConverter> { static auto load(const QJsonValue& jv) -- cgit v1.2.3 From c05ade838f0fce81f2bbe80a3295618a8a26ff52 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 19:59:40 +0900 Subject: Apply the new brace wrapping to source files --- lib/events/eventloader.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index a203eaa3..9e8bb410 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -20,10 +20,8 @@ #include "stateevent.h" -namespace QMatrixClient -{ -namespace _impl -{ +namespace QMatrixClient { +namespace _impl { template static inline auto loadEvent(const QJsonObject& json, const QString& matrixType) @@ -75,8 +73,7 @@ inline StateEventPtr loadStateEvent(const QString& matrixType, } template -struct JsonConverter> -{ +struct JsonConverter> { static auto load(const QJsonValue& jv) { return loadEvent(jv.toObject()); -- cgit v1.2.3 From 27ca32a1e5a56e09b9cc1d94224d2831004dcf3d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jul 2019 19:32:34 +0900 Subject: Namespace: QMatrixClient -> Quotient (with back comp alias) --- lib/events/eventloader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 9e8bb410..ebb96441 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -20,7 +20,7 @@ #include "stateevent.h" -namespace QMatrixClient { +namespace Quotient { namespace _impl { template static inline auto loadEvent(const QJsonObject& json, @@ -83,4 +83,4 @@ struct JsonConverter> { return loadEvent(jd.object()); } }; -} // namespace QMatrixClient +} // namespace Quotient -- cgit v1.2.3 From cd9c9296bb1ac7af7ebbbf66931e731dbf581bc8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 26 Dec 2020 14:54:31 +0100 Subject: Port existing copyright statement to reuse using licensedigger --- lib/events/eventloader.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index ebb96441..0d95daf5 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -1,19 +1,7 @@ /****************************************************************************** - * Copyright (C) 2018 Kitsune Ral + * SPDX-FileCopyrightText: 2018 Kitsune Ral * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -- cgit v1.2.3 From 0a775d9b3209be15dea8b8915fc0a1c8e0046ba6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 16 Jan 2021 18:19:45 +0100 Subject: Updated copyright statements upon Git audit After going through all the files and the history of commits on them it was clear that some copyright statements are obsolete (the code has been overwritten since) and some are missing. This commit tries best to remedy that, along with adding SPDX tags where they were still not used. Also, a minimal SPDX convention is documented for further contributions. Closes #426. --- lib/events/eventloader.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 0d95daf5..978668f2 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -1,8 +1,5 @@ -/****************************************************************************** - * SPDX-FileCopyrightText: 2018 Kitsune Ral - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ +// SPDX-FileCopyrightText: 2018 Kitsune Ral +// SPDX-License-Identifier: LGPL-2.1-or-later #pragma once -- cgit v1.2.3 From 231c4d723eb53f3ea5f641b743d198584840a963 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 22 Dec 2021 13:44:39 +0100 Subject: Simplify the code around EventFactory<> The former code assumed that EventFactory<> is just a class-level shell for a bunch of functions and a static data member that only exists to allow specialisations to occur for the whole group together. On top of that, setupFactory() and registerEventType() strived to protect this group from double registration coming from static variables in an anonymous namespace produced by REGISTER_EVENT_TYPE. The whole thing is now de-static-ed: resolving the factory now relies on class-static Event/RoomEvent/StateEventBase::factory variables instead of factory_t type aliases; and REGISTER_EVENT_TYPE produces non-static inline variables instead, obviating the need of registerEventType/setupFactory kludge. --- lib/events/eventloader.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 978668f2..fe624d70 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -6,16 +6,6 @@ #include "stateevent.h" namespace Quotient { -namespace _impl { - template - static inline auto loadEvent(const QJsonObject& json, - const QString& matrixType) - { - if (auto e = EventFactory::make(json, matrixType)) - return e; - return makeEvent(unknownEventTypeId(), json); - } -} // namespace _impl /*! Create an event with proper type from a JSON object * @@ -26,7 +16,7 @@ namespace _impl { template inline event_ptr_tt loadEvent(const QJsonObject& fullJson) { - return _impl::loadEvent(fullJson, fullJson[TypeKeyL].toString()); + return doLoadEvent(fullJson, fullJson[TypeKeyL].toString()); } /*! Create an event from a type string and content JSON @@ -39,8 +29,8 @@ template inline event_ptr_tt loadEvent(const QString& matrixType, const QJsonObject& content) { - return _impl::loadEvent(basicEventJson(matrixType, content), - matrixType); + return doLoadEvent(basicEventJson(matrixType, content), + matrixType); } /*! Create a state event from a type string, content JSON and state key @@ -53,7 +43,7 @@ inline StateEventPtr loadStateEvent(const QString& matrixType, const QJsonObject& content, const QString& stateKey = {}) { - return _impl::loadEvent( + return doLoadEvent( basicStateEventJson(matrixType, content, stateKey), matrixType); } -- cgit v1.2.3 From 843f7a0ac2619a2f2863d457cdeaa03707255793 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 4 May 2022 21:12:29 +0200 Subject: basic*EventJson() -> *Event::basicJson() This makes it easier and more intuitive to build a minimal JSON payload for a given event type. A common basicJson() call point is also convenient in template contexts (see next commits). --- lib/events/eventloader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index fe624d70..c7b82e8e 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -29,7 +29,7 @@ template inline event_ptr_tt loadEvent(const QString& matrixType, const QJsonObject& content) { - return doLoadEvent(basicEventJson(matrixType, content), + return doLoadEvent(Event::basicJson(matrixType, content), matrixType); } @@ -44,7 +44,7 @@ inline StateEventPtr loadStateEvent(const QString& matrixType, const QString& stateKey = {}) { return doLoadEvent( - basicStateEventJson(matrixType, content, stateKey), matrixType); + StateEventBase::basicJson(matrixType, content, stateKey), matrixType); } template -- cgit v1.2.3 From 150df8ce08976ac7b8c25dbed1b965b7c2f65249 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 1 Aug 2022 12:11:58 +0200 Subject: Pull out common JsonConverter code to JsonObjectUnpacker --- lib/events/eventloader.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index c7b82e8e..7dde9786 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -48,14 +48,11 @@ inline StateEventPtr loadStateEvent(const QString& matrixType, } template -struct JsonConverter> { - static auto load(const QJsonValue& jv) +struct JsonConverter> + : JsonObjectUnpacker> { + static auto load(const QJsonObject& jo) { - return loadEvent(jv.toObject()); - } - static auto load(const QJsonDocument& jd) - { - return loadEvent(jd.object()); + return loadEvent(jo); } }; } // namespace Quotient -- cgit v1.2.3 From 88dcdd3ef0af4030a963b08bf8c5bff0784c320d Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 1 Aug 2022 13:51:58 +0200 Subject: Fix FTBFS --- lib/events/eventloader.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 7dde9786..15271ab1 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -50,9 +50,11 @@ inline StateEventPtr loadStateEvent(const QString& matrixType, template struct JsonConverter> : JsonObjectUnpacker> { + using JsonObjectUnpacker>::load; static auto load(const QJsonObject& jo) { return loadEvent(jo); } }; + } // namespace Quotient -- cgit v1.2.3 From 3214feeb031fa231c7c42c21c53410302966e32e Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Fri, 29 Jul 2022 18:13:14 +0200 Subject: eventloader.h: use basicJson() in a uniform way There's no particular reason the order of parameters in StateEventBase::basicJson() should be as it was, and (the only) loadStateEvent() usage in room.cpp suggests the unified order is more convenient. Besides, this order is aligned with that in the StateEventBase constructor. --- lib/events/eventloader.h | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 15271ab1..4c639efa 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -19,32 +19,17 @@ inline event_ptr_tt loadEvent(const QJsonObject& fullJson) return doLoadEvent(fullJson, fullJson[TypeKeyL].toString()); } -/*! Create an event from a type string and content JSON - * - * Use this factory template to resolve the C++ type from the Matrix - * type string in \p matrixType and create an event of that type that has - * its content part set to \p content. - */ -template -inline event_ptr_tt loadEvent(const QString& matrixType, - const QJsonObject& content) -{ - return doLoadEvent(Event::basicJson(matrixType, content), - matrixType); -} - -/*! Create a state event from a type string, content JSON and state key - * - * Use this factory to resolve the C++ type from the Matrix type string - * in \p matrixType and create a state event of that type with content part - * set to \p content and state key set to \p stateKey (empty by default). - */ -inline StateEventPtr loadStateEvent(const QString& matrixType, - const QJsonObject& content, - const QString& stateKey = {}) +//! \brief Create an event from a type string and content JSON +//! +//! Use this template to resolve the C++ type from the Matrix type string in +//! \p matrixType and create an event of that type by passing all parameters +//! to BaseEventT::basicJson(). +template +inline event_ptr_tt loadEvent( + const QString& matrixType, const BasicJsonParamTs&... basicJsonParams) { - return doLoadEvent( - StateEventBase::basicJson(matrixType, content, stateKey), matrixType); + return doLoadEvent( + BaseEventT::basicJson(matrixType, basicJsonParams...), matrixType); } template -- cgit v1.2.3 From 17cd3beaefa5501a902e08c7644e8cd97c9091a0 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Fri, 12 Aug 2022 16:46:01 +0200 Subject: Streamline event types This commit introduces a few things to further reduce the boilerplate across event type definitions: - Event type is no more separately stored in Event and therefore no more passed to base event constructors. Until the previous commit, it was used by is() to quickly match the event type; with the new event metatype class, the same is achieved even quicker by comparing metatype pointers. - EventTemplate is a generalisation of StateEvent for all event types providing common constructor signatures and content() for (most) leaf event types. StateEvent therefore has become a partial specialisation of EventTemplate for types derived from StateEventBase; as the known client code base does not use it directly, a compatibility alias is not provided. Also, DEFINE_SIMPLE_EVENT now expands into a class deriving from EventTemplate. - On top of StateEvent->EventTemplate specialisation, KeyedStateEventBase and KeylessStateEventBase types are introduced with appropriate constructor signatures (with or without state_key, respectively) to allow `using` of them from derived event types. To facilitate writing of constraints, concepts for keyed and keyless state event types are also introduced; RoomStateView, e.g., makes use of those to provide appropriate method signatures. - typeId(), unknownEventTypeId(), UnknownEventTypeId are no more provided - they weren't used throughout the known code base (Quaternion, NeoChat), and the concept of "unknown event types" is hereby eliminated entirely. - RoomKeyEvent no more accepts senderId as a parameter; it has never been a good practice as the sender is assigned by Connection anyway. --- lib/events/eventloader.h | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) (limited to 'lib/events/eventloader.h') diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 4c639efa..b4ac154c 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -6,40 +6,8 @@ #include "stateevent.h" namespace Quotient { - -/*! Create an event with proper type from a JSON object - * - * Use this factory template to detect the type from the JSON object - * contents (the detected event type should derive from the template - * parameter type) and create an event object of that type. - */ -template -inline event_ptr_tt loadEvent(const QJsonObject& fullJson) -{ - return doLoadEvent(fullJson, fullJson[TypeKeyL].toString()); -} - -//! \brief Create an event from a type string and content JSON -//! -//! Use this template to resolve the C++ type from the Matrix type string in -//! \p matrixType and create an event of that type by passing all parameters -//! to BaseEventT::basicJson(). -template -inline event_ptr_tt loadEvent( - const QString& matrixType, const BasicJsonParamTs&... basicJsonParams) -{ - return doLoadEvent( - BaseEventT::basicJson(matrixType, basicJsonParams...), matrixType); +struct [[deprecated( + "This header is obsolete since libQuotient 0.7; include a header with" + " the respective event type definition instead")]] EventLoaderH; +StateEventPtr eventLoaderH(EventLoaderH&); } - -template -struct JsonConverter> - : JsonObjectUnpacker> { - using JsonObjectUnpacker>::load; - static auto load(const QJsonObject& jo) - { - return loadEvent(jo); - } -}; - -} // namespace Quotient -- cgit v1.2.3