6#ifndef QXMPPACCOUNTMIGRATIONMANAGER_H
7#define QXMPPACCOUNTMIGRATIONMANAGER_H
9#include "QXmppClientExtension.h"
10#include "QXmppFutureUtils_p.h"
15#include <unordered_map>
17struct QXmppExportDataPrivate;
19class QXMPP_EXPORT QXmppExportData
22 template<
typename T = QXmpp::Success>
23 using Result = std::variant<T, QXmppError>;
26 QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppExportData)
28 static std::variant<QXmppExportData, QXmppError> fromDom(
const QDomElement &);
29 void toXml(QXmlStreamWriter *)
const;
31 const QString &accountJid()
const;
32 void setAccountJid(
const QString &jid);
35 using ExtensionParser = Result<T> (*)(
const QDomElement &);
37 using ExtensionSerializer = void (*)(
const T &, QXmlStreamWriter &);
39 template<
typename T, ExtensionParser<T> parse, ExtensionSerializer<T> serialize>
40 static void registerExtension(QStringView tagName, QStringView xmlns)
42 using namespace QXmpp::Private;
43 using AnyParser = ExtensionParser<std::any>;
44 using AnySerializer = ExtensionSerializer<std::any>;
46 AnyParser parseAny = [](
const QDomElement &el) {
47 return std::visit(overloaded {
48 [](T data) -> Result<std::any> {
return std::move(data); },
49 [](
QXmppError e) -> Result<std::any> {
return std::move(e); },
54 AnySerializer serializeAny = [](
const std::any &data, QXmlStreamWriter &w) {
55 return std::invoke(serialize, std::any_cast<const T &>(data), w);
58 registerExtensionInternal(std::type_index(
typeid(T)), parseAny, serializeAny, tagName, xmlns);
63 friend class tst_QXmppAccountMigrationManager;
65 const std::unordered_map<std::type_index, std::any> &extensions()
const;
66 void setExtension(std::any value);
68 static void registerExtensionInternal(std::type_index, ExtensionParser<std::any>, ExtensionSerializer<std::any>, QStringView tagName, QStringView xmlns);
70 QSharedDataPointer<QXmppExportDataPrivate> d;
73struct QXmppAccountMigrationManagerPrivate;
79 friend struct QXmppAccountMigrationManagerPrivate;
82 template<
typename T = QXmpp::Success>
83 using Result = std::variant<T, QXmppError>;
91 template<
typename DataType,
typename ImportFunc,
typename ExportFunc>
92 void registerExportData(ImportFunc importFunc, ExportFunc exportFunc);
94 template<
typename DataType>
95 void unregisterExportData();
99 void unregisterMigrationDataInternal(std::type_index dataType);
101 std::unique_ptr<QXmppAccountMigrationManagerPrivate> d;
104template<
typename DataType,
typename ImportFunc,
typename ExportFunc>
107 using namespace QXmpp::Private;
109 static_assert(std::is_constructible_v<std::function<QXmppTask<Result<>>(
const DataType &)>, ImportFunc>);
110 static_assert(std::is_constructible_v<std::function<QXmppTask<Result<DataType>>()>, ExportFunc>);
111 static_assert(std::is_invocable_v<ImportFunc, const DataType &>);
112 static_assert(std::is_invocable_v<ExportFunc>);
113 static_assert(std::is_same_v<first_argument_t<ImportFunc>,
const DataType &>);
115 auto importInternal = [importFunc = std::move(importFunc)](std::any data) ->
QXmppTask<
Result<>> {
116 Q_ASSERT(std::type_index(data.type()) == std::type_index(
typeid(DataType)));
117 return importFunc(std::any_cast<DataType>(std::move(data)));
120 using AnyResult = std::variant<std::any, QXmppError>;
123 return std::visit(overloaded {
124 [](DataType data) -> AnyResult {
return std::any(std::move(data)); },
125 [](
QXmppError err) -> AnyResult {
return err; } },
130 registerMigrationDataInternal(std::type_index(
typeid(DataType)), std::move(importInternal), std::move(exportInternal));
133template<
typename DataType>
136 unregisterMigrationDataInternal(std::type_index(
typeid(DataType)));
Allows to export and import account data.
Definition QXmppAccountMigrationManager.h:76
std::variant< T, QXmppError > Result
Definition QXmppAccountMigrationManager.h:83
void unregisterExportData()
Definition QXmppAccountMigrationManager.h:134
void registerExportData(ImportFunc importFunc, ExportFunc exportFunc)
Definition QXmppAccountMigrationManager.h:105
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:32
Definition QXmppTask.h:62
Definition QXmppError.h:17