6#ifndef QXMPPACCOUNTMIGRATIONMANAGER_H
7#define QXMPPACCOUNTMIGRATIONMANAGER_H
9#include "QXmppClientExtension.h"
10#include "QXmppFutureUtils_p.h"
16struct QXmppExportDataPrivate;
18class QXMPP_EXPORT QXmppExportData
21 template<
typename T = QXmpp::Success>
22 using Result = std::variant<T, QXmppError>;
25 QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppExportData)
27 static std::variant<QXmppExportData, QXmppError> fromDom(
const QDomElement &);
28 void toXml(QXmlStreamWriter *)
const;
30 const QString &accountJid()
const;
31 void setAccountJid(
const QString &jid);
34 using ExtensionParser = Result<T> (*)(
const QDomElement &);
36 using ExtensionSerializer = void (*)(
const T &, QXmlStreamWriter &);
38 template<
typename T, ExtensionParser<T> parse, ExtensionSerializer<T> serialize>
39 static void registerExtension(QStringView tagName, QStringView xmlns)
41 using namespace QXmpp::Private;
42 using AnyParser = ExtensionParser<std::any>;
43 using AnySerializer = ExtensionSerializer<std::any>;
45 AnyParser parseAny = [](
const QDomElement &el) {
46 return std::visit(overloaded {
47 [](T data) -> Result<std::any> {
return std::move(data); },
48 [](
QXmppError e) -> Result<std::any> {
return std::move(e); },
53 AnySerializer serializeAny = [](
const std::any &data, QXmlStreamWriter &w) {
54 return std::invoke(serialize, std::any_cast<const T &>(data), w);
57 registerExtensionInternal(std::type_index(
typeid(T)), parseAny, serializeAny, tagName, xmlns);
62 friend class tst_QXmppAccountMigrationManager;
64 const std::unordered_map<std::type_index, std::any> &extensions()
const;
65 void setExtension(std::any value);
67 static void registerExtensionInternal(std::type_index, ExtensionParser<std::any>, ExtensionSerializer<std::any>, QStringView tagName, QStringView xmlns);
69 QSharedDataPointer<QXmppExportDataPrivate> d;
72struct QXmppAccountMigrationManagerPrivate;
78 friend struct QXmppAccountMigrationManagerPrivate;
81 template<
typename T = QXmpp::Success>
82 using Result = std::variant<T, QXmppError>;
90 template<
typename DataType,
typename ImportFunc,
typename ExportFunc>
91 void registerExportData(ImportFunc importFunc, ExportFunc exportFunc);
93 template<
typename DataType>
94 void unregisterExportData();
98 void unregisterMigrationDataInternal(std::type_index dataType);
100 std::unique_ptr<QXmppAccountMigrationManagerPrivate> d;
103template<
typename DataType,
typename ImportFunc,
typename ExportFunc>
106 using namespace QXmpp::Private;
108 static_assert(std::is_constructible_v<std::function<QXmppTask<Result<>>(
const DataType &)>, ImportFunc>);
109 static_assert(std::is_constructible_v<std::function<QXmppTask<Result<DataType>>()>, ExportFunc>);
110 static_assert(std::is_invocable_v<ImportFunc, const DataType &>);
111 static_assert(std::is_invocable_v<ExportFunc>);
112 static_assert(std::is_same_v<first_argument_t<ImportFunc>,
const DataType &>);
114 auto importInternal = [importFunc = std::move(importFunc)](std::any data) ->
QXmppTask<
Result<>> {
115 Q_ASSERT(std::type_index(data.type()) == std::type_index(
typeid(DataType)));
116 return importFunc(std::any_cast<DataType>(std::move(data)));
119 using AnyResult = std::variant<std::any, QXmppError>;
122 return std::visit(overloaded {
123 [](DataType data) -> AnyResult {
return std::any(std::move(data)); },
124 [](
QXmppError err) -> AnyResult {
return err; } },
129 registerMigrationDataInternal(std::type_index(
typeid(DataType)), std::move(importInternal), std::move(exportInternal));
132template<
typename DataType>
135 unregisterMigrationDataInternal(std::type_index(
typeid(DataType)));
Allows to export and import account data.
Definition QXmppAccountMigrationManager.h:75
std::variant< T, QXmppError > Result
Definition QXmppAccountMigrationManager.h:82
void unregisterExportData()
Definition QXmppAccountMigrationManager.h:133
void registerExportData(ImportFunc importFunc, ExportFunc exportFunc)
Definition QXmppAccountMigrationManager.h:104
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:32
Definition QXmppTask.h:62
Definition QXmppError.h:17