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/application-service/definitions/protocol.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index 2aca7d66..0a1f9a21 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -25,12 +25,10 @@ namespace QMatrixClient /// An placeholder serving as a valid example of the field value. QString placeholder; }; - - QJsonObject toJson(const FieldType& pod); - - template <> struct FromJsonObject + template <> struct JsonObjectConverter { - FieldType operator()(const QJsonObject& jo) const; + static void dumpTo(QJsonObject& jo, const FieldType& pod); + static void fillFrom(const QJsonObject& jo, FieldType& pod); }; struct ProtocolInstance @@ -45,12 +43,10 @@ namespace QMatrixClient /// A unique identifier across all instances. QString networkId; }; - - QJsonObject toJson(const ProtocolInstance& pod); - - template <> struct FromJsonObject + template <> struct JsonObjectConverter { - ProtocolInstance operator()(const QJsonObject& jo) const; + static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod); + static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod); }; struct ThirdPartyProtocol @@ -78,12 +74,10 @@ namespace QMatrixClient /// same application service. QVector instances; }; - - QJsonObject toJson(const ThirdPartyProtocol& pod); - - template <> struct FromJsonObject + template <> struct JsonObjectConverter { - ThirdPartyProtocol operator()(const QJsonObject& jo) const; + static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod); + static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod); }; } // 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/application-service/definitions/protocol.h | 64 ++++++++++++-------------- 1 file changed, 30 insertions(+), 34 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index 0a1f9a21..66012a13 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -6,76 +6,72 @@ #include "converters.h" +#include "converters.h" #include #include -#include "converters.h" #include -namespace QMatrixClient -{ +namespace QMatrixClient { // Data structures /// Definition of valid values for a field. - struct FieldType - { - /// A regular expression for validation of a field's value. This may be relatively - /// coarse to verify the value as the application service providing this protocol - /// may apply additional validation or filtering. + struct FieldType { + /// A regular expression for validation of a field's value. This may be + /// relatively coarse to verify the value as the application service + /// providing this protocol may apply additional validation or + /// filtering. QString regexp; /// An placeholder serving as a valid example of the field value. QString placeholder; }; - template <> struct JsonObjectConverter - { + template <> struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const FieldType& pod); static void fillFrom(const QJsonObject& jo, FieldType& pod); }; - struct ProtocolInstance - { + struct ProtocolInstance { /// A human-readable description for the protocol, such as the name. QString desc; - /// An optional content URI representing the protocol. Overrides the one provided - /// at the higher level Protocol object. + /// An optional content URI representing the protocol. Overrides the one + /// provided at the higher level Protocol object. QString icon; /// Preset values for ``fields`` the client may use to search by. QJsonObject fields; /// A unique identifier across all instances. QString networkId; }; - template <> struct JsonObjectConverter - { + template <> struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod); static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod); }; - struct ThirdPartyProtocol - { - /// Fields which may be used to identify a third party user. These should be - /// ordered to suggest the way that entities may be grouped, where higher - /// groupings are ordered first. For example, the name of a network should be - /// searched before the nickname of a user. + struct ThirdPartyProtocol { + /// Fields which may be used to identify a third party user. These + /// should be ordered to suggest the way that entities may be grouped, + /// where higher groupings are ordered first. For example, the name of a + /// network should be searched before the nickname of a user. QStringList userFields; - /// Fields which may be used to identify a third party location. These should be - /// ordered to suggest the way that entities may be grouped, where higher - /// groupings are ordered first. For example, the name of a network should be - /// searched before the name of a channel. + /// Fields which may be used to identify a third party location. These + /// should be ordered to suggest the way that entities may be grouped, + /// where higher groupings are ordered first. For example, the name of a + /// network should be searched before the name of a channel. QStringList locationFields; /// A content URI representing an icon for the third party protocol. QString icon; - /// The type definitions for the fields defined in the ``user_fields`` and - /// ``location_fields``. Each entry in those arrays MUST have an entry here. The + /// The type definitions for the fields defined in the ``user_fields`` + /// and + /// ``location_fields``. Each entry in those arrays MUST have an entry + /// here. The /// ``string`` key for this object is field name itself. - /// + /// /// May be an empty object if no fields are defined. QHash fieldTypes; - /// A list of objects representing independent instances of configuration. - /// For example, multiple networks on IRC if multiple are provided by the - /// same application service. + /// A list of objects representing independent instances of + /// configuration. For example, multiple networks on IRC if multiple are + /// provided by the same application service. QVector instances; }; - template <> struct JsonObjectConverter - { + template <> struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod); static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod); }; -- 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/application-service/definitions/protocol.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index 0d227851..ab99264f 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -10,7 +10,7 @@ #include #include -namespace QMatrixClient +namespace Quotient { // Data structures @@ -85,4 +85,4 @@ struct JsonObjectConverter static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod); }; -} // namespace QMatrixClient +} // namespace Quotient -- cgit v1.2.3 From 7036ed0dcb137cb5cbb6b426dd338c5e2e4c6424 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 17 Apr 2020 07:42:13 +0200 Subject: Regenerate API files using new GTAD and refreshed templates No functional changes. --- lib/application-service/definitions/protocol.h | 61 ++++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index ab99264f..ac1e50e2 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -10,77 +10,80 @@ #include #include -namespace Quotient -{ +namespace Quotient { // Data structures /// Definition of valid values for a field. -struct FieldType -{ +struct FieldType { /// A regular expression for validation of a field's value. This may be - /// relativelycoarse to verify the value as the application service - /// providing this protocolmay apply additional validation or filtering. + /// relatively coarse to verify the value as the application service + /// providing this protocol may apply additional validation or filtering. QString regexp; + /// An placeholder serving as a valid example of the field value. QString placeholder; }; template <> -struct JsonObjectConverter -{ +struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const FieldType& pod); static void fillFrom(const QJsonObject& jo, FieldType& pod); }; -struct ProtocolInstance -{ +struct ProtocolInstance { /// A human-readable description for the protocol, such as the name. QString desc; + /// An optional content URI representing the protocol. Overrides the one - /// providedat the higher level Protocol object. + /// provided at the higher level Protocol object. QString icon; + /// Preset values for ``fields`` the client may use to search by. QJsonObject fields; + /// A unique identifier across all instances. QString networkId; }; template <> -struct JsonObjectConverter -{ +struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod); static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod); }; -struct ThirdPartyProtocol -{ - /// Fields which may be used to identify a third party user. These should - /// beordered to suggest the way that entities may be grouped, where - /// highergroupings are ordered first. For example, the name of a network - /// should besearched before the nickname of a user. +struct ThirdPartyProtocol { + /// Fields which may be used to identify a third party user. These should be + /// ordered to suggest the way that entities may be grouped, where higher + /// groupings are ordered first. For example, the name of a network should + /// be searched before the nickname of a user. QStringList userFields; + /// Fields which may be used to identify a third party location. These - /// should beordered to suggest the way that entities may be grouped, where - /// highergroupings are ordered first. For example, the name of a network - /// should besearched before the name of a channel. + /// should be ordered to suggest the way that entities may be grouped, where + /// higher groupings are ordered first. For example, the name of a network + /// should be searched before the name of a channel. QStringList locationFields; + /// A content URI representing an icon for the third party protocol. QString icon; + /// The type definitions for the fields defined in the ``user_fields`` and /// ``location_fields``. Each entry in those arrays MUST have an entry here. - /// The``string`` key for this object is field name itself.May be an empty - /// object if no fields are defined. + /// The + /// ``string`` key for this object is field name itself. + /// + /// May be an empty object if no fields are defined. QHash fieldTypes; - /// A list of objects representing independent instances of - /// configuration.For example, multiple networks on IRC if multiple are - /// provided by thesame application service. + + /// A list of objects representing independent instances of configuration. + /// For example, multiple networks on IRC if multiple are provided by the + /// same application service. QVector instances; }; template <> -struct JsonObjectConverter -{ +struct JsonObjectConverter { static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod); static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod); }; -- cgit v1.2.3 From 32729d9a7519cd2c4cddb0174b8329c6fd4a4a83 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jun 2020 19:46:40 +0200 Subject: Update generated files according to gtad/* changes --- lib/application-service/definitions/protocol.h | 53 +++++++++++++++++++------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index ac1e50e2..6aee9c57 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -6,14 +6,7 @@ #include "converters.h" -#include -#include -#include - namespace Quotient { - -// Data structures - /// Definition of valid values for a field. struct FieldType { /// A regular expression for validation of a field's value. This may be @@ -27,8 +20,16 @@ struct FieldType { template <> struct JsonObjectConverter { - static void dumpTo(QJsonObject& jo, const FieldType& pod); - static void fillFrom(const QJsonObject& jo, FieldType& pod); + static void dumpTo(QJsonObject& jo, const FieldType& pod) + { + addParam<>(jo, QStringLiteral("regexp"), pod.regexp); + addParam<>(jo, QStringLiteral("placeholder"), pod.placeholder); + } + static void fillFrom(const QJsonObject& jo, FieldType& pod) + { + fromJson(jo.value("regexp"_ls), pod.regexp); + fromJson(jo.value("placeholder"_ls), pod.placeholder); + } }; struct ProtocolInstance { @@ -48,8 +49,20 @@ struct ProtocolInstance { template <> struct JsonObjectConverter { - static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod); - static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod); + static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod) + { + addParam<>(jo, QStringLiteral("desc"), pod.desc); + addParam(jo, QStringLiteral("icon"), pod.icon); + addParam<>(jo, QStringLiteral("fields"), pod.fields); + addParam<>(jo, QStringLiteral("network_id"), pod.networkId); + } + static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod) + { + fromJson(jo.value("desc"_ls), pod.desc); + fromJson(jo.value("icon"_ls), pod.icon); + fromJson(jo.value("fields"_ls), pod.fields); + fromJson(jo.value("network_id"_ls), pod.networkId); + } }; struct ThirdPartyProtocol { @@ -84,8 +97,22 @@ struct ThirdPartyProtocol { template <> struct JsonObjectConverter { - static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod); - static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod); + static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod) + { + addParam<>(jo, QStringLiteral("user_fields"), pod.userFields); + addParam<>(jo, QStringLiteral("location_fields"), pod.locationFields); + addParam<>(jo, QStringLiteral("icon"), pod.icon); + addParam<>(jo, QStringLiteral("field_types"), pod.fieldTypes); + addParam<>(jo, QStringLiteral("instances"), pod.instances); + } + static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod) + { + fromJson(jo.value("user_fields"_ls), pod.userFields); + fromJson(jo.value("location_fields"_ls), pod.locationFields); + fromJson(jo.value("icon"_ls), pod.icon); + fromJson(jo.value("field_types"_ls), pod.fieldTypes); + fromJson(jo.value("instances"_ls), pod.instances); + } }; } // namespace Quotient -- cgit v1.2.3 From 0d4315008374d9a4dfb11f934875b1a16670ec74 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 23 Jun 2021 19:12:38 +0200 Subject: Re-generate API files --- lib/application-service/definitions/protocol.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/application-service/definitions/protocol.h') diff --git a/lib/application-service/definitions/protocol.h b/lib/application-service/definitions/protocol.h index 6aee9c57..213dbf19 100644 --- a/lib/application-service/definitions/protocol.h +++ b/lib/application-service/definitions/protocol.h @@ -40,7 +40,7 @@ struct ProtocolInstance { /// provided at the higher level Protocol object. QString icon; - /// Preset values for ``fields`` the client may use to search by. + /// Preset values for `fields` the client may use to search by. QJsonObject fields; /// A unique identifier across all instances. @@ -81,10 +81,9 @@ struct ThirdPartyProtocol { /// A content URI representing an icon for the third party protocol. QString icon; - /// The type definitions for the fields defined in the ``user_fields`` and - /// ``location_fields``. Each entry in those arrays MUST have an entry here. - /// The - /// ``string`` key for this object is field name itself. + /// The type definitions for the fields defined in the `user_fields` and + /// `location_fields`. Each entry in those arrays MUST have an entry here. + /// The `string` key for this object is field name itself. /// /// May be an empty object if no fields are defined. QHash fieldTypes; -- cgit v1.2.3