diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-09-15 18:40:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 18:40:15 +0900 |
commit | 5ad32f13b8a7a8552e2b6c56571bd8177b3fabb2 (patch) | |
tree | 2f0069a1487573cc56856ab47758ac3993b125d5 /connection.h | |
parent | 180d62e094a1a6b6fc69c99b291ef075dc649135 (diff) | |
parent | c4f690edf4cc2e11f19370f80ddd7428aba0b536 (diff) | |
download | libquotient-5ad32f13b8a7a8552e2b6c56571bd8177b3fabb2.tar.gz libquotient-5ad32f13b8a7a8552e2b6c56571bd8177b3fabb2.zip |
Merge pull request #82 from QMatrixClient/kitsune-uncouple-factories
Connection: Room and User factories are std::functions now
Diffstat (limited to 'connection.h')
-rw-r--r-- | connection.h | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/connection.h b/connection.h index 0b8500b9..4b0413e3 100644 --- a/connection.h +++ b/connection.h @@ -22,6 +22,8 @@ #include <QtCore/QUrl> #include <QtCore/QSize> +#include <functional> + namespace QMatrixClient { class Room; @@ -96,6 +98,20 @@ namespace QMatrixClient */ Q_INVOKABLE QByteArray generateTxnId(); + template <typename T = Room> + static void setRoomType() + { + createRoom = + [](Connection* c, const QString& id) { return new T(c, id); }; + } + + template <typename T = User> + static void setUserType() + { + createUser = + [](Connection* c, const QString& id) { return new T(id, c); }; + } + signals: void resolved(); void connected(); @@ -130,18 +146,11 @@ namespace QMatrixClient */ Room* provideRoom(const QString& roomId); - /** - * makes it possible for derived classes to have its own User class - */ - virtual User* createUser(const QString& userId); - - /** - * makes it possible for derived classes to have its own Room class - */ - virtual Room* createRoom(const QString& roomId); - private: class Private; Private* d; + + static std::function<Room*(Connection*, const QString&)> createRoom; + static std::function<User*(Connection*, const QString&)> createUser; }; } // namespace QMatrixClient |