aboutsummaryrefslogtreecommitdiff
path: root/connection.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-30 08:56:59 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-08 16:25:06 +0900
commite3ae4840e3082cbd30b4f699ef142787187ef688 (patch)
tree5fd70632e18d540e1f61d15e679af0992b3b4526 /connection.h
parentc5ed011aa13d08d62e999fc6b5ff142a2bc07421 (diff)
downloadlibquotient-e3ae4840e3082cbd30b4f699ef142787187ef688.tar.gz
libquotient-e3ae4840e3082cbd30b4f699ef142787187ef688.zip
Connection: Room and User factories are std::functions now
Instead of createUser() and createRoom() virtual functions, use std::function<> to store predefined lambdas that would create respective descendants from User and Room, respectively. No more need QuaternionConnection just for the sake of creating a QuaternionRoom.
Diffstat (limited to 'connection.h')
-rw-r--r--connection.h29
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