diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-12-14 23:32:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-14 23:32:16 +0900 |
commit | fcc8d2ca615fce6e42bf1cf6585d60f94a2db926 (patch) | |
tree | b0dd17b632a5c5775f2221fd0b53b21a8c02ce58 /lib/application-service/definitions/protocol.cpp | |
parent | 50571a92b4e9f634c4daf546222fa082120db6c7 (diff) | |
parent | 12a0b95fdcfea15cd0ef313aec8868656629b986 (diff) | |
download | libquotient-fcc8d2ca615fce6e42bf1cf6585d60f94a2db926.tar.gz libquotient-fcc8d2ca615fce6e42bf1cf6585d60f94a2db926.zip |
Merge pull request #263 from QMatrixClient/kitsune-lazy-loading
Lazy loading members
Diffstat (limited to 'lib/application-service/definitions/protocol.cpp')
-rw-r--r-- | lib/application-service/definitions/protocol.cpp | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/lib/application-service/definitions/protocol.cpp b/lib/application-service/definitions/protocol.cpp index 04bb7dfc..2a62b15d 100644 --- a/lib/application-service/definitions/protocol.cpp +++ b/lib/application-service/definitions/protocol.cpp @@ -6,75 +6,55 @@ using namespace QMatrixClient; -QJsonObject QMatrixClient::toJson(const FieldType& pod) +void JsonObjectConverter<FieldType>::dumpTo( + QJsonObject& jo, const FieldType& pod) { - QJsonObject jo; addParam<>(jo, QStringLiteral("regexp"), pod.regexp); addParam<>(jo, QStringLiteral("placeholder"), pod.placeholder); - return jo; } -FieldType FromJsonObject<FieldType>::operator()(const QJsonObject& jo) const +void JsonObjectConverter<FieldType>::fillFrom( + const QJsonObject& jo, FieldType& result) { - FieldType result; - result.regexp = - fromJson<QString>(jo.value("regexp"_ls)); - result.placeholder = - fromJson<QString>(jo.value("placeholder"_ls)); - - return result; + fromJson(jo.value("regexp"_ls), result.regexp); + fromJson(jo.value("placeholder"_ls), result.placeholder); } -QJsonObject QMatrixClient::toJson(const ProtocolInstance& pod) +void JsonObjectConverter<ProtocolInstance>::dumpTo( + QJsonObject& jo, const ProtocolInstance& pod) { - QJsonObject jo; addParam<>(jo, QStringLiteral("desc"), pod.desc); addParam<IfNotEmpty>(jo, QStringLiteral("icon"), pod.icon); addParam<>(jo, QStringLiteral("fields"), pod.fields); addParam<>(jo, QStringLiteral("network_id"), pod.networkId); - return jo; } -ProtocolInstance FromJsonObject<ProtocolInstance>::operator()(const QJsonObject& jo) const +void JsonObjectConverter<ProtocolInstance>::fillFrom( + const QJsonObject& jo, ProtocolInstance& result) { - ProtocolInstance result; - result.desc = - fromJson<QString>(jo.value("desc"_ls)); - result.icon = - fromJson<QString>(jo.value("icon"_ls)); - result.fields = - fromJson<QJsonObject>(jo.value("fields"_ls)); - result.networkId = - fromJson<QString>(jo.value("network_id"_ls)); - - return result; + fromJson(jo.value("desc"_ls), result.desc); + fromJson(jo.value("icon"_ls), result.icon); + fromJson(jo.value("fields"_ls), result.fields); + fromJson(jo.value("network_id"_ls), result.networkId); } -QJsonObject QMatrixClient::toJson(const ThirdPartyProtocol& pod) +void JsonObjectConverter<ThirdPartyProtocol>::dumpTo( + QJsonObject& jo, const ThirdPartyProtocol& pod) { - QJsonObject jo; 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); - return jo; } -ThirdPartyProtocol FromJsonObject<ThirdPartyProtocol>::operator()(const QJsonObject& jo) const +void JsonObjectConverter<ThirdPartyProtocol>::fillFrom( + const QJsonObject& jo, ThirdPartyProtocol& result) { - ThirdPartyProtocol result; - result.userFields = - fromJson<QStringList>(jo.value("user_fields"_ls)); - result.locationFields = - fromJson<QStringList>(jo.value("location_fields"_ls)); - result.icon = - fromJson<QString>(jo.value("icon"_ls)); - result.fieldTypes = - fromJson<QHash<QString, FieldType>>(jo.value("field_types"_ls)); - result.instances = - fromJson<QVector<ProtocolInstance>>(jo.value("instances"_ls)); - - return result; + fromJson(jo.value("user_fields"_ls), result.userFields); + fromJson(jo.value("location_fields"_ls), result.locationFields); + fromJson(jo.value("icon"_ls), result.icon); + fromJson(jo.value("field_types"_ls), result.fieldTypes); + fromJson(jo.value("instances"_ls), result.instances); } |