aboutsummaryrefslogtreecommitdiff
path: root/lib/events/eventcontent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-01 22:48:38 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 09:07:32 +0900
commitf1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc (patch)
treef2435183d11a4cea52a7532eb9ff3d4d837e1d22 /lib/events/eventcontent.h
parentd5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff)
downloadlibquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.tar.gz
libquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.zip
Event types system remade to be extensible
There were two common points that had to be updated every time a new event is introduced: the EventType enumeration and one of 3 doMakeEvent<> specialisations. The new code has a template class, EventFactory<>, that uses a list of static factory methods to create events instead of typelists used in doMakeEvent<>(); the EventType enumeration is replaced with a namespace populated with constants as necessary. In general, EventType is considered a deprecated mechanism altogether; instead, a set of facilities is provided: is<>() to check if an event has a certain type (to replace comparison against an EventType value) and visit<>() to execute actions based on the event type (replacing switch statements over EventType values). Closes #129.
Diffstat (limited to 'lib/events/eventcontent.h')
-rw-r--r--lib/events/eventcontent.h36
1 files changed, 1 insertions, 35 deletions
diff --git a/lib/events/eventcontent.h b/lib/events/eventcontent.h
index 9d44aec0..91d7a8c8 100644
--- a/lib/events/eventcontent.h
+++ b/lib/events/eventcontent.h
@@ -21,14 +21,11 @@
// This file contains generic event content definitions, applicable to room
// message events as well as other events (e.g., avatars).
-#include "converters.h"
-
+#include <QtCore/QJsonObject>
#include <QtCore/QMimeType>
#include <QtCore/QUrl>
#include <QtCore/QSize>
-#include <functional>
-
namespace QMatrixClient
{
namespace EventContent
@@ -58,37 +55,6 @@ namespace QMatrixClient
virtual void fillJson(QJsonObject* o) const = 0;
};
- template <typename T = QString>
- class SimpleContent: public Base
- {
- public:
- using value_type = T;
-
- // The constructor is templated to enable perfect forwarding
- template <typename TT>
- SimpleContent(QString keyName, TT&& value)
- : value(std::forward<TT>(value)), key(std::move(keyName))
- { }
- SimpleContent(const QJsonObject& json, QString keyName)
- : Base(json)
- , value(QMatrixClient::fromJson<T>(json[keyName]))
- , key(std::move(keyName))
- { }
-
- public:
- T value;
-
- protected:
- QString key;
-
- private:
- void fillJson(QJsonObject* json) const override
- {
- Q_ASSERT(json);
- json->insert(key, QMatrixClient::toJson(value));
- }
- };
-
// The below structures fairly follow CS spec 11.2.1.6. The overall
// set of attributes for each content types is a superset of the spec
// but specific aggregation structure is altered. See doc comments to